public class DatabaseTypeFactory extends Object
DatabaseType objects based on the database being connected to. This should be
the only class (or at least one of the very few) that actually has database-specific knowledge coded into it.| Modifier and Type | Method and Description |
|---|---|
static void |
clearDatabaseTypeCache()
By default, this factory will remember what
DatabaseType is associated with
a specific connection class type. |
static Connection |
getConnection(Context context,
String datasource)
Given a context and a JNDI datasource name, this will lookup within that context to find the named datasource.
|
static DatabaseType |
getDatabaseType(Connection conn)
Given a
Connection object, this method returns its associated DatabaseType. |
static DatabaseType |
getDatabaseType(Context context,
String datasource)
Convenience method that gives you the
DatabaseType given a context and datasource. |
static DatabaseType |
getDefaultDatabaseType()
This is the getter of a get/set convenience mechanism for storing and retrieving the active database type.
|
static boolean |
isH2(Connection c)
Is the database H2?
|
static boolean |
isH2(DatabaseType type)
Determines if the given type refers to an H2 database.
|
static boolean |
isOracle(Connection c)
Is the database Oracle?
|
static boolean |
isOracle(DatabaseType type)
Determines if the given type refers to an Oracle database.
|
static boolean |
isPostgres(Connection c)
Is the database PostgreSQL?
|
static boolean |
isPostgres(DatabaseType type)
Determines if the given type refers to a Postgres database.
|
static boolean |
isSQLServer(Connection c)
Is the database SQL Server?
|
static boolean |
isSQLServer(DatabaseType type)
Determines if the given type refers to an SQL Server database.
|
static String |
loadJdbcDriver(String jdbc_url)
Given a JDBC URL, this will attempt to load in the JDBC driver class that will be needed to connect to the
database via that URL and will return that driver class name.
|
static void |
setDefaultDatabaseType(DatabaseType databaseType)
This is the setter of a get/set convenience mechanism for storing and retrieving the active database type.
|
public static void clearDatabaseTypeCache()
DatabaseType is associated with
a specific connection class type. However, if you change the JDBC URL, its possible
that this will also change the database type the connection class type should be
associated with (i.e. the URL may point to a different version of the same vendor's
database). If you change the JDBC URL, you should call this method to clear the
cache, thus enabling the factory to re-check the connection metadata to associate
a new database type with the connection class type.public static DatabaseType getDatabaseType(Context context, String datasource) throws Exception
DatabaseType given a context and datasource. This is a combination
of getDatabaseType(Context, String) and getDatabaseType(Connection).context - the context where the datasource can be founddatasource - the name of the datasource within the given contextDatabaseType of the type of database behind the data sourceException - if cannot find the datasource in the given context or the connection cannot be created or if
cannot determine what database the connection is connected topublic static Connection getConnection(Context context, String datasource) throws Exception
getDatabaseType(Connection) to create a DatabaseType.context - the context where the datasource can be founddatasource - the name of the datasource within the given contextException - if cannot find the datasource in the given context or the connection cannot be createdpublic static DatabaseType getDatabaseType(Connection conn) throws Exception
Connection object, this method returns its associated DatabaseType.conn - DatabaseType that the connection is connected toException - if cannot determine what database the connection is connected topublic static DatabaseType getDefaultDatabaseType()
public static void setDefaultDatabaseType(DatabaseType databaseType)
public static String loadJdbcDriver(String jdbc_url)
null will be returned - in which case attempting to connect to the database with the given URL will
probably fail.jdbc_url - a connection URL to the databasepublic static boolean isPostgres(Connection c) throws Exception
c - the connection to the databasetrue if the connection is talking to a Postgres databaseExceptionpublic static boolean isPostgres(DatabaseType type)
type - true if the type is a Postgres databasepublic static boolean isOracle(Connection c) throws Exception
c - the connection to the databasetrue if the connection is talking to an Oracle databaseExceptionpublic static boolean isOracle(DatabaseType type)
type - true if the type is an Oracle databasepublic static boolean isH2(Connection c) throws Exception
c - the connection to the databasetrue if the connection is talking to an H2 databaseExceptionpublic static boolean isH2(DatabaseType type)
type - true if the type is an H2 databasepublic static boolean isSQLServer(Connection c) throws Exception
c - the connection to the databasetrue if the connection is talking to an SQL Server databaseExceptionpublic static boolean isSQLServer(DatabaseType type)
type - true if the type is an SQL Server databaseCopyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.