public class DatabaseAccessor extends DatasourceAccessor
DatabaseAccessor also defines a single reference through which all configuration dependent behaviour may be invoked.
DabaseAccessor implements the following behavior.
DatabasePlatform| Modifier and Type | Field and Description |
|---|---|
protected java.sql.Statement |
dynamicStatement
PERF: Cache the statement object for dynamic SQL execution.
|
protected boolean |
isDynamicStatementInUse |
protected LOBValueWriter |
lobWriter |
protected java.sql.DatabaseMetaData |
metaData
Cache of the connection's java.sql.DatabaseMetaData
|
static boolean |
shouldUseDynamicStatements
PERF: Backdoor to disabling dynamic statements.
|
protected boolean |
shouldUseThreadCursors
PERF: Option to allow concurrent thread processing of result sets.
|
protected java.util.Hashtable |
statementCache
Stores statement handles for common used prepared statements.
|
callCount, datasourceConnection, isConnected, isInTransaction, login, platform| Constructor and Description |
|---|
DatabaseAccessor() |
| Modifier and Type | Method and Description |
|---|---|
java.sql.Statement |
allocateDynamicStatement()
Allocate a statement for dynamic SQL execution.
|
void |
basicBeginTransaction(AbstractSession session)
Begin a transaction on the database.
|
void |
basicCommitTransaction(AbstractSession session)
Commit a transaction on the database.
|
java.lang.Object |
basicExecuteCall(Call call,
AbstractRecord translationRow,
AbstractSession session)
Execute the call.
|
void |
basicRollbackTransaction(AbstractSession session)
Rollback a transaction on the database.
|
protected void |
buildConnectLog(AbstractSession session)
If logging is turned on and the JDBC implementation supports meta data then display connection info.
|
AbstractRecord |
buildOutputRow(java.sql.CallableStatement statement,
DatabaseCall call,
AbstractSession session)
Build a row from the output parameters of a sp call.
|
java.util.Vector |
buildSortedFields(java.util.Vector fields,
java.sql.ResultSet resultSet,
AbstractSession session)
Return the field sorted in the correct order coresponding to the result set.
|
protected java.util.Vector |
buildThreadCursoredResult(DatabaseCall dbCall,
java.sql.ResultSet resultSet,
java.sql.Statement statement,
java.sql.ResultSetMetaData metaData,
AbstractSession session) |
protected void |
checkTransactionIsolation()
Check to see if the transaction isolation needs to
be set for the newly created connection.
|
void |
clearStatementCache(AbstractSession session)
Flush the statement cache.
|
void |
closeConnection()
Close the accessor's connection.
|
void |
closeCursor(java.sql.ResultSet resultSet)
Close the result set of the cursored stream.
|
void |
closeDatasourceConnection()
Close the connection.
|
void |
closeStatement(java.sql.Statement statement,
AbstractSession session)
INTERNAL:
Closes a PreparedStatment (which is supposed to close it's current resultSet).
|
void |
commitTransaction(AbstractSession session)
Commit a transaction on the database.
|
protected void |
connect(Login login)
Connect to the database.
|
AbstractRecord |
cursorRetrieveNextRow(java.util.Vector fields,
java.sql.ResultSet resultSet,
AbstractSession session)
Advance the result set and return a DatabaseRow populated
with values from the next valid row in the result set.
|
AbstractRecord |
cursorRetrievePreviousRow(java.util.Vector fields,
java.sql.ResultSet resultSet,
AbstractSession session)
Advance the result set and return a DatabaseRow populated
with values from the next valid row in the result set.
|
void |
disconnect(AbstractSession session)
Disconnect from the datasource.
|
protected void |
executeBatchedStatement(java.sql.PreparedStatement statement,
AbstractSession session)
Execute the TopLink dynamicly batch/concat statement.
|
java.lang.Object |
executeCall(Call call,
AbstractRecord translationRow,
AbstractSession session)
Execute the call.
|
java.lang.Integer |
executeDirectNoSelect(java.sql.Statement statement,
DatabaseCall call,
AbstractSession session)
Execute the statement.
|
protected void |
executeJDK12BatchStatement(java.sql.Statement statement,
DatabaseCall dbCall,
AbstractSession session)
Execute the batched statement through the JDBC2 API.
|
protected java.lang.Integer |
executeNoSelect(DatabaseCall call,
java.sql.Statement statement,
AbstractSession session)
Execute the statement.
|
protected java.sql.ResultSet |
executeSelect(DatabaseCall call,
java.sql.Statement statement,
AbstractSession session)
Execute the statement.
|
protected AbstractRecord |
fetchRow(java.util.Vector fields,
java.sql.ResultSet resultSet,
java.sql.ResultSetMetaData metaData,
AbstractSession session)
Return a new DatabaseRow.
|
void |
flushSelectCalls(AbstractSession session)
Execute any deferred select calls stored in the LOBValueWriter instance.
|
java.util.Vector |
getColumnInfo(java.lang.String catalog,
java.lang.String schema,
java.lang.String tableName,
java.lang.String columnName,
AbstractSession session)
Get a description of table columns available in a catalog.
|
protected java.util.Vector |
getColumnNames(java.sql.ResultSet resultSet,
AbstractSession session)
Return the column names from a result sets meta data.
|
java.sql.Connection |
getConnection()
Return the receiver's connection to its data source.
|
java.sql.DatabaseMetaData |
getConnectionMetaData()
return the cached metaData
|
LOBValueWriter |
getLOBWriter()
Return the LOBValueWriter instance.
|
protected java.lang.Object |
getObject(java.sql.ResultSet resultSet,
DatabaseField field,
java.sql.ResultSetMetaData metaData,
int columnNumber,
DatabasePlatform platform,
boolean optimizeData,
AbstractSession session)
Return an object retrieved from resultSet with the getObject() method.
|
protected java.lang.Object |
getObjectThroughOptimizedDataConversion(java.sql.ResultSet resultSet,
DatabaseField field,
int type,
int columnNumber,
DatabasePlatform platform,
AbstractSession session)
Handle the conversion into java optimially through calling the direct type API.
|
DatabasePlatform |
getPlatform()
Return the platform.
|
protected java.util.Hashtable |
getStatementCache()
The statement cache stores a fixed sized number of prepared statements.
|
java.util.Vector |
getTableInfo(java.lang.String catalog,
java.lang.String schema,
java.lang.String tableName,
java.lang.String[] types,
AbstractSession session)
Get a description of tables available in a catalog.
|
protected boolean |
hasStatementCache()
Return if the accessor has any cached statements.
|
boolean |
isDatasourceConnected()
Return true if the receiver is currently connected to a data source.
|
boolean |
isDynamicStatementInUse()
Return the cached statement for dynamic SQL execution is in use.
|
java.sql.Statement |
prepareStatement(DatabaseCall call,
AbstractSession session)
Prepare the SQL statement for the call.
|
protected void |
reconnect(AbstractSession session)
Attempt to save some of the cost associated with getting a fresh connection.
|
protected void |
releaseStatement(java.sql.Statement statement,
java.lang.String sqlString,
DatabaseCall call,
AbstractSession session)
Release the statement through closing it or putting it back in the statement cache.
|
void |
setIsDynamicStatementInUse(boolean isDynamicStatementInUse)
Set if the cached statement for dynamic SQL execution is in use.
|
void |
setShouldUseThreadCursors(boolean shouldUseThreadCursors)
Set if thread cursors should be used for fetch the result row.
|
protected void |
setStatementCache(java.util.Hashtable statementCache)
The statement cache stores a fixed sized number of prepared statements.
|
boolean |
shouldUseThreadCursors()
Return if thread cursors should be used for fetch the result row.
|
protected java.util.Vector |
sortFields(java.util.Vector fields,
java.util.Vector columnNames)
This method will sort the fields in correct order based
on the column names.
|
java.lang.String |
toString() |
void |
writesCompleted(AbstractSession session)
This method will be called after a series of writes have been issued to
mark where a particular set of writes has completed.
|
afterJTSTransaction, beginTransaction, clone, connect, decrementCallCount, getCallCount, getDatasourceConnection, getDatasourcePlatform, getLogin, incrementCallCount, isConnected, isInTransaction, reestablishConnection, rollbackTransaction, setCallCount, setDatasourceConnection, setDatasourcePlatform, setIsConnected, setIsInTransaction, setLogin, usesExternalConnectionPooling, usesExternalTransactionControllerpublic static boolean shouldUseDynamicStatements
protected java.util.Hashtable statementCache
protected java.sql.DatabaseMetaData metaData
protected LOBValueWriter lobWriter
protected boolean shouldUseThreadCursors
protected java.sql.Statement dynamicStatement
protected boolean isDynamicStatementInUse
public void flushSelectCalls(AbstractSession session)
flushSelectCalls in interface AccessorflushSelectCalls in class DatasourceAccessorLOBValueWriter,
DatasourceCallQueryMechanism.insertObject()public LOBValueWriter getLOBWriter()
LOBValueWriterpublic java.sql.Statement allocateDynamicStatement()
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean isDynamicStatementInUse()
public void setIsDynamicStatementInUse(boolean isDynamicStatementInUse)
public void basicBeginTransaction(AbstractSession session) throws DatabaseException
basicBeginTransaction in class DatasourceAccessorDatabaseExceptionprotected void buildConnectLog(AbstractSession session)
buildConnectLog in class DatasourceAccessorpublic AbstractRecord buildOutputRow(java.sql.CallableStatement statement, DatabaseCall call, AbstractSession session) throws DatabaseException
DatabaseExceptionpublic java.util.Vector buildSortedFields(java.util.Vector fields,
java.sql.ResultSet resultSet,
AbstractSession session)
throws DatabaseException
DatabaseExceptionprotected void connect(Login login) throws DatabaseException
connect in class DatasourceAccessorDatabaseExceptionprotected void checkTransactionIsolation()
throws DatabaseException
DatabaseExceptionpublic void clearStatementCache(AbstractSession session)
public void closeCursor(java.sql.ResultSet resultSet)
throws DatabaseException
DatabaseExceptionpublic void closeStatement(java.sql.Statement statement,
AbstractSession session)
throws java.sql.SQLException
java.sql.SQLExceptionpublic void commitTransaction(AbstractSession session) throws DatabaseException
commitTransaction in interface AccessorcommitTransaction in class DatasourceAccessorDatabaseExceptionpublic void basicCommitTransaction(AbstractSession session) throws DatabaseException
basicCommitTransaction in class DatasourceAccessorDatabaseExceptionpublic AbstractRecord cursorRetrieveNextRow(java.util.Vector fields, java.sql.ResultSet resultSet, AbstractSession session) throws DatabaseException
DatabaseExceptionpublic AbstractRecord cursorRetrievePreviousRow(java.util.Vector fields, java.sql.ResultSet resultSet, AbstractSession session) throws DatabaseException
DatabaseExceptionpublic void closeDatasourceConnection()
throws DatabaseException
closeDatasourceConnection in class DatasourceAccessorDatabaseExceptionpublic void disconnect(AbstractSession session) throws DatabaseException
disconnect in interface Accessordisconnect in class DatasourceAccessorDatabaseExceptionpublic void closeConnection()
closeConnection in interface AccessorcloseConnection in class DatasourceAccessorprotected void executeBatchedStatement(java.sql.PreparedStatement statement,
AbstractSession session)
throws DatabaseException
DatabaseExceptionpublic java.lang.Object executeCall(Call call, AbstractRecord translationRow, AbstractSession session) throws DatabaseException
executeCall in interface AccessorexecuteCall in class DatasourceAccessorDatabaseExceptionpublic java.lang.Object basicExecuteCall(Call call, AbstractRecord translationRow, AbstractSession session) throws DatabaseException
basicExecuteCall in class DatasourceAccessorDatabaseExceptionprotected java.util.Vector buildThreadCursoredResult(DatabaseCall dbCall, java.sql.ResultSet resultSet, java.sql.Statement statement, java.sql.ResultSetMetaData metaData, AbstractSession session)
public java.lang.Integer executeDirectNoSelect(java.sql.Statement statement,
DatabaseCall call,
AbstractSession session)
throws DatabaseException
DatabaseExceptionprotected void executeJDK12BatchStatement(java.sql.Statement statement,
DatabaseCall dbCall,
AbstractSession session)
throws DatabaseException
DatabaseExceptionprotected java.lang.Integer executeNoSelect(DatabaseCall call, java.sql.Statement statement, AbstractSession session) throws DatabaseException
DatabaseExceptionprotected java.sql.ResultSet executeSelect(DatabaseCall call, java.sql.Statement statement, AbstractSession session) throws java.sql.SQLException
java.sql.SQLExceptionprotected AbstractRecord fetchRow(java.util.Vector fields, java.sql.ResultSet resultSet, java.sql.ResultSetMetaData metaData, AbstractSession session) throws DatabaseException
Populate the row from the data in cursor. The fields representing the results and the order of the results are stored in fields.
NOTE: Make sure that the field name is set. An empty field name placeholder is used in the sortFields() method when the number of fields defined does not match the number of column names available on the database.
DatabaseExceptionpublic java.util.Vector getColumnInfo(java.lang.String catalog,
java.lang.String schema,
java.lang.String tableName,
java.lang.String columnName,
AbstractSession session)
throws DatabaseException
Only column descriptions matching the catalog, schema, table and column name criteria are returned. They are ordered by TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
Each column description has the following columns:
getColumnInfo in interface AccessorgetColumnInfo in class DatasourceAccessorcatalog - a catalog name; "" retrieves those without a
catalog; null means drop catalog name from the selection criteriaschemaPattern - a schema name pattern; "" retrieves those
without a schematableNamePattern - a table name patterncolumnNamePattern - a column name patternDatabaseExceptionprotected java.util.Vector getColumnNames(java.sql.ResultSet resultSet,
AbstractSession session)
throws java.sql.SQLException
java.sql.SQLExceptionpublic java.sql.Connection getConnection()
throws DatabaseException
getConnection in interface AccessorgetConnection in class DatasourceAccessorDatabaseExceptionConnectionpublic DatabasePlatform getPlatform()
public java.sql.DatabaseMetaData getConnectionMetaData()
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.lang.Object getObject(java.sql.ResultSet resultSet,
DatabaseField field,
java.sql.ResultSetMetaData metaData,
int columnNumber,
DatabasePlatform platform,
boolean optimizeData,
AbstractSession session)
throws DatabaseException
DatabaseExceptionprotected java.lang.Object getObjectThroughOptimizedDataConversion(java.sql.ResultSet resultSet,
DatabaseField field,
int type,
int columnNumber,
DatabasePlatform platform,
AbstractSession session)
throws java.sql.SQLException
java.sql.SQLExceptionprotected boolean hasStatementCache()
protected java.util.Hashtable getStatementCache()
public java.util.Vector getTableInfo(java.lang.String catalog,
java.lang.String schema,
java.lang.String tableName,
java.lang.String[] types,
AbstractSession session)
throws DatabaseException
Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
Each table description has the following columns:
Note: Some databases may not return information for all tables.
getTableInfo in interface AccessorgetTableInfo in class DatasourceAccessorcatalog - a catalog name; "" retrieves those without a
catalog; null means drop catalog name from the selection criteriaschemaPattern - a schema name pattern; "" retrieves those
without a schematableNamePattern - a table name patterntypes - a list of table types to include; null returns all typesDatabaseExceptionpublic boolean isDatasourceConnected()
isDatasourceConnected in class DatasourceAccessorpublic boolean shouldUseThreadCursors()
public void setShouldUseThreadCursors(boolean shouldUseThreadCursors)
public java.sql.Statement prepareStatement(DatabaseCall call, AbstractSession session) throws java.sql.SQLException
java.sql.SQLExceptionprotected void reconnect(AbstractSession session)
reconnect in class DatasourceAccessorprotected void releaseStatement(java.sql.Statement statement,
java.lang.String sqlString,
DatabaseCall call,
AbstractSession session)
throws java.sql.SQLException
java.sql.SQLExceptionpublic void basicRollbackTransaction(AbstractSession session) throws DatabaseException
basicRollbackTransaction in class DatasourceAccessorDatabaseExceptionprotected void setStatementCache(java.util.Hashtable statementCache)
protected java.util.Vector sortFields(java.util.Vector fields,
java.util.Vector columnNames)
public java.lang.String toString()
toString in class java.lang.Objectpublic void writesCompleted(AbstractSession session)
writesCompleted in interface AccessorwritesCompleted in class DatasourceAccessor