Class DatabaseAdaptor

java.lang.Object
xal.tools.database.DatabaseAdaptor
Direct Known Subclasses:
MySQLDatabaseAdaptor, PostgresDatabaseAdaptor

public abstract class DatabaseAdaptor extends Object
DatabaseAdaptor provides a generic adaptor to wrap database specific code. For example, making a SQL array requires database specific code.
Author:
tap
  • Constructor Details

    • DatabaseAdaptor

      public DatabaseAdaptor()
  • Method Details

    • newBlob

      public Blob newBlob(Connection connection)
      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 array
      connection - An SQL connection
      array - 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 connect
      user - The user login into the database
      password - the user's password
      Throws:
      DatabaseException - if a database exception is thrown
    • getConnection

      public Connection getConnection(ConnectionDictionary dictionary) throws DatabaseException
      Get a new database connection
      Parameters:
      dictionary - A connection dictionary
      Throws:
      DatabaseException - if a database exception is thrown
    • getInstance

      public static DatabaseAdaptor 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

      public List<String> fetchAllSchemas(Connection connection) throws DatabaseException
      Fetch all schema from the connected database
      Returns:
      list of all schema in the database
      Throws:
      DatabaseException
      DatabaseException - if the schema fetch fails
    • fetchNontrivialSchemas

      public List<String> fetchNontrivialSchemas(Connection connection) throws DatabaseException
      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

      public List<String> fetchTables(Connection connection, String schema) throws DatabaseException
      Fetch tables for the specified schema
      Parameters:
      connection - The database connection
      schema - 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

      public ResultSet getTablesResultSet(DatabaseMetaData metaData, String schema) throws SQLException
      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 connection
      schema - The schema to use
      table - 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