com.sibvisions.rad.persist.jdbc
Class DBAccess

java.lang.Object
  extended by com.sibvisions.rad.persist.jdbc.DBAccess
All Implemented Interfaces:
IDBAccess, ICloseable
Direct Known Subclasses:
AbstractOracleDBAccess, DB2DBAccess, DerbyDBAccess, H2DBAccess, HanaDBAccess, HSQLDBAccess, MSSQLDBAccess, MySQLDBAccess, PostgreSQLDBAccess, SQLiteDBAccess

public class DBAccess
extends java.lang.Object
implements IDBAccess, ICloseable

The DBAccess is the implementation for most used SQL databases.
Standard ANSI SQL Databases are anyways supported.
Its used to read/write data between the storage and the DataBook/DataPage. It has database type specific implementations.


Example:

 
 DBAccess dba = new DBAccess();
 
 // set connect properties
 dba.setDriver("org.hsqldb.jdbcDriver");
 dba.setUrl("jdbc:hsqldb:file:testdbs/test/testdb");
 dba.setUsername("sa");
 dba.setPassword("");
 
 Properties pDBProperties = new Properties();
 pDBProperties.put("shutdown", true);
 dba.setDBProperties(pDBProperties);
 
 // open
 dba.open();
 
 To get Database independent DBAccess, it is better to use:
 
 DBAccess dba = DBAccess.getDBAccess("jdbc:hsqldb:file:testdbs/test/testdb");
 
 // insert data into test table
 PreparedStatement psPreparedStatement = dba.getPreparedStatement(
                     "insert into test (id, name) values(?,?)", false);
 psPreparedStatement.setInt(1, 1);
 psPreparedStatement.setString(2, "projectX");
 dba.executeUpdate(psPreparedStatement);
 
 // select data from test table
 psPreparedStatement = dba.getPreparedStatement("select * from test", false);
 ResultSet rs = dba.executeQuery(psPreparedStatement);
 
 while (rs.next())
 {
    System.out.println(rs.getInt("id") + "," + rs.getString("name"));
 }
 
 

See Also:
IDBAccess, RemoteDataBook

Nested Class Summary
static class DBAccess.BlobFileHandle
          The DBAccess.BlobFileHandle is a simple IFileHandle implementation that stores a Blob and allows to retrieve it again.
static class DBAccess.ParameterizedStatement
          The DBAccess.ParameterizedStatement is a simple, mutable container for a statement and its values.
 
Field Summary
static int BFILE
          A jdbc BFILE DB column data type constant.
static int LONGNVARCHAR
          A jdbc VARCHAR DB column data type constant.
static int NCHAR
          A jdbc VARCHAR DB column data type constant.
static int NCLOB
          A jdbc BLOB DB column data type constant.
static int NVARCHAR
          A jdbc VARCHAR DB column data type constant.
static java.lang.String QUOTE
          JVx generell DB quote character. will be translated in the DB specific.
static int SQLXML
          A jdbc XML DB column data type constant.
static int TIMESTAMPWITHLOCALTIMEZONE
          A jdbc timestamp DB column data type constant.
static int TIMESTAMPWITHTIMEZONE
          A jdbc timestamp DB column data type constant.
 
Constructor Summary
DBAccess()
          Constructs a new DBAccess Object.
 
Method Summary
static void clearMetaData()
          Clears the meta data cache.
static void clearMetaData(java.lang.String pApplicationName)
          Clears the meta data cache for the given application.
 void close()
          Closes the database Connection and releases all memory.
 void commit()
          Commits the DB transaction.
protected  void commitOrRollbackBeforeClose()
          Calls commit or rollback before closing the connection.
protected  java.lang.Object convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData, java.lang.Object pObject)
          Enables the database specific implementation to handle/convert special objects.
protected  java.lang.Object convertValueToDatabaseSpecificObject(java.lang.Object pValue)
          Converts an object to a standard value for the specific database.
static java.lang.String createIdentifier(java.lang.Object... pIdentifier)
          Creates an identifier string from the given parameter.
protected  java.lang.String createReplace(java.lang.String pSource, java.lang.String pOld, java.lang.String pNew)
          Create an DB specific replace command, which replacs in the pSource all pOld to pNew.
protected  ServerColumnMetaData createServerColumnMetaData(java.sql.ResultSetMetaData pResultSetMetaData, int pResultSetColumnIndex, java.lang.String pQueryColumn)
          Creates the ServerColumnMetaData based on ResultSetMetaData.
protected  java.lang.String createWhereColumn(ServerMetaData pServerMetaData, CompareCondition pCompare, java.lang.String pColumnName)
          Creates the where column.
protected  java.lang.String createWhereParam(ServerMetaData pServerMetaData, CompareCondition pCompare)
          Creates the where parameter.
protected static void debug(java.lang.Object... pInfo)
          Logs debug information.
 void delete(java.lang.String pWriteBackTable, ServerMetaData pServerMetaData, java.lang.Object[] pDelete)
          Deletes the specified row.
protected  boolean detectModified()
          Detects if a transaction is open directly in the database.
protected static void error(java.lang.Object... pInfo)
          Logs error information.
 EventHandler<IConfigureConnectionListener> eventConfigureConnection()
          The event configure connection is always dispatched, when a new connection is used by this DBAccess.
 EventHandler<IUnconfigureConnectionListener> eventUnconfigureConnection()
          The event configure connection is always dispatched, when a new connection is used by this DBAccess.
 java.lang.Object executeFunction(java.lang.String pFunctionName, int pReturnType, java.lang.Object... pParameters)
          Executes a DB function with the specified parameters and return the result.
 java.lang.Object executeFunction(java.lang.String pFunctionName, OutParam pReturnOutParam, java.lang.Object... pParameters)
          Executes a DB function with the specified parameters and return the result.
 void executeProcedure(java.lang.String pProcedureName, java.lang.Object... pParameters)
          Executes a DB procedure with the specified parameters.
 java.util.List<Bean> executeQuery(java.lang.String pStatement, java.lang.Object... pParameters)
          Executes a SQL query as prepared statement.
 java.util.List<java.lang.Object> executeSql(java.lang.String pStatement, java.lang.Object... pParameters)
          Executes a SQL command as prepared statement.
protected  java.util.List<java.lang.Object> executeSqlMulti(java.lang.String pStatement, int pResultColumn, java.lang.Object... pParameters)
          Executes a SQL command as prepared statement.
 int executeStatement(java.lang.String pStatement, java.lang.Object... pParameters)
          Executes a DDL or DML Statement.
 java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereCondition, java.lang.String pAfterWhereClause, SortDefinition pSort, int pFromRow, int pMinimumRowCount)
          Returns the List of fetched rows (as List of Object[]) for the specified query tables and parameters.
 java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereCondition, java.lang.String pAfterWhereClause, SortDefinition pSort, int pFromRow, int pMinimumRowCount, boolean pAllowLazyFetch)
          Returns the List of fetched rows (as List of Object[]) for the specified query tables and parameters.
 java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereCondition, java.lang.String pAfterWhereClause, SortDefinition pSort, java.lang.String pOrderByClause, int pFromRow, int pMinimumRowCount)
          Mostly same as fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int).
 java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereCondition, java.lang.String pAfterWhereClause, SortDefinition pSort, java.lang.String pOrderByClause, int pFromRow, int pMinimumRowCount, boolean pAllowLazyFetch)
          Mostly same as fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int).
protected  ICondition findAndCreateReducedCondition(ICondition pCondition, java.util.Set<java.lang.String> pNames, java.util.Map<java.lang.String,CompareCondition> pNameToCondition)
          Finds and removes the ICondition with the given column names from the given ICondition.
protected  void findNamedParameters(java.lang.String pStatement, java.util.List<java.lang.String> pNameList)
          Finds all named parameters in the given statement and adds the names to the given List.
protected  void fireEventConfigureConnection()
          Fires the event configureConnection.
protected  void fireEventUnconfigureConnection()
          Fires the event unconfigureConnection.
protected  java.sql.SQLException formatSQLException(java.sql.SQLException pSqlException)
          Adds the SQL Error Code into the message of the SQL Exception.
protected  java.sql.SQLException formatSQLException(java.sql.SQLException pSqlException, java.lang.String pMessage, java.lang.String pCode)
          Adds the SQL Error Code into the message of the SQL Exception.
 java.util.Map<java.lang.String,java.lang.Object[]> getAllowedValues(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Gets the allowed values from a specific table.
protected  java.util.Map<java.lang.String,java.lang.Object[]> getAllowedValuesIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Gets the allowed values from a specific table.
static TranslationMap getAutomaticLinkColumnNameTranslation()
          Returns the TranslationMap for the automatic link column name custom Translation. its used in the getAutomaticLinkColName(ForeignKey pForeignKey) to change the column, thats determined.
 java.lang.String getCloseQuoteCharacter()
          Gets the database specific quote character.
 ServerColumnMetaData[] getColumnMetaData(java.lang.String pFromClause, java.lang.String[] pQueryColumns, java.lang.String pBeforeQueryColumns, java.lang.String pWhereClause, java.lang.String pAfterWhereClause)
          Returns the meta data information for the specified query, and configures all columns with defaults.
 IColumnMetaDataCreator getColumnMetaDataCreator()
          Gets the column meta data creator for custom column meta data support.
protected  ServerColumnMetaData[] getColumnMetaDataIntern(java.lang.String pFromClause, java.lang.String[] pQueryColumns, java.lang.String pBeforeQueryColumns, java.lang.String pWhereClause, java.lang.String pAfterWhereClause)
          Returns the meta data information for the specified query, and configures all columns with defaults.
protected  java.lang.String getColumnName(java.sql.ResultSetMetaData pMetaData, int pColumn)
          Gets the column name from the given resultset metadata.
 java.sql.Connection getConnection()
          Returns the connection to the database.
protected  java.sql.Connection getConnectionIntern()
          Returns the connection to the database.
 IConnectionPool getConnectionPool()
          Returns the conncetion to the database.
protected  java.lang.String getDatabaseSpecificLockStatement(java.lang.String pWriteBackTable, ServerMetaData pServerMetaData, ICondition pPKFilter)
          Returns the database specific statement to lock the specified row in the database.
static DBAccess getDBAccess(java.sql.Connection pConnection)
          Gets the suitable DBAccess for the given external connection.
static DBAccess getDBAccess(DBCredentials pCredentials)
          Gets the suitable DBAccess for the given DBCredentials.
static DBAccess getDBAccess(IConnectionPool pConnectionPool)
          Gets the suitable DBAccess for the given connection pool.
static DBAccess getDBAccess(java.lang.String pJdbcUrl)
          Gets the suitable DBAcces for the given JdbcUrl.
static DBAccess getDBAccess(java.lang.String pJdbcUrl, java.lang.String pOptionalUserName, java.lang.String pOptionalPassword)
          Gets the suitable DBAcces for the given JdbcUrl.
 java.util.Properties getDBProperties()
          Returns the DB specific initial parameters for the Connection creation.
 java.lang.String getDBProperty(java.lang.String pName)
          Gets the value for a specific database property.
 java.lang.Object[] getDefaultAllowedValues(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable, ServerColumnMetaData pMetaData)
          Gets the default allowed values for a given column from a given table.
static long getDefaultCursorCacheTimeout()
          Gets the default cursor cache timeout in ms.
static long getDefaultLargeObjectLimit()
          Gets the default value for the limit for what is considered a "large object".
 java.lang.String getDefaultSchema()
          Gets the default schema name, if it was set manually.
 java.util.Map<java.lang.String,java.lang.Object> getDefaultValues(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Gets all default column values of a specific table.
protected  java.util.Map<java.lang.String,java.lang.Object> getDefaultValuesIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Gets all default column values of a specific table.
protected  int getDiscardRowCount(int pFromRow, int pMinimumRowCount)
          Gets how many rows should be discarded based on the given values.
 java.lang.String getDriver()
          Gets the database driver name as String.
 java.util.List<ForeignKey> getForeignKeys(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Returns all Foreign Keys for the specified table.
protected  java.util.List<ForeignKey> getForeignKeysIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          Returns all Foreign Keys for the specified table.
protected  java.lang.String getIdentifier()
          Gets the identifier for this DBAccess.
 long getLargeObjectLimit()
          Gets the value for the limit for what is considered a "large object".
 int getMaxColumnLength()
          Returns the maximum allowed column length.
 int getMaxTime()
          Returns the maximum time in miliseconds to use, to try to fetch all rows. reduce open cursors, and increase performance.
 MetaDataCacheOption getMetaDataCacheOption()
          Gets the metadata cache option for this instance.
protected  java.lang.String getMetaDataWhereClause()
          Gets the where clause for metadata detection.
protected  java.lang.Object getObjectFromResultSet(java.sql.ResultSet pResultSet, int pIndex)
          Gets the Object from the result set, and ensures that numbers are always returned as BigDecimal, and dates as Timestamp.
protected  java.lang.Object getObjectFromResultSet(java.sql.ResultSet pResultSet, int pIndex, ServerColumnMetaData pColumnMetaData)
          Gets the Object from the result set, and ensures that numbers are always returned as BigDecimal, and dates as Timestamp.
 java.lang.String getOpenQuoteCharacter()
          Gets the database specific open quote character.
protected  java.lang.Object[] getParameter(ICondition pCondition)
          Returns the parameters used for this ICondition.
protected  java.lang.Object[] getParameter(ICondition pCondition, int pFromRow, int pMinimumRowCount)
          Returns the parameters used for this ICondition.
 DBAccess.ParameterizedStatement getParameterizedSelectStatement(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereClause, java.lang.String pAfterWhereClause, SortDefinition pSort, java.lang.String pOrderByClause, int pFromRow, int pMinimumRowCount)
          Creates the DBAccess.ParameterizedStatement and returns it.
 java.lang.String getPassword()
          Sets the password to use for the connection to the database.
 java.sql.PreparedStatement getPreparedStatement(java.lang.String pSqlStatement)
          Return a PreparedStatement for the given SQL statement.
protected  java.sql.PreparedStatement getPreparedStatement(java.lang.String pSqlStatement, boolean pReturnGeneratedKeys)
          Return a PreparedStatement for the given SQL statement.
 Key getPrimaryKey(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          It's gets all Primary Key columns and return it as String[].
protected  Key getPrimaryKeyIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          It's gets all Primary Key columns and return it as String[].
 int getQueryTimeout()
          Gets the query time out.
protected  java.lang.String getRealQueryColumnName(java.lang.String pQueryColumn)
          Gets the real query column name without alias.
 java.lang.String getSelectStatement(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereClause, java.lang.String pAfterWhereClause, SortDefinition pSort, java.lang.String pOrderByClause)
          It initialize the select for a specified storage unit and return the SELECT statement.
 java.lang.String getSelectStatement(ServerMetaData pServerMetaData, java.lang.String pBeforeQueryColumns, java.lang.String[] pQueryColumns, java.lang.String pFromClause, ICondition pFilter, java.lang.String pWhereClause, java.lang.String pAfterWhereClause, SortDefinition pSort, java.lang.String pOrderByClause, int pFromRow, int pMinimumRowCount)
          It initialize the select for a specified storage unit and return the SELECT statement.
protected  java.lang.String getSQL(ServerMetaData pServerMetaData, ICondition pCondition, boolean pUseRealColumnName)
          Returns the ANSI SQL String for this ICondition.
 java.lang.String getTableForSynonym(java.lang.String pSynomyn)
          Returns the full qualified table name incl. schema/catalog/db link for the given synonym.
protected  java.lang.String getTableForSynonymIntern(java.lang.String pSynomyn)
          Returns the full qualified table name incl. schema/catalog/db link for the given synonym.
 TableInfo getTableInfo(java.lang.String pWriteBackTable)
          Returns the meta data information for the specified query, and configures all columns with defaults.
protected  TableInfo getTableInfoIntern(java.lang.String pWriteBackTable)
          Returns the meta data information for the specified query, and configures all columns with defaults.
 int getTransactionTimeout()
          Gets the transaction time out.
 java.util.List<Key> getUniqueKeys(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          It gets all columns for each Unique Key and return it.
protected  java.util.List<Key> getUniqueKeysIntern(java.lang.String pCatalog, java.lang.String pSchema, java.lang.String pTable)
          It gets all columns for each Unique Key and return it.
 java.lang.String getUrl()
          Gets the jdbc url String for this database.
 java.lang.String getUsername()
          Gets the user name to connect with.
protected  java.lang.String getWhereClause(ServerMetaData pServerMetaData, ICondition pFilter, java.lang.String pWhereClause, boolean pUsePrefix)
          Returns the WHERE clause for a UPDATE, DELETE or SELECT statement specified with a Filter.
protected static void info(java.lang.Object... pInfo)
          Logs information.
 void initializeColumnMetaData(java.sql.ResultSetMetaData pResultSetMetaData, int pResultSetColumnIndex, ColumnMetaData pColumnMetaData)
          Initilizes the ColumnMetaData with the given ResultSetMetaData.
protected  void initializeDataType(java.sql.ResultSetMetaData pResultSetMetaData, int pResultSetColumnIndex, ColumnMetaData pColumnMetaData)
          Initializes the datatype data of the ColumnMetaData with the given ResultSetMetaData.
protected  ServerColumnMetaData initializeServerColumnMetaData(java.sql.ResultSetMetaData pResultSetMetaData, int pResultSetColumnIndex, java.lang.String pQueryColumn, ServerColumnMetaData pServerColumnMetaData)
          Fills data into the ServerColumnMetaData based on ResultSetMetaData.
 java.lang.Object[] insert(java.lang.String pWriteBackTable, ServerMetaData pServerMetaData, java.lang.Object[] pNewDataRow)
          Returns the newly inserted row from the write back table.
protected  java.lang.Object[] insertAnsiSQL(java.lang.String pWriteBackTable, java.lang.String pInsertStatement, ServerMetaData pServerMetaData, java.lang.Object[] pNewDataRow, java.lang.String pDummyColumn)
          Returns the newly inserted row from a Ansi SQL Database.
protected  java.lang.Object[] insertDatabaseSpecific(java.lang.String pWriteBackTable, java.lang.String pInsertStatement, ServerMetaData pServerMetaData, java.lang.Object[] pNewDataRow, java.lang.String pDummyColumn)
          Returns the newly inserted row from a Database specific insert statement.
 boolean isAutoCommit()
          Gets whether auto-commit is en-/disabled.
 boolean isAutoQuote(java.lang.String pName)
          It returns true if this name should be automated quoted.
 boolean isConnectionPoolEnabled()
          Gets the method of connection pool usage.
static boolean isJdbc(java.lang.String pUrl)
          Gets whether the given URL is a JDBC resource.
protected static boolean isLogEnabled(ILogger.LogLevel pLevel)
          Gets whether the given log level is enabled.
protected  boolean isMetaDataCacheEnabled()
          Gets whether the meta data cache should be used.
 boolean isModified()
          Gets whether the database access is modified.
 boolean isOpen()
          Returns true, if the database is still open.
 boolean isReleaseConnectionPending()
          True, if there is a release connection task waiting.
 boolean isTypeEqual(ServerColumnMetaData pServerColumnMetaData, CompareCondition pCompare)
          Check if the Type of the column and the value to compare is equal.
 void lockRow(java.lang.String pWriteBackTable, ServerMetaData pServerMetaData, ICondition pPKFilter)
          It locks the specified row in the storage.
protected  int lockRowInternal(java.lang.String pWriteBackTable, ServerMetaData pServerMetaData, ICondition pPKFilter)
          It locks the current row and return how many rows are affected.
 void open()
          It opens the database and stores the Connection object.
protected  void prepareConnection(java.sql.Connection pConnection)
          Prepares the given Connection for being used by this DBAccess.
 java.lang.String quote(java.lang.String pName)
          Quotes a named DB object with our internal quote character, if it should be quoted in this database.
 java.lang.String quoteAllways(java.lang.String pName)
          Quotes a named DB object with the JVx DB QUOTE character.
static void registerDBAccessClass(java.lang.String pJdbcUrlPrefix, java.lang.Class<? extends DBAccess> pClass)
          Registers the Class for the jdbc url prefix.
 void releaseConnection()
          Returns the connection to the connection pool.
protected  void releaseConnectionIntern()
          Returns the connection to the connection pool.
 java.lang.String removeDBSpecificQuotes(java.lang.String pName)
          Removes the DB specific quotes of a named DB object.
static java.lang.String removeQuotes(java.lang.String pName)
          Removes the JVx DB Quotes of a named DB object.
 void rollback()
          Rollback the DB transaction.
 void setAutoCommit(boolean pEnable)
          Sets auto-commit state.
static void setAutomaticLinkColumnNameTranslation(TranslationMap pTranslationMap)
          Sets the TranslationMap for the automatic link column name custom Translation. its used in the getAutomaticLinkColName(ForeignKey pForeignKey) to change the column, thats determined.
 void setColumnMetaDataCreator(IColumnMetaDataCreator pColumnMetaDataCreator)
          Sets the column meta data creator for custom column meta data support.
 void setColumnMetaDataCreator(java.lang.Object pListener, java.lang.String pMethodName)
          Sets the column meta data creator for custom column meta data support.
protected  int setColumnsToStore(java.sql.PreparedStatement pInsert, ServerColumnMetaData[] pServerColumnMetaData, int[] iaWriteables, java.lang.Object[] pNew, java.lang.Object[] pOld)
          Sets the values of all changed columns to store from the value Object[]s into the PreparedStatement and returns the last used parameter index.
protected  void setConnection(java.sql.Connection pConnection)
          Sets the internal connection to the database.
protected  void setConnectionPool(IConnectionPool pConnectionPool)
          Sets the internal connection pool to the database.
 void setConnectionPoolEnabled(boolean pConnectionPoolEnabled)
          Sets the method of connection pool usage.
 void setDBProperties(java.util.Properties pProperties)
          Sets DB specific initial parameters for the Connection creation.
 void setDBProperty(java.lang.String pName, java.lang.String pValue)
          Sets a specific database property.
static void setDefaultCursorCacheTimeout(long pDefaultCursorCacheTimeout)
          Sets the default cursor cache timeout in ms.
static void setDefaultLargeObjectLimit(long pDefaultLargeObjectLimit)
          Sets the default value for the limit for what is considered a "large object".
 void setDefaultSchema(java.lang.String pSchema)
          Sets the user-defined default schema.
 void setDriver(java.lang.String pDriver)
          Sets the database driver name as String.
 void setLargeObjectLimit(long pLargeObjectLimit)
          Sets the value for the limit for what is considered a "large object".
 void setMaxTime(int pMaxTime)
          Sets the maximum time in miliseconds to use, to try to fetch all rows. reduce open cursors, and increase performance.
 void setMetaDataCacheOption(MetaDataCacheOption pOption)
          Sets the metadata cache option for this instance.
protected  void setModified(java.lang.Boolean pModified)
          Sets modified state of the connection.
 void setPassword(java.lang.String pPassword)
          Sets the password to use for the connection to the database.
 void setQueryTimeout(int pQueryTimeout)
          Sets the query time out in seconds.
protected  void setQuoteCharacters(java.lang.String pOpen, java.lang.String pClose)
          Sets the database specific quote characters.
 void setTransactionTimeout(int pTransactionTimeout)
          Sets the transaction time out.
 void setUrl(java.lang.String pUrl)
          Sets the url String for this database.
 void setUsername(java.lang.String pUsername)
          Sets the user name to connect with.
protected  java.lang.String[] splitSchemaTable(java.lang.String pFromClause)
          Separates the schema and table from the given from clause.
 boolean supportsGetGeneratedKeys()
          Returns if this Database specific supports generated keys.
 java.lang.String toString()
          
protected  java.lang.Object translateDefaultValue(java.lang.String pColumnName, int pDataType, java.lang.String pDefaultValue)
          Translates a default value from a column to the datatype object.
 java.lang.String translateQuotes(java.lang.String pStatement)
          It replaces all JVx quotes with the database specific quote.
protected  java.lang.Object translateValue(int pDataType, java.lang.String pValue)
          Translates an object value to the datatype object.
 java.lang.Object[] update(java.lang.String pWriteBackTable, ServerMetaData pServerMetaData, java.lang.Object[] pOld, java.lang.Object[] pNew)
          Return the updated row.
 int updateAnsiSQL(java.lang.String pWriteBackTable, java.lang.String sUpdateStatement, ServerMetaData pServerMetaData, java.lang.Object[] pOld, java.lang.Object[] pNew, ICondition pPKFilter)
          Updates the specified row and return the count of affected rows.
 int updateDatabaseSpecific(java.lang.String pWriteBackTable, java.lang.String sUpdateStatement, ServerMetaData pServerMetaData, java.lang.Object[] pOld, java.lang.Object[] pNew, ICondition pPKFilter)
          Updates the specified row and returns the count of affected rows.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NCHAR

public static final int NCHAR
A jdbc VARCHAR DB column data type constant.

See Also:
Constant Field Values

NVARCHAR

public static final int NVARCHAR
A jdbc VARCHAR DB column data type constant.

See Also:
Constant Field Values

LONGNVARCHAR

public static final int LONGNVARCHAR
A jdbc VARCHAR DB column data type constant.

See Also:
Constant Field Values

BFILE

public static final int BFILE
A jdbc BFILE DB column data type constant.

See Also:
Constant Field Values

TIMESTAMPWITHTIMEZONE

public static final int TIMESTAMPWITHTIMEZONE
A jdbc timestamp DB column data type constant.

See Also:
Constant Field Values

TIMESTAMPWITHLOCALTIMEZONE

public static final int TIMESTAMPWITHLOCALTIMEZONE
A jdbc timestamp DB column data type constant.

See Also:
Constant Field Values

SQLXML

public static final int SQLXML
A jdbc XML DB column data type constant.

See Also:
Constant Field Values

NCLOB

public static final int NCLOB
A jdbc BLOB DB column data type constant.

See Also:
Constant Field Values

QUOTE

public static final java.lang.String QUOTE
JVx generell DB quote character. will be translated in the DB specific.

See Also:
Constant Field Values
Constructor Detail

DBAccess

public DBAccess()
Constructs a new DBAccess Object.

Method Detail

getDBAccess

public static DBAccess getDBAccess(java.lang.String pJdbcUrl)
                            throws DataSourceException
Gets the suitable DBAcces for the given JdbcUrl.

Parameters:
pJdbcUrl - the JdbcUrl.
Returns:
the suitable DBAccess.
Throws:
DataSourceException - if the instance name is unknown or the DBAccess object cannot be created.

getDBAccess

public static DBAccess getDBAccess(java.lang.String pJdbcUrl,
                                   java.lang.String pOptionalUserName,
                                   java.lang.String pOptionalPassword)
                            throws DataSourceException
Gets the suitable DBAcces for the given JdbcUrl.

Parameters:
pJdbcUrl - the JdbcUrl.
pOptionalUserName - optional username for the connection
pOptionalPassword - optional password for the connection
Returns:
the suitable DBAccess.
Throws:
DataSourceException - if the instance name is unknown or the DBAccess object cannot be created.

getDBAccess

public static DBAccess getDBAccess(DBCredentials pCredentials)
                            throws DataSourceException
Gets the suitable DBAccess for the given DBCredentials.

Parameters:
pCredentials - the database credentials.
Returns:
the suitable DBAccess.
Throws:
DataSourceException - if the instance name is unknown or the DBAccess object cannot be created.

getDBAccess

public static DBAccess getDBAccess(java.sql.Connection pConnection)
                            throws DataSourceException
Gets the suitable DBAccess for the given external connection. The external won't be closed automatically.

Parameters:
pConnection - the database connection.
Returns:
the suitable DBAccess.
Throws:
DataSourceException - if the instance name is unknown or the DBAccess object cannot be created.

getDBAccess

public static DBAccess getDBAccess(IConnectionPool pConnectionPool)
                            throws DataSourceException
Gets the suitable DBAccess for the given connection pool.

Parameters:
pConnectionPool - the connection pool.
Returns:
the suitable DBAccess.
Throws:
DataSourceException - if the instance name is unknown or the DBAccess object cannot be created.

registerDBAccessClass

public static void registerDBAccessClass(java.lang.String pJdbcUrlPrefix,
                                         java.lang.Class<? extends DBAccess> pClass)
Registers the Class for the jdbc url prefix.

Parameters:
pJdbcUrlPrefix - the jdbc url prefix.
pClass - the Class.

setAutomaticLinkColumnNameTranslation

public static void setAutomaticLinkColumnNameTranslation(TranslationMap pTranslationMap)
Sets the TranslationMap for the automatic link column name custom Translation. its used in the getAutomaticLinkColName(ForeignKey pForeignKey) to change the column, thats determined. Default is *_ID to *, and *_id to *.

Parameters:
pTranslationMap - the TranslationMap to use.

getAutomaticLinkColumnNameTranslation

public static TranslationMap getAutomaticLinkColumnNameTranslation()
Returns the TranslationMap for the automatic link column name custom Translation. its used in the getAutomaticLinkColName(ForeignKey pForeignKey) to change the column, thats determined. Default is *_ID to *, and *_id to *.

Returns:
the TranslationMap for the automatic link column name custom Translation.

getDefaultCursorCacheTimeout

public static long getDefaultCursorCacheTimeout()
Gets the default cursor cache timeout in ms. by default it is 1 hour.

Returns:
the default cursor cache timeout in ms.

setDefaultCursorCacheTimeout

public static void setDefaultCursorCacheTimeout(long pDefaultCursorCacheTimeout)
Sets the default cursor cache timeout in ms. by default it is 1 hour.

Parameters:
pDefaultCursorCacheTimeout - the default cursor cache timeout in ms.

getDefaultLargeObjectLimit

public static long getDefaultLargeObjectLimit()
Gets the default value for the limit for what is considered a "large object". This limit is used for columns which have the fetchLargObjectsLazy option set to determine if the current object should be lazily fetched or not. "Lazy" means that the object is only send to the client if the value is actually requested. It is still fetched from the datasource and cached on the server side. Note that the default limit is only applied to new instances of DBAccess.

Returns:
the default limit for what is considered a "large object".

setDefaultLargeObjectLimit

public static void setDefaultLargeObjectLimit(long pDefaultLargeObjectLimit)
Sets the default value for the limit for what is considered a "large object". This limit is used for columns which have the fetchLargObjectsLazy option set to determine if the current object should be lazily fetched or not. "Lazy" means that the object is only send to the client if the value is actually requested. It is still fetched from the datasource and cached on the server side. Note that the default limit is only applied to new instances of DBAccess.

Parameters:
pDefaultLargeObjectLimit - the new default limit.

getUniqueKeysIntern

protected java.util.List<Key> getUniqueKeysIntern(java.lang.String pCatalog,
                                                  java.lang.String pSchema,
                                                  java.lang.String pTable)
                                           throws DataSourceException
It gets all columns for each Unique Key and return it.

Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use
Returns:
all columns for each Unique Key.
Throws:
DataSourceException - if an error occur during UK search process.

getLargeObjectLimit

public long getLargeObjectLimit()
Gets the value for the limit for what is considered a "large object". This limit is used for columns which have the fetchLargObjectsLazy option set to determine if the current object should be lazily fetched or not. "Lazy" means that the object is only send to the client if the value is actually requested. It is still fetched from the datasource and cached on the server side.

Returns:
the current limit.

getPrimaryKeyIntern

protected Key getPrimaryKeyIntern(java.lang.String pCatalog,
                                  java.lang.String pSchema,
                                  java.lang.String pTable)
                           throws DataSourceException
It's gets all Primary Key columns and return it as String[]. Gets all Primary Key columns and return it as list of Strings.

Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use
Returns:
all Primary Key columns and return it as String[].
Throws:
DataSourceException - if an error occur during PK search process.

getForeignKeysIntern

protected java.util.List<ForeignKey> getForeignKeysIntern(java.lang.String pCatalog,
                                                          java.lang.String pSchema,
                                                          java.lang.String pTable)
                                                   throws DataSourceException
Returns all Foreign Keys for the specified table.

Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use as base table.
Returns:
all Foreign Keys for the specified table.
Throws:
DataSourceException - if an error occur in determining the ForeignKeys.

getUniqueKeys

public final java.util.List<Key> getUniqueKeys(java.lang.String pCatalog,
                                               java.lang.String pSchema,
                                               java.lang.String pTable)
                                        throws DataSourceException
It gets all columns for each Unique Key and return it.

Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use
Returns:
all columns for each Unique Key.
Throws:
DataSourceException - if an error occur during UK search process.

getPrimaryKey

public final Key getPrimaryKey(java.lang.String pCatalog,
                               java.lang.String pSchema,
                               java.lang.String pTable)
                        throws DataSourceException
It's gets all Primary Key columns and return it as String[].

Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use
Returns:
all Primary Key columns and return it as String[].
Throws:
DataSourceException - if an error occur during PK search process.

getForeignKeys

public final java.util.List<ForeignKey> getForeignKeys(java.lang.String pCatalog,
                                                       java.lang.String pSchema,
                                                       java.lang.String pTable)
                                                throws DataSourceException
Returns all Foreign Keys for the specified table.

Parameters:
pCatalog - the catalog to use
pSchema - the schema to use
pTable - the table to use as base table.
Returns:
all Foreign Keys for the specified table.
Throws:
DataSourceException - if an error occur in determining the ForeignKeys.

getTableForSynonym

public final java.lang.String getTableForSynonym(java.lang.String pSynomyn)
                                          throws DataSourceException
Returns the full qualified table name incl. schema/catalog/db link for the given synonym. If pSynomyn is no synonym, then the pSynomyn string is returned.

Parameters:
pSynomyn - the synonym to use.
Returns:
the full qualified table name incl. schema/catalog/db link for the given synonym.
Throws:
DataSourceException - if an error occur in determining the synonyms.

getTableForSynonymIntern

protected java.lang.String getTableForSynonymIntern(java.lang.String pSynomyn)
                                             throws DataSourceException
Returns the full qualified table name incl. schema/catalog/db link for the given synonym. If pSynomyn is no synonym, then the pSynomyn string is returned.

Parameters:
pSynomyn - the synonym to use.
Returns:
the full qualified table name incl. schema/catalog/db link for the given synonym.
Throws:
DataSourceException - if an error occur in determining the synonyms.

fetch

public java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData,
                                                java.lang.String pBeforeQueryColumns,
                                                java.lang.String[] pQueryColumns,
                                                java.lang.String pFromClause,
                                                ICondition pFilter,
                                                java.lang.String pWhereCondition,
                                                java.lang.String pAfterWhereClause,
                                                SortDefinition pSort,
                                                int pFromRow,
                                                int pMinimumRowCount,
                                                boolean pAllowLazyFetch)
                                         throws DataSourceException
Returns the List of fetched rows (as List of Object[]) for the specified query tables and parameters. It fetch's the the rows from pFromRow row index a minimum amount of pMinimumRowCount rows. Implementations should fetch as much rows as possible in a proper amount of time, to get less requests from the client model to the server IDBAccess. Implementation can cache the select cursor and reuse it for the next fetch operation, but they should take care, that's a state less call and in a fall over case it maybe loose on the fail over system the cursor.

Specified by:
fetch in interface IDBAccess
Parameters:
pServerMetaData - the MetaDataColumn array to use.
pBeforeQueryColumns - the before query columns
pQueryColumns - the query columns
pFromClause - the from clause with query tables and join definitions
pFilter - the filter to use
pWhereCondition - the last where condition in query
pAfterWhereClause - the after where clause in query
pSort - the sort order to use
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
pAllowLazyFetch - if lazy fetch should be allowed.
Returns:
the List of fetched rows (as List of Object[]) for the specified query tables and parameters.
Throws:
DataSourceException - if the fetch fails.

fetch

public java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData,
                                                java.lang.String pBeforeQueryColumns,
                                                java.lang.String[] pQueryColumns,
                                                java.lang.String pFromClause,
                                                ICondition pFilter,
                                                java.lang.String pWhereCondition,
                                                java.lang.String pAfterWhereClause,
                                                SortDefinition pSort,
                                                int pFromRow,
                                                int pMinimumRowCount)
                                         throws DataSourceException
Returns the List of fetched rows (as List of Object[]) for the specified query tables and parameters. It fetch's the the rows from pFromRow row index a minimum amount of pMinimumRowCount rows. Implementations should fetch as much rows as possible in a proper amount of time, to get less requests from the client model to the server IDBAccess. Implementation can cache the select cursor and reuse it for the next fetch operation, but they should take care, that's a state less call and in a fall over case it maybe loose on the fail over system the cursor.

Parameters:
pBeforeQueryColumns - the before query columns
pQueryColumns - the query columns
pFromClause - the from clause with query tables and join definitions
pFilter - the filter to use
pWhereCondition - the last where condition in query
pAfterWhereClause - the after where clause in query
pSort - the sort order to use
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
pServerMetaData - the MetaDataColumn array to use.
Returns:
the List of fetched rows (as List of Object[]) for the specified query tables and parameters.
Throws:
DataSourceException - if the fetch fails.

fetch

public java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData,
                                                java.lang.String pBeforeQueryColumns,
                                                java.lang.String[] pQueryColumns,
                                                java.lang.String pFromClause,
                                                ICondition pFilter,
                                                java.lang.String pWhereCondition,
                                                java.lang.String pAfterWhereClause,
                                                SortDefinition pSort,
                                                java.lang.String pOrderByClause,
                                                int pFromRow,
                                                int pMinimumRowCount)
                                         throws DataSourceException
Mostly same as fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int). This fetch does accept an additional order by clause which will be used if the given default sort is null.

Parameters:
pBeforeQueryColumns - the before query columns
pQueryColumns - the query columns
pFromClause - the from clause with query tables and join definitions
pFilter - the filter to use
pWhereCondition - the last where condition in query
pAfterWhereClause - the after where clause in query
pOrderByClause - the order by clause
pSort - the sort order to use
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
pServerMetaData - the MetaDataColumn array to use.
Returns:
the List of fetched rows (as List of Object[]) for the specified query tables and parameters.
Throws:
DataSourceException - if the fetch fails.

fetch

public java.util.List<java.lang.Object[]> fetch(ServerMetaData pServerMetaData,
                                                java.lang.String pBeforeQueryColumns,
                                                java.lang.String[] pQueryColumns,
                                                java.lang.String pFromClause,
                                                ICondition pFilter,
                                                java.lang.String pWhereCondition,
                                                java.lang.String pAfterWhereClause,
                                                SortDefinition pSort,
                                                java.lang.String pOrderByClause,
                                                int pFromRow,
                                                int pMinimumRowCount,
                                                boolean pAllowLazyFetch)
                                         throws DataSourceException
Mostly same as fetch(ServerMetaData, String, String[], String, ICondition, String, String, SortDefinition, int, int). This fetch does accept an additional order by clause which will be used if the given default sort is null.

Parameters:
pBeforeQueryColumns - the before query columns
pQueryColumns - the query columns
pFromClause - the from clause with query tables and join definitions
pFilter - the filter to use
pWhereCondition - the last where condition in query
pAfterWhereClause - the after where clause in query
pOrderByClause - the order by clause
pSort - the sort order to use
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
pServerMetaData - the MetaDataColumn array to use.
pAllowLazyFetch - if lazy fetch should be allowed.
Returns:
the List of fetched rows (as List of Object[]) for the specified query tables and parameters.
Throws:
DataSourceException - if the fetch fails.

lockRow

public void lockRow(java.lang.String pWriteBackTable,
                    ServerMetaData pServerMetaData,
                    ICondition pPKFilter)
             throws DataSourceException
It locks the specified row in the storage.

Specified by:
lockRow in interface IDBAccess
Parameters:
pWriteBackTable - the storage unit to use
pServerMetaData - the MetaDataColumn array to use.
pPKFilter - the PrimaryKey in as an ICondition to identify the row to lock
Throws:
DataSourceException - if an Exception occur during interacting with the storage

lockRowInternal

protected int lockRowInternal(java.lang.String pWriteBackTable,
                              ServerMetaData pServerMetaData,
                              ICondition pPKFilter)
                       throws DataSourceException
It locks the current row and return how many rows are affected.

Parameters:
pWriteBackTable - the storage unit to use
pPKFilter - the PrimaryKey in as an ICondition to identify the row to lock
pServerMetaData - the MetaDataColumn array to use.
Returns:
the counts of affected rows
Throws:
DataSourceException - if an Exception occur during interacting with the storage

insert

public java.lang.Object[] insert(java.lang.String pWriteBackTable,
                                 ServerMetaData pServerMetaData,
                                 java.lang.Object[] pNewDataRow)
                          throws DataSourceException
Returns the newly inserted row from the write back table.

Specified by:
insert in interface IDBAccess
Parameters:
pWriteBackTable - the write back table to use.
pServerMetaData - the meta data to use.
pNewDataRow - the new values Object[] to insert.
Returns:
the newly inserted row as Object[] from the write back table.
Throws:
DataSourceException - if an Exception occur during insert the row to the table

setLargeObjectLimit

public void setLargeObjectLimit(long pLargeObjectLimit)
Sets the value for the limit for what is considered a "large object". This limit is used for columns which have the fetchLargObjectsLazy option set to determine if the current object should be lazily fetched or not. "Lazy" means that the object is only send to the client if the value is actually requested. It is still fetched from the datasource and cached on the server side.

Parameters:
pLargeObjectLimit - the new limit.

update

public java.lang.Object[] update(java.lang.String pWriteBackTable,
                                 ServerMetaData pServerMetaData,
                                 java.lang.Object[] pOld,
                                 java.lang.Object[] pNew)
                          throws DataSourceException
Return the updated row.

Specified by:
update in interface IDBAccess
Parameters:
pWriteBackTable - the write back table to use.
pServerMetaData - the meta data to use.
pOld - the old values of the row
pNew - the new values of the row
Returns:
the updated row.
Throws:
DataSourceException - if an Exception occur during update.

updateDatabaseSpecific

public int updateDatabaseSpecific(java.lang.String pWriteBackTable,
                                  java.lang.String sUpdateStatement,
                                  ServerMetaData pServerMetaData,
                                  java.lang.Object[] pOld,
                                  java.lang.Object[] pNew,
                                  ICondition pPKFilter)
                           throws DataSourceException
Updates the specified row and returns the count of affected rows.
Database specific implementation should override this method to implement the specific update code.

Parameters:
pWriteBackTable - the table to use for the update
sUpdateStatement - the SQL Statement to use for the update
pServerMetaData - the meta data to use.
pOld - the old row (values) to use.
pNew - the new row (values) to use.
pPKFilter - the PrimaryKey equals filter to use.
Returns:
the count of updates rows from a Ansi SQL Database.
Throws:
DataSourceException - if an Exception occur during update to the storage

updateAnsiSQL

public int updateAnsiSQL(java.lang.String pWriteBackTable,
                         java.lang.String sUpdateStatement,
                         ServerMetaData pServerMetaData,
                         java.lang.Object[] pOld,
                         java.lang.Object[] pNew,
                         ICondition pPKFilter)
                  throws DataSourceException
Updates the specified row and return the count of affected rows.

Parameters:
pWriteBackTable - the table to use for the update
sUpdateStatement - the SQL Statement to use for the update
pServerMetaData - the meta data to use.
pOld - the old row (values) to use.
pNew - the new row (values) to use.
pPKFilter - the PrimaryKey equals filter to use.
Returns:
the count of updates rows from a Ansi SQL Database.
Throws:
DataSourceException - if an Exception occur during update to the storage

delete

public void delete(java.lang.String pWriteBackTable,
                   ServerMetaData pServerMetaData,
                   java.lang.Object[] pDelete)
            throws DataSourceException
Deletes the specified row.

Specified by:
delete in interface IDBAccess
Parameters:
pWriteBackTable - the write back table to use.
pServerMetaData - the meta data to use.
pDelete - the row to delete.
Throws:
DataSourceException - if an Exception occur during delete.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

getOpenQuoteCharacter

public java.lang.String getOpenQuoteCharacter()
Gets the database specific open quote character.

Returns:
the open quote character

getCloseQuoteCharacter

public java.lang.String getCloseQuoteCharacter()
Gets the database specific quote character.

Returns:
the close quote character

setQuoteCharacters

protected void setQuoteCharacters(java.lang.String pOpen,
                                  java.lang.String pClose)
Sets the database specific quote characters.

Parameters:
pOpen - the open quote character
pClose - the close quote character

isAutoQuote

public boolean isAutoQuote(java.lang.String pName)
It returns true if this name should be automated quoted. e.g. in Oracle default all isUppercase(), so if the name has one loweCase character, then AutoQuote is true to quote this name.

Parameters:
pName - the name to quote.
Returns:
true if this name should be automated quoted.

quote

public java.lang.String quote(java.lang.String pName)
Quotes a named DB object with our internal quote character, if it should be quoted in this database. Thats the case if the name != to the default case sensitivness. e.g. in Oracle != upperCase()

Parameters:
pName - the name to use.
Returns:
the quoted name if quoting in this database is necessary or otherwise just the name.

quoteAllways

public java.lang.String quoteAllways(java.lang.String pName)
Quotes a named DB object with the JVx DB QUOTE character.

Parameters:
pName - the name to use.
Returns:
the name quoted.

removeQuotes

public static java.lang.String removeQuotes(java.lang.String pName)
Removes the JVx DB Quotes of a named DB object.

Parameters:
pName - the name to use.
Returns:
the unquoted name.

removeDBSpecificQuotes

public java.lang.String removeDBSpecificQuotes(java.lang.String pName)
Removes the DB specific quotes of a named DB object.

Parameters:
pName - the name to use.
Returns:
the unquoted name.

translateQuotes

public java.lang.String translateQuotes(java.lang.String pStatement)
It replaces all JVx quotes with the database specific quote.

Parameters:
pStatement - the statement to use.
Returns:
the database specific quoted statement.

open

public void open()
          throws DataSourceException
It opens the database and stores the Connection object.

Throws:
DataSourceException - if the database couldn't opened

isOpen

public boolean isOpen()
               throws DataSourceException
Returns true, if the database is still open.

Returns:
true, if the database is still open.
Throws:
DataSourceException - if isClosed() on the DB Connection throws an Exception

close

public void close()
           throws DataSourceException
Closes the database Connection and releases all memory.

Specified by:
close in interface ICloseable
Throws:
DataSourceException - if database couldn't closed.

commitOrRollbackBeforeClose

protected void commitOrRollbackBeforeClose()
Calls commit or rollback before closing the connection.


setAutoCommit

public void setAutoCommit(boolean pEnable)
                   throws DataSourceException
Sets auto-commit state.

Parameters:
pEnable - true to enable, false to disable auto-commit
Throws:
DataSourceException - if setting state failed

isAutoCommit

public boolean isAutoCommit()
Gets whether auto-commit is en-/disabled.

Returns:
true if enabled, false otherwise

rollback

public void rollback()
              throws DataSourceException
Rollback the DB transaction.

Throws:
DataSourceException - if the transaction couldn't rollback

commit

public void commit()
            throws DataSourceException
Commits the DB transaction.

Throws:
DataSourceException - if the transaction couldn't commit

getQueryTimeout

public int getQueryTimeout()
Gets the query time out. default is -1 a value < 0 means, it is not set on statement a value > 0 means the time out in seconds.

Returns:
the timeout in seconds

setQueryTimeout

public void setQueryTimeout(int pQueryTimeout)
Sets the query time out in seconds. default is -1 a value < 0 means, it is not set on statement a value > 0 means the time out in seconds.

Parameters:
pQueryTimeout - the timeout in seconds

getTransactionTimeout

public int getTransactionTimeout()
Gets the transaction time out. default is -1 0 (no timeout) a value < 0 means, it is not set on statement a value > 0 means the time out in seconds.

Returns:
the timeout in seconds

setTransactionTimeout

public void setTransactionTimeout(int pTransactionTimeout)
Sets the transaction time out. default is -1 0 (no timeout) a value < 0 means, it is not set on statement a value > 0 means the time out in seconds.

Parameters:
pTransactionTimeout - the timeout in seconds

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns the connection to the database.

Returns:
the connection to the database.
Throws:
java.sql.SQLException - if connection is not available.

getConnectionIntern

protected java.sql.Connection getConnectionIntern()
                                           throws java.sql.SQLException
Returns the connection to the database. This includes getting the connection from the pool, if needed.

Returns:
the connection to the database.
Throws:
java.sql.SQLException - if connection is not available.

releaseConnection

public void releaseConnection()
                       throws DataSourceException
Returns the connection to the connection pool.

Throws:
DataSourceException - if the DBAccess is in modified state, and the connection cannot be released.

isReleaseConnectionPending

public boolean isReleaseConnectionPending()
True, if there is a release connection task waiting.

Returns:
True, if there is a release connection task waiting.

releaseConnectionIntern

protected void releaseConnectionIntern()
Returns the connection to the connection pool.


setConnection

protected void setConnection(java.sql.Connection pConnection)
Sets the internal connection to the database.

Parameters:
pConnection - the connection to the database

getConnectionPool

public IConnectionPool getConnectionPool()
Returns the conncetion to the database.

Returns:
the conncetion to the database.

setConnectionPool

protected void setConnectionPool(IConnectionPool pConnectionPool)
Sets the internal connection pool to the database.

Parameters:
pConnectionPool - the connection pool to the database

isConnectionPoolEnabled

public boolean isConnectionPoolEnabled()
Gets the method of connection pool usage.
ReleaseOnClose: releases the connection, when the DBAccess is closed. This is the default behaviour.
ReleaseOnCommitRollback: releases the connection, when the commit or rollback is closed.
ReleaseAfterLastCall: releases the connection, after the last call.

Returns:
the connection pool method

setConnectionPoolEnabled

public void setConnectionPoolEnabled(boolean pConnectionPoolEnabled)
Sets the method of connection pool usage.
ReleaseOnClose: releases the connection, when the DBAccess is closed. This is the default behaviour.
ReleaseOnCommitRollback: releases the connection, when the commit or rollback is closed.
ReleaseAfterLastCall: releases the connection, after the last call.

Parameters:
pConnectionPoolEnabled - the connection pool method

eventConfigureConnection

public EventHandler<IConfigureConnectionListener> eventConfigureConnection()
The event configure connection is always dispatched, when a new connection is used by this DBAccess. This can either be due to opening the DBAccess or due to getting a new connection from the connection pool.

Returns:
return the event handler for configuring the

eventUnconfigureConnection

public EventHandler<IUnconfigureConnectionListener> eventUnconfigureConnection()
The event configure connection is always dispatched, when a new connection is used by this DBAccess. This can either be due to opening the DBAccess or due to getting a new connection from the connection pool.

Returns:
return the event handler for configuring the

fireEventConfigureConnection

protected void fireEventConfigureConnection()
                                     throws java.sql.SQLException
Fires the event configureConnection.

Throws:
java.sql.SQLException - if the event causes an exception.

fireEventUnconfigureConnection

protected void fireEventUnconfigureConnection()
Fires the event unconfigureConnection.


getDriver

public java.lang.String getDriver()
Gets the database driver name as String.

Returns:
pDriverName the database driver name

setDriver

public void setDriver(java.lang.String pDriver)
Sets the database driver name as String.

Parameters:
pDriver - the database driver name

getUrl

public java.lang.String getUrl()
Gets the jdbc url String for this database.

Returns:
the jdbc url String.

setUrl

public void setUrl(java.lang.String pUrl)
Sets the url String for this database.

Parameters:
pUrl - the jdbc url String.

getUsername

public java.lang.String getUsername()
Gets the user name to connect with.

Returns:
pUser the user name

setUsername

public void setUsername(java.lang.String pUsername)
Sets the user name to connect with.

Parameters:
pUsername - the user name

getPassword

public java.lang.String getPassword()
Sets the password to use for the connection to the database.

Returns:
pPassword the password to use for the database

setPassword

public void setPassword(java.lang.String pPassword)
Sets the password to use for the connection to the database.

Parameters:
pPassword - the password to use for the database

setDBProperty

public void setDBProperty(java.lang.String pName,
                          java.lang.String pValue)
Sets a specific database property.

Parameters:
pName - the property name
pValue - th value

getDBProperty

public java.lang.String getDBProperty(java.lang.String pName)
Gets the value for a specific database property.

Parameters:
pName - the property name
Returns:
the value or null if the property was not found

setDBProperties

public void setDBProperties(java.util.Properties pProperties)
Sets DB specific initial parameters for the Connection creation.

Parameters:
pProperties - DB specific initial parameters

getDBProperties

public java.util.Properties getDBProperties()
Returns the DB specific initial parameters for the Connection creation.

Returns:
the DB specific initial parameters for the Connection creation.

getMaxTime

public int getMaxTime()
Returns the maximum time in miliseconds to use, to try to fetch all rows. reduce open cursors, and increase performance.

Returns:
the iMaxTime.

setMaxTime

public void setMaxTime(int pMaxTime)
Sets the maximum time in miliseconds to use, to try to fetch all rows. reduce open cursors, and increase performance.

Parameters:
pMaxTime - the iMaxTime to set

getMaxColumnLength

public int getMaxColumnLength()
Returns the maximum allowed column length.

Returns:
the iMaxColumnLength.

getColumnMetaDataCreator

public IColumnMetaDataCreator getColumnMetaDataCreator()
Gets the column meta data creator for custom column meta data support.

Returns:
the column meta data creator for custom column meta data support.

setColumnMetaDataCreator

public void setColumnMetaDataCreator(IColumnMetaDataCreator pColumnMetaDataCreator)
Sets the column meta data creator for custom column meta data support.

Parameters:
pColumnMetaDataCreator - the column meta data creator for custom column meta data support.

setColumnMetaDataCreator

public void setColumnMetaDataCreator(java.lang.Object pListener,
                                     java.lang.String pMethodName)
Sets the column meta data creator for custom column meta data support.

Parameters:
pListener - the listener instance.
pMethodName - the method name.

executeProcedure

public void executeProcedure(java.lang.String pProcedureName,
                             java.lang.Object... pParameters)
                      throws java.sql.SQLException
Executes a DB procedure with the specified parameters.

Parameters:
pProcedureName - the procedure (optional with package) name.
pParameters - the parameters to use with the correct and corresponding java type.
Throws:
java.sql.SQLException - if the call failed.

executeFunction

public java.lang.Object executeFunction(java.lang.String pFunctionName,
                                        int pReturnType,
                                        java.lang.Object... pParameters)
                                 throws java.sql.SQLException
Executes a DB function with the specified parameters and return the result.

Parameters:
pFunctionName - the function (optional with package) name.
pReturnType - the return SQL Type (see Types
pParameters - the parameters to use with the correct and corresponding java type.
Returns:
the result of the DB function call.
Throws:
java.sql.SQLException - if the call failed.

executeFunction

public java.lang.Object executeFunction(java.lang.String pFunctionName,
                                        OutParam pReturnOutParam,
                                        java.lang.Object... pParameters)
                                 throws java.sql.SQLException
Executes a DB function with the specified parameters and return the result.

Parameters:
pFunctionName - the function (optional with package) name.
pReturnOutParam - the return SQL Type (see Types
pParameters - the parameters to use with the correct and corresponding java type.
Returns:
the result of the DB function call.
Throws:
java.sql.SQLException - if the call failed.

executeStatement

public int executeStatement(java.lang.String pStatement,
                            java.lang.Object... pParameters)
                     throws java.sql.SQLException
Executes a DDL or DML Statement.

Parameters:
pStatement - the statement.
pParameters - the parameters.
Returns:
the numberof the affected rows.
Throws:
java.sql.SQLException - if an error occur during execution.

executeQuery

public java.util.List<Bean> executeQuery(java.lang.String pStatement,
                                         java.lang.Object... pParameters)
                                  throws java.sql.SQLException
Executes a SQL query as prepared statement.

Parameters:
pStatement - the statement with or without parameters
pParameters - the parameters to use
Returns:
the first parameter from the result set, for every row, or null if the command returned no result
Throws:
java.sql.SQLException - if an error occurs during execution

executeSql

public java.util.List<java.lang.Object> executeSql(java.lang.String pStatement,
                                                   java.lang.Object... pParameters)
                                            throws java.sql.SQLException
Executes a SQL command as prepared statement.

Parameters:
pStatement - the statement with or without parameters
pParameters - the parameters to use
Returns:
the first parameter from the result set, for every row, or null if the command returned no result
Throws:
java.sql.SQLException - if an error occurs during execution

executeSqlMulti

protected java.util.List<java.lang.Object> executeSqlMulti(java.lang.String pStatement,
                                                           int pResultColumn,
                                                           java.lang.Object... pParameters)
                                                    throws java.sql.SQLException
Executes a SQL command as prepared statement.

Parameters:
pStatement - the statement with or without parameters
pResultColumn - the column index which contains the result value. If you set -1 all column values will be returned as Object[]
pParameters - the parameters to use
Returns:
the first parameter from the result set, for every row, or null if the command returned no result
Throws:
java.sql.SQLException - if an error occurs during execution

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.lang.String pSqlStatement)
                                                throws java.sql.SQLException
Return a PreparedStatement for the given SQL statement.

Parameters:
pSqlStatement - the SQL statement to prepare
Returns:
a PreparedStatement for the given SQL statement.
Throws:
java.sql.SQLException - if the statement couldn't prepared.

getPreparedStatement

protected java.sql.PreparedStatement getPreparedStatement(java.lang.String pSqlStatement,
                                                          boolean pReturnGeneratedKeys)
                                                   throws java.sql.SQLException
Return a PreparedStatement for the given SQL statement.

Parameters:
pSqlStatement - the SQL statement to prepare
pReturnGeneratedKeys - if the generated key in insert statements should returned
Returns:
a PreparedStatement for the given SQL statement.
Throws:
java.sql.SQLException - if the statement couldn't prepared.

formatSQLException

protected java.sql.SQLException formatSQLException(java.sql.SQLException pSqlException)
Adds the SQL Error Code into the message of the SQL Exception.

Parameters:
pSqlException - the SQL Exception to use.
Returns:
the SQLException with the modified error message with SQL Error Code.

formatSQLException

protected java.sql.SQLException formatSQLException(java.sql.SQLException pSqlException,
                                                   java.lang.String pMessage,
                                                   java.lang.String pCode)
Adds the SQL Error Code into the message of the SQL Exception.

Parameters:
pSqlException - the SQL Exception to use.
pMessage - the message to use
pCode - the detected error code
Returns:
the SQLException with the modified error message with SQL Error Code.

getParameterizedSelectStatement

public DBAccess.ParameterizedStatement getParameterizedSelectStatement(ServerMetaData pServerMetaData,
                                                                       java.lang.String pBeforeQueryColumns,
                                                                       java.lang.String[] pQueryColumns,
                                                                       java.lang.String pFromClause,
                                                                       ICondition pFilter,
                                                                       java.lang.String pWhereClause,
                                                                       java.lang.String pAfterWhereClause,
                                                                       SortDefinition pSort,
                                                                       java.lang.String pOrderByClause,
                                                                       int pFromRow,
                                                                       int pMinimumRowCount)
                                                                throws DataSourceException
Creates the DBAccess.ParameterizedStatement and returns it.

Note that this function is subject to be changed in a future version, and can there for not be considered stable.

Parameters:
pServerMetaData - the MetaDataColumn array to use.
pBeforeQueryColumns - the string to place in the SELECT statement between the SELECT and the first query column.
pQueryColumns - the list of query columns to use in the SELECT statement.
pFromClause - the list of query tables to use in the SELECT statement.
pFilter - the Filter to use
pWhereClause - the string to place in the SELECT statement after the last WHERE condition from the Filter or MasterReference (Master-Detail Condition).
pAfterWhereClause - the string to place in the SELECT statement after the WHERE clause and before the ORDER BY clause.
pSort - the sort definition.
pOrderByClause - the order by clause.
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
Returns:
the SELECT statement as String.
Throws:
DataSourceException - if it's not possible to build the select statement in fact of missing elements

getSelectStatement

public java.lang.String getSelectStatement(ServerMetaData pServerMetaData,
                                           java.lang.String pBeforeQueryColumns,
                                           java.lang.String[] pQueryColumns,
                                           java.lang.String pFromClause,
                                           ICondition pFilter,
                                           java.lang.String pWhereClause,
                                           java.lang.String pAfterWhereClause,
                                           SortDefinition pSort,
                                           java.lang.String pOrderByClause,
                                           int pFromRow,
                                           int pMinimumRowCount)
                                    throws DataSourceException
It initialize the select for a specified storage unit and return the SELECT statement.
It doesn't add the ORDER BY clause.

Parameters:
pServerMetaData - the MetaDataColumn array to use.
pBeforeQueryColumns - the string to place in the SELECT statement between the SELECT and the first query column.
pQueryColumns - the list of query columns to use in the SELECT statement.
pFromClause - the list of query tables to use in the SELECT statement.
pFilter - the Filter to use
pWhereClause - the string to place in the SELECT statement after the last WHERE condition from the Filter or MasterReference (Master-Detail Condition).
pAfterWhereClause - the string to place in the SELECT statement after the WHERE clause and before the ORDER BY clause.
pSort - the sort definition.
pOrderByClause - the order by clause.
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
Returns:
the SELECT statement as String.
Throws:
DataSourceException - if it's not possible to build the select statement in fact of missing elements

getSelectStatement

public java.lang.String getSelectStatement(ServerMetaData pServerMetaData,
                                           java.lang.String pBeforeQueryColumns,
                                           java.lang.String[] pQueryColumns,
                                           java.lang.String pFromClause,
                                           ICondition pFilter,
                                           java.lang.String pWhereClause,
                                           java.lang.String pAfterWhereClause,
                                           SortDefinition pSort,
                                           java.lang.String pOrderByClause)
                                    throws DataSourceException
It initialize the select for a specified storage unit and return the SELECT statement.
It doesn't add the ORDER BY clause.

Parameters:
pServerMetaData - the MetaDataColumn array to use.
pBeforeQueryColumns - the string to place in the SELECT statement between the SELECT and the first query column.
pQueryColumns - the list of query columns to use in the SELECT statement.
pFromClause - the list of query tables to use in the SELECT statement.
pFilter - the Filter to use
pWhereClause - the string to place in the SELECT statement after the last WHERE condition from the Filter or MasterReference (Master-Detail Condition).
pAfterWhereClause - the string to place in the SELECT statement after the WHERE clause and before the ORDER BY clause.
pSort - the sort definition.
pOrderByClause - the order by clause.
Returns:
the SELECT statement as String.
Throws:
DataSourceException - if it's not possible to build the select statement in fact of missing elements

getWhereClause

protected java.lang.String getWhereClause(ServerMetaData pServerMetaData,
                                          ICondition pFilter,
                                          java.lang.String pWhereClause,
                                          boolean pUsePrefix)
                                   throws DataSourceException
Returns the WHERE clause for a UPDATE, DELETE or SELECT statement specified with a Filter.

Parameters:
pServerMetaData - the MetaData to use
pFilter - the Filter to use
pWhereClause - the where clause to use
pUsePrefix - true to use the prefixed column (real column name) and false to ignore prefixes (the simple name of the column)
Returns:
the WHERE clause for a UPDATE, DELETE or SELECT statement specified with a Filter.
Throws:
DataSourceException - if columns not existing

getDatabaseSpecificLockStatement

protected java.lang.String getDatabaseSpecificLockStatement(java.lang.String pWriteBackTable,
                                                            ServerMetaData pServerMetaData,
                                                            ICondition pPKFilter)
                                                     throws DataSourceException
Returns the database specific statement to lock the specified row in the database.

Parameters:
pWriteBackTable - the table to use.
pPKFilter - the PK filter with the values to use.
pServerMetaData - the MetaDataColumn array to use.
Returns:
the database specific statement to lock the specified row in the database.
Throws:
DataSourceException - if some parts are missing for the statement

insertDatabaseSpecific

protected java.lang.Object[] insertDatabaseSpecific(java.lang.String pWriteBackTable,
                                                    java.lang.String pInsertStatement,
                                                    ServerMetaData pServerMetaData,
                                                    java.lang.Object[] pNewDataRow,
                                                    java.lang.String pDummyColumn)
                                             throws DataSourceException
Returns the newly inserted row from a Database specific insert statement.
Database specific derivations of DBAccess need to implement it database specific.

Parameters:
pWriteBackTable - the table to use for the insert
pInsertStatement - the SQL Statement to use for the insert
pServerMetaData - the meta data to use.
pNewDataRow - the new row (Object[]) with the values to insert
pDummyColumn - null, if all writeable columns are null, but for a correct INSERT it have to be minimum one column to use in the syntax.
Returns:
the newly inserted row from an Oracle Database.
Throws:
DataSourceException - if an Exception occur during insert to the storage

supportsGetGeneratedKeys

public boolean supportsGetGeneratedKeys()
Returns if this Database specific supports generated keys. Because of Derby bug!

Returns:
if this Database specific supports generated keys.

insertAnsiSQL

protected java.lang.Object[] insertAnsiSQL(java.lang.String pWriteBackTable,
                                           java.lang.String pInsertStatement,
                                           ServerMetaData pServerMetaData,
                                           java.lang.Object[] pNewDataRow,
                                           java.lang.String pDummyColumn)
                                    throws DataSourceException
Returns the newly inserted row from a Ansi SQL Database.
It uses getGeneratedKeys to get the primary key values back from the database. Its recommend that the jdbc driver of the database support that clean.

Parameters:
pWriteBackTable - the table to use for the insert
pInsertStatement - the SQL Statement to use for the insert
pServerMetaData - the meta data to use.
pNewDataRow - the new row (Object[]) with the values to insert
pDummyColumn - true, if all writeable columns are null, but for a correct INSERT it have to be minimum one column to use in the syntax.
Returns:
the newly inserted row from a Ansi SQL Database.
Throws:
DataSourceException - if an Exception occur during insert to the storage

getColumnMetaDataIntern

protected ServerColumnMetaData[] getColumnMetaDataIntern(java.lang.String pFromClause,
                                                         java.lang.String[] pQueryColumns,
                                                         java.lang.String pBeforeQueryColumns,
                                                         java.lang.String pWhereClause,
                                                         java.lang.String pAfterWhereClause)
                                                  throws DataSourceException
Returns the meta data information for the specified query, and configures all columns with defaults.

Parameters:
pBeforeQueryColumns - the before query columns
pQueryColumns - the query columns
pFromClause - the from clause with query tables and join definitions
pWhereClause - the last where condition in query
pAfterWhereClause - the after where clause in query
Returns:
the meta data for the specified query, and initials all columns.
Throws:
DataSourceException - if an Exception occur during getting the meta data or if the storage is not opened or if one columns SQL type is not supported

getRealQueryColumnName

protected java.lang.String getRealQueryColumnName(java.lang.String pQueryColumn)
Gets the real query column name without alias.

Parameters:
pQueryColumn - the full query column name with alias
Returns:
the real query column name without alias.

createServerColumnMetaData

protected ServerColumnMetaData createServerColumnMetaData(java.sql.ResultSetMetaData pResultSetMetaData,
                                                          int pResultSetColumnIndex,
                                                          java.lang.String pQueryColumn)
                                                   throws java.sql.SQLException,
                                                          DataSourceException
Creates the ServerColumnMetaData based on ResultSetMetaData.

Parameters:
pResultSetMetaData - the result set meta data.
pResultSetColumnIndex - the column index.
pQueryColumn - the specific query column of the select statement or null if none
Returns:
the created ServerColumnMetaData
Throws:
java.sql.SQLException - if an unwanted SQLException occurs
DataSourceException - if an know problem occurs during creation

initializeServerColumnMetaData

protected ServerColumnMetaData initializeServerColumnMetaData(java.sql.ResultSetMetaData pResultSetMetaData,
                                                              int pResultSetColumnIndex,
                                                              java.lang.String pQueryColumn,
                                                              ServerColumnMetaData pServerColumnMetaData)
                                                       throws java.sql.SQLException,
                                                              DataSourceException
Fills data into the ServerColumnMetaData based on ResultSetMetaData.

Parameters:
pResultSetMetaData - the result set meta data.
pResultSetColumnIndex - the column index.
pQueryColumn - the specific query column of the select statement or null if none
pServerColumnMetaData - the ServerColumnMetaData
Returns:
the created ServerColumnMetaData
Throws:
java.sql.SQLException - if an unwanted SQLException occurs
DataSourceException - if an know problem occurs during creation

initializeColumnMetaData

public void initializeColumnMetaData(java.sql.ResultSetMetaData pResultSetMetaData,
                                     int pResultSetColumnIndex,
                                     ColumnMetaData pColumnMetaData)
                              throws java.sql.SQLException,
                                     DataSourceException
Initilizes the ColumnMetaData with the given ResultSetMetaData.

Parameters:
pResultSetMetaData - the result set meta data.
pResultSetColumnIndex - the column index.
pColumnMetaData - the ColumnMetaData
Throws:
java.sql.SQLException - if an unwanted SQLException occurs
DataSourceException - if an know problem occurs during creation

initializeDataType

protected void initializeDataType(java.sql.ResultSetMetaData pResultSetMetaData,
                                  int pResultSetColumnIndex,
                                  ColumnMetaData pColumnMetaData)
                           throws java.sql.SQLException,
                                  DataSourceException
Initializes the datatype data of the ColumnMetaData with the given ResultSetMetaData.

Parameters:
pResultSetMetaData - the result set meta data.
pResultSetColumnIndex - the column index.
pColumnMetaData - the ColumnMetaData
Throws:
java.sql.SQLException - if an unwanted SQLException occurs
DataSourceException - if an know problem occurs during creation

getColumnMetaData

public final ServerColumnMetaData[] getColumnMetaData(java.lang.String pFromClause,
                                                      java.lang.String[] pQueryColumns,
                                                      java.lang.String pBeforeQueryColumns,
                                                      java.lang.String pWhereClause,
                                                      java.lang.String pAfterWhereClause)
                                               throws DataSourceException
Returns the meta data information for the specified query, and configures all columns with defaults.

Parameters:
pBeforeQueryColumns - the before query columns
pQueryColumns - the query columns
pFromClause - the from clause with query tables and join definitions
pWhereClause - the last where condition in query
pAfterWhereClause - the after where clause in query
Returns:
the meta data for the specified query, and initials all columns.
Throws:
DataSourceException - if an Exception occur during getting the meta data or if the storage is not opened or if one columns SQL type is not supported

getTableInfoIntern

protected TableInfo getTableInfoIntern(java.lang.String pWriteBackTable)
                                throws DataSourceException
Returns the meta data information for the specified query, and configures all columns with defaults.

Parameters:
pWriteBackTable - the write back table to use for the isWriteable() state (Optional)
Returns:
the meta data for the specified query, and initials all columns.
Throws:
DataSourceException - if an Exception occur during getting the meta data or if the storage is not opened or if one columns SQL type is not supported

getTableInfo

public final TableInfo getTableInfo(java.lang.String pWriteBackTable)
                             throws DataSourceException
Returns the meta data information for the specified query, and configures all columns with defaults.

Parameters:
pWriteBackTable - the write back table to use for the isWriteable() state (Optional)
Returns:
the meta data for the specified query, and initials all columns.
Throws:
DataSourceException - if an Exception occur during getting the meta data or if the storage is not opened or if one columns SQL type is not supported

setColumnsToStore

protected int setColumnsToStore(java.sql.PreparedStatement pInsert,
                                ServerColumnMetaData[] pServerColumnMetaData,
                                int[] iaWriteables,
                                java.lang.Object[] pNew,
                                java.lang.Object[] pOld)
                         throws DataSourceException
Sets the values of all changed columns to store from the value Object[]s into the PreparedStatement and returns the last used parameter index.

Parameters:
pInsert - the PreparedStatement to initialize
pServerColumnMetaData - the column meta data to use.
iaWriteables - the writable columns as int index array
pNew - the new values Object[]
pOld - the old values Object[]
Returns:
the last used parameter index of the PreparedStatement.
Throws:
DataSourceException - if the values can't set into the PreparedStatement

getDefaultValues

public final java.util.Map<java.lang.String,java.lang.Object> getDefaultValues(java.lang.String pCatalog,
                                                                               java.lang.String pSchema,
                                                                               java.lang.String pTable)
                                                                        throws DataSourceException
Gets all default column values of a specific table.

Parameters:
pCatalog - the catalog name
pSchema - the schema name
pTable - the table name
Returns:
a Hashtable with the column name as key and the default value as value. It only contains columns with a default value
Throws:
DataSourceException - if the database access throws an exception

getDefaultValuesIntern

protected java.util.Map<java.lang.String,java.lang.Object> getDefaultValuesIntern(java.lang.String pCatalog,
                                                                                  java.lang.String pSchema,
                                                                                  java.lang.String pTable)
                                                                           throws DataSourceException
Gets all default column values of a specific table.

Parameters:
pCatalog - the catalog name
pSchema - the schema name
pTable - the table name
Returns:
a Hashtable with the column name as key and the default value as value. It only contains columns with a default value
Throws:
DataSourceException - if the database access throws an exception

translateDefaultValue

protected java.lang.Object translateDefaultValue(java.lang.String pColumnName,
                                                 int pDataType,
                                                 java.lang.String pDefaultValue)
                                          throws java.lang.Exception
Translates a default value from a column to the datatype object.

Parameters:
pColumnName - the column name to translate
pDataType - the datatype of the column
pDefaultValue - the original default value from the database
Returns:
the default value with the datatype of the column or null if the default value is not valid
Throws:
java.lang.Exception - if the type translation causes an error or the datatype is not supported

translateValue

protected java.lang.Object translateValue(int pDataType,
                                          java.lang.String pValue)
                                   throws java.lang.Exception
Translates an object value to the datatype object.

Parameters:
pDataType - the datatype of the column
pValue - the value from the database
Returns:
the value with the specified datatype or null if the value is not valid
Throws:
java.lang.Exception - if the type translation causes an error or the datatype is not supported

getAllowedValuesIntern

protected java.util.Map<java.lang.String,java.lang.Object[]> getAllowedValuesIntern(java.lang.String pCatalog,
                                                                                    java.lang.String pSchema,
                                                                                    java.lang.String pTable)
                                                                             throws DataSourceException
Gets the allowed values from a specific table. The allowed values are defined through check constraints or other table related restrictions.

Parameters:
pCatalog - the catalog name
pSchema - the schema name
pTable - the table to check
Returns:
a Hashtable with a column name as key and the allowed values as array of Objects or null if there are no allowed values
Throws:
DataSourceException - if the database access throws an exception

getAllowedValues

public final java.util.Map<java.lang.String,java.lang.Object[]> getAllowedValues(java.lang.String pCatalog,
                                                                                 java.lang.String pSchema,
                                                                                 java.lang.String pTable)
                                                                          throws DataSourceException
Gets the allowed values from a specific table. The allowed values are defined through check constraints or other table related restrictions.

Parameters:
pCatalog - the catalog name
pSchema - the schema name
pTable - the table to check
Returns:
a Hashtable with a column name as key and the allowed values as array of Objects or null if there are no allowed values
Throws:
DataSourceException - if the database access throws an exception

getDefaultAllowedValues

public java.lang.Object[] getDefaultAllowedValues(java.lang.String pCatalog,
                                                  java.lang.String pSchema,
                                                  java.lang.String pTable,
                                                  ServerColumnMetaData pMetaData)
Gets the default allowed values for a given column from a given table. This method will be called if no other default values for the given column are available.

Parameters:
pCatalog - the catalog name
pSchema - the schema name
pTable - the table to check
pMetaData - the column meta data
Returns:
the default allowed values or null if there are no default values

getSQL

protected java.lang.String getSQL(ServerMetaData pServerMetaData,
                                  ICondition pCondition,
                                  boolean pUseRealColumnName)
                           throws DataSourceException
Returns the ANSI SQL String for this ICondition.

Parameters:
pServerMetaData - the MetaDataColumn array to use.
pCondition - the Condition to use.
pUseRealColumnName - true to use the prefixed column (real column name) and false to ignore prefixes (the simple name of the column)
Returns:
the ANSI SQL String for this ICondition.
Throws:
DataSourceException - if columns not existing

createReplace

protected java.lang.String createReplace(java.lang.String pSource,
                                         java.lang.String pOld,
                                         java.lang.String pNew)
Create an DB specific replace command, which replacs in the pSource all pOld to pNew. This implementation use the ANSI SQL REPLACE command.

Parameters:
pSource - the source to replace.
pOld - the old value.
pNew - the new value.
Returns:
the SQL command to to this.

createWhereParam

protected java.lang.String createWhereParam(ServerMetaData pServerMetaData,
                                            CompareCondition pCompare)
Creates the where parameter. That is normally a single question mark, but it depends on the database if conversions are needed.

Parameters:
pServerMetaData - the server metadata
pCompare - the compare condition
Returns:
the parameter representation for where clause

createWhereColumn

protected java.lang.String createWhereColumn(ServerMetaData pServerMetaData,
                                             CompareCondition pCompare,
                                             java.lang.String pColumnName)
Creates the where column. That is normally just the column name, but it depends on the database if conversions are needed.

Parameters:
pServerMetaData - the server metadata
pCompare - the compare condition
pColumnName - the column name to use
Returns:
the column name representation for where clause

isTypeEqual

public boolean isTypeEqual(ServerColumnMetaData pServerColumnMetaData,
                           CompareCondition pCompare)
Check if the Type of the column and the value to compare is equal.

Parameters:
pServerColumnMetaData - the server column meta data for the column to compare.
pCompare - the compare condition to use.
Returns:
false if the type isn't equal.

getParameter

protected java.lang.Object[] getParameter(ICondition pCondition,
                                          int pFromRow,
                                          int pMinimumRowCount)
Returns the parameters used for this ICondition.

Parameters:
pCondition - the Condition to use.
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
Returns:
the parameters used for this ICondition.

getParameter

protected java.lang.Object[] getParameter(ICondition pCondition)
Returns the parameters used for this ICondition.

Parameters:
pCondition - the Condition to use.
Returns:
the parameters used for this ICondition.

splitSchemaTable

protected java.lang.String[] splitSchemaTable(java.lang.String pFromClause)
Separates the schema and table from the given from clause. The separation is only possible if the from clause is simple, e.g. it does not contain any quote characters and does not contain separators (',').

Parameters:
pFromClause - the from clause
Returns:
[0]...schema, [1]...table

setDefaultSchema

public void setDefaultSchema(java.lang.String pSchema)
Sets the user-defined default schema.

Parameters:
pSchema - the schema name
See Also:
getDefaultSchema()

getDefaultSchema

public java.lang.String getDefaultSchema()
Gets the default schema name, if it was set manually.

Returns:
the user-defined default schema name
See Also:
setDefaultSchema(String)

getObjectFromResultSet

protected java.lang.Object getObjectFromResultSet(java.sql.ResultSet pResultSet,
                                                  int pIndex,
                                                  ServerColumnMetaData pColumnMetaData)
                                           throws java.sql.SQLException
Gets the Object from the result set, and ensures that numbers are always returned as BigDecimal, and dates as Timestamp. This is for database independency support.

Parameters:
pResultSet - the result set
pIndex - the index
pColumnMetaData - the server column meta data
Returns:
the object
Throws:
java.sql.SQLException - if it fails.

getObjectFromResultSet

protected java.lang.Object getObjectFromResultSet(java.sql.ResultSet pResultSet,
                                                  int pIndex)
                                           throws java.sql.SQLException
Gets the Object from the result set, and ensures that numbers are always returned as BigDecimal, and dates as Timestamp. This is for database independency support.

Parameters:
pResultSet - the result set
pIndex - the index
Returns:
the object
Throws:
java.sql.SQLException - if it fails.

convertDatabaseSpecificObjectToValue

protected java.lang.Object convertDatabaseSpecificObjectToValue(ServerColumnMetaData pColumnMetaData,
                                                                java.lang.Object pObject)
                                                         throws java.sql.SQLException
Enables the database specific implementation to handle/convert special objects. Some databases have datatypes that are not defined in the standard. This datatypes have specific classes in the JDBC drivers. With this method it is possible to convert the values of specific JDBC driver classes into usable objects. We can not send any JDBC object to the client!

Parameters:
pColumnMetaData - the column metadata
pObject - the read object
Returns:
the value to use
Throws:
java.sql.SQLException - if it fails.

convertValueToDatabaseSpecificObject

protected java.lang.Object convertValueToDatabaseSpecificObject(java.lang.Object pValue)
Converts an object to a standard value for the specific database. Not all values are supported from the underlying database, e.g. java.sql.Timestamp is preferred instead of java.util.Date.

Parameters:
pValue - any value
Returns:
the database specific value

getIdentifier

protected java.lang.String getIdentifier()
Gets the identifier for this DBAccess.

Returns:
the identifier for this DBAccess.

clearMetaData

public static void clearMetaData()
Clears the meta data cache.


clearMetaData

public static void clearMetaData(java.lang.String pApplicationName)
Clears the meta data cache for the given application.

Parameters:
pApplicationName - the application name

createIdentifier

public static java.lang.String createIdentifier(java.lang.Object... pIdentifier)
Creates an identifier string from the given parameter.

Parameters:
pIdentifier - the identifier
Returns:
the identifier string

setMetaDataCacheOption

public void setMetaDataCacheOption(MetaDataCacheOption pOption)
Sets the metadata cache option for this instance. If a session cache option is set, the instance cache option overrules the session setting.

Parameters:
pOption - the metadata cache option
See Also:
isMetaDataCacheEnabled()

getMetaDataCacheOption

public MetaDataCacheOption getMetaDataCacheOption()
Gets the metadata cache option for this instance.

Returns:
the metadata cache option
See Also:
setMetaDataCacheOption(MetaDataCacheOption)

isMetaDataCacheEnabled

protected boolean isMetaDataCacheEnabled()
Gets whether the meta data cache should be used.

Returns:
whether the meta data cache should be used.

prepareConnection

protected void prepareConnection(java.sql.Connection pConnection)
                          throws java.sql.SQLException
Prepares the given Connection for being used by this DBAccess.

Parameters:
pConnection - the Connection to configure.
Throws:
java.sql.SQLException - if the configuring the Connection fails.

setModified

protected void setModified(java.lang.Boolean pModified)
Sets modified state of the connection. The connection should be set modified if insert/update or delete was executed. If the database connection is in auto-commit mode, it's not possible to set the modified flag.

Parameters:
pModified - true to set the connection modified, false to set it not modified

isModified

public boolean isModified()
Gets whether the database access is modified.

Returns:
true if modified, false otherwise

detectModified

protected boolean detectModified()
Detects if a transaction is open directly in the database.

Returns:
true, if a transaction is open directly in the database.

isLogEnabled

protected static boolean isLogEnabled(ILogger.LogLevel pLevel)
Gets whether the given log level is enabled.

Parameters:
pLevel - the level to check
Returns:
true if the log level is enabled, false otherwise

debug

protected static void debug(java.lang.Object... pInfo)
Logs debug information.

Parameters:
pInfo - the debug information

info

protected static void info(java.lang.Object... pInfo)
Logs information.

Parameters:
pInfo - the information

error

protected static void error(java.lang.Object... pInfo)
Logs error information.

Parameters:
pInfo - the error information

isJdbc

public static boolean isJdbc(java.lang.String pUrl)
Gets whether the given URL is a JDBC resource.

Parameters:
pUrl - the URL
Returns:
true if given URL is a jdbc resource

findNamedParameters

protected void findNamedParameters(java.lang.String pStatement,
                                   java.util.List<java.lang.String> pNameList)
Finds all named parameters in the given statement and adds the names to the given List.

Note that this function is subject to be changed in a future version, and can there for not be considered stable.

Parameters:
pStatement - the statement.
pNameList - the List to add the names to.

getColumnName

protected java.lang.String getColumnName(java.sql.ResultSetMetaData pMetaData,
                                         int pColumn)
                                  throws java.sql.SQLException
Gets the column name from the given resultset metadata.

Parameters:
pMetaData - the metadata
pColumn - the column index
Returns:
the column name
Throws:
java.sql.SQLException - if accessing metadata failed

getDiscardRowCount

protected int getDiscardRowCount(int pFromRow,
                                 int pMinimumRowCount)
Gets how many rows should be discarded based on the given values.

Parameters:
pFromRow - the row index from to fetch
pMinimumRowCount - the minimum count row to fetch
Returns:
the amount of rows to discard.

findAndCreateReducedCondition

protected ICondition findAndCreateReducedCondition(ICondition pCondition,
                                                   java.util.Set<java.lang.String> pNames,
                                                   java.util.Map<java.lang.String,CompareCondition> pNameToCondition)
Finds and removes the ICondition with the given column names from the given ICondition. It adds the name and value to the given Map.

Note that this function is subject to be changed in a future version, and can there for not be considered stable.

Parameters:
pCondition - the ICondition in which to search.
pNames - the names of the conditions to search.
pNameToCondition - the Map into which the ICondition is inserted.
Returns:
the changed condition.

getMetaDataWhereClause

protected java.lang.String getMetaDataWhereClause()
Gets the where clause for metadata detection.

Returns:
the where clause


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.