com.j256.ormlite.db
Class DatabaseTypeUtils

java.lang.Object
  extended by com.j256.ormlite.db.DatabaseTypeUtils

public class DatabaseTypeUtils
extends Object

Utility class which helps with managing database specific classes.

Author:
graywatson

Method Summary
static DatabaseType createDatabaseType(DataSource dataSource)
          Creates and returns a DatabaseType associated with a DataSource.
static DatabaseType createDatabaseType(String databaseUrl)
          Creates and returns a DatabaseType for the database URL.
static SimpleDataSource createSimpleDataSource(String databaseUrl)
          Creates and returns a SimpleDataSource associated with the databaseUrl and optional userName and password.
static SimpleDataSource createSimpleDataSource(String databaseUrl, String userName, String password)
          Creates and returns a SimpleDataSource associated with the databaseUrl and optional userName and password.
static void loadDriver(String databaseUrl)
          Examines the databaseUrl parameter and load the driver for the proper database type if it can.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadDriver

public static void loadDriver(String databaseUrl)
                       throws ClassNotFoundException
Examines the databaseUrl parameter and load the driver for the proper database type if it can. It is expecting a databaseUrl format like jdbc:db-type:... where db-type is one of "h2", "mysql", "postgresql", ...

Throws:
IllegalArgumentException - if the url format is not recognized or the database type is unknown.
ClassNotFoundException - If the database class is unknown.

createSimpleDataSource

public static SimpleDataSource createSimpleDataSource(String databaseUrl)
                                               throws SQLException
Creates and returns a SimpleDataSource associated with the databaseUrl and optional userName and password. Calls loadDriver(java.lang.String) as well. You can, of course, provide your own DataSource for use with the package.

Throws:
SQLException - If there are problems constructing the DataSource.

createSimpleDataSource

public static SimpleDataSource createSimpleDataSource(String databaseUrl,
                                                      String userName,
                                                      String password)
                                               throws SQLException
Creates and returns a SimpleDataSource associated with the databaseUrl and optional userName and password. Calls loadDriver(java.lang.String) as well.

Throws:
SQLException - If there are problems constructing the DataSource.

createDatabaseType

public static DatabaseType createDatabaseType(String databaseUrl)
Creates and returns a DatabaseType for the database URL.

Throws:
IllegalArgumentException - if the url format is not recognized, the database type is unknown, or the class could not be constructed.

createDatabaseType

public static DatabaseType createDatabaseType(DataSource dataSource)
                                       throws SQLException
Creates and returns a DatabaseType associated with a DataSource. This has to make a connection with the DataSource so it can get meta-data which has the URL. Use of createDatabaseType(String) is recommended.

Throws:
SQLException


Copyright © 2010. All Rights Reserved.