Package xal.tools.database
Class DatabaseAdaptor
java.lang.Object
xal.tools.database.DatabaseAdaptor
- Direct Known Subclasses:
MySQLDatabaseAdaptor
,PostgresDatabaseAdaptor
DatabaseAdaptor provides a generic adaptor to wrap database specific code.
For example, making a SQL array requires database specific code.
- Author:
- tap
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfetchAllSchemas
(Connection connection) Fetch all schema from the connected databasefetchNontrivialSchemas
(Connection connection) Fetch the list of nontrivial schema.fetchPrimaryKeys
(Connection connection, String schema, String table) Fetch the primary keys for a specified table in a specified schemafetchTables
(Connection connection, String schema) Fetch tables for the specified schemaabstract Array
getArray
(String type, Connection connection, Object array) Get an SQL Array given an SQL array type, connection and a primitive arraygetColumnsResultSet
(DatabaseMetaData metaData, String schema, String table) Get the result set of columns for the specified meta data, schema and tablegetConnection
(String urlSpec, String user, String password) Get a new database connectiongetConnection
(ConnectionDictionary dictionary) Get a new database connectionstatic DatabaseAdaptor
Get a new database adaptor using the default database adaptor.getPrimaryKeysResultSet
(DatabaseMetaData metaData, String schema, String table) Get the result set of primary keys for the specified meta data, schema and tablegetTablesResultSet
(DatabaseMetaData metaData, String schema) Get the result set of tables for the specified meta data and schemanewBlob
(Connection connection) Instantiate an empty Blob.
-
Constructor Details
-
DatabaseAdaptor
public DatabaseAdaptor()
-
-
Method Details
-
newBlob
Instantiate an empty Blob.- Parameters:
connection
- the database connection- Returns:
- a new instance of a Blob appropriate for this adaptor.
-
getArray
public abstract Array getArray(String type, Connection connection, Object array) throws DatabaseException Get an SQL Array given an SQL array type, connection and a primitive array- Parameters:
type
- An SQL array type identifying the type of arrayconnection
- An SQL connectionarray
- The primitive Java array- Returns:
- the SQL array which wraps the primitive array
- Throws:
DatabaseException
- if a database exception is thrown
-
getConnection
public Connection getConnection(String urlSpec, String user, String password) throws DatabaseException Get a new database connection- Parameters:
urlSpec
- The URL to which to connectuser
- The user login into the databasepassword
- the user's password- Throws:
DatabaseException
- if a database exception is thrown
-
getConnection
Get a new database connection- Parameters:
dictionary
- A connection dictionary- Throws:
DatabaseException
- if a database exception is thrown
-
getInstance
Get a new database adaptor using the default database adaptor. Site specific code should provide an implementation of this method using the site specific database drivers.- Returns:
- return a new instance of the default database adaptor (OracleDatabaseAdaptor)
-
fetchAllSchemas
Fetch all schema from the connected database- Returns:
- list of all schema in the database
- Throws:
DatabaseException
DatabaseException
- if the schema fetch fails
-
fetchNontrivialSchemas
Fetch the list of nontrivial schema. By default, fetch all schema. Driver specific subclasses should provide a more accurate implementation.- Parameters:
connection
- database connection- Returns:
- list of nontrivial schema names
- Throws:
DatabaseException
-
fetchTables
Fetch tables for the specified schema- Parameters:
connection
- The database connectionschema
- The schema for which to fetch the tables- Returns:
- a list of tables associated with the specified schema
- Throws:
DatabaseException
DatabaseException
- if the schema fetch fails
-
getTablesResultSet
Get the result set of tables for the specified meta data and schema- Throws:
SQLException
-
getColumnsResultSet
public ResultSet getColumnsResultSet(DatabaseMetaData metaData, String schema, String table) throws SQLException Get the result set of columns for the specified meta data, schema and table- Throws:
SQLException
-
fetchPrimaryKeys
public List<String> fetchPrimaryKeys(Connection connection, String schema, String table) throws DatabaseException Fetch the primary keys for a specified table in a specified schema- Parameters:
connection
- The database connectionschema
- The schema to usetable
- The table for which to fetch the primary keys- Returns:
- a list of the primary keys as column names
- Throws:
DatabaseException
- Description of the Exception
-
getPrimaryKeysResultSet
public ResultSet getPrimaryKeysResultSet(DatabaseMetaData metaData, String schema, String table) throws SQLException Get the result set of primary keys for the specified meta data, schema and table- Throws:
SQLException
-