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 Statement |
dynamicStatement
PERF: Cache the statement object for dynamic SQL execution.
|
protected boolean |
isDynamicStatementInUse |
protected LOBValueWriter |
lobWriter |
protected 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 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 |
---|---|
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.
|
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(CallableStatement statement,
DatabaseCall call,
AbstractSession session)
Build a row from the output parameters of a sp call.
|
Vector |
buildSortedFields(Vector fields,
ResultSet resultSet,
AbstractSession session)
Return the field sorted in the correct order coresponding to the result set.
|
protected Vector |
buildThreadCursoredResult(DatabaseCall dbCall,
ResultSet resultSet,
Statement statement,
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(ResultSet resultSet)
Close the result set of the cursored stream.
|
void |
closeDatasourceConnection()
Close the connection.
|
void |
closeStatement(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(Vector fields,
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(Vector fields,
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(PreparedStatement statement,
AbstractSession session)
Execute the TopLink dynamicly batch/concat statement.
|
Object |
executeCall(Call call,
AbstractRecord translationRow,
AbstractSession session)
Execute the call.
|
Integer |
executeDirectNoSelect(Statement statement,
DatabaseCall call,
AbstractSession session)
Execute the statement.
|
protected void |
executeJDK12BatchStatement(Statement statement,
DatabaseCall dbCall,
AbstractSession session)
Execute the batched statement through the JDBC2 API.
|
protected Integer |
executeNoSelect(DatabaseCall call,
Statement statement,
AbstractSession session)
Execute the statement.
|
protected ResultSet |
executeSelect(DatabaseCall call,
Statement statement,
AbstractSession session)
Execute the statement.
|
protected AbstractRecord |
fetchRow(Vector fields,
ResultSet resultSet,
ResultSetMetaData metaData,
AbstractSession session)
Return a new DatabaseRow.
|
void |
flushSelectCalls(AbstractSession session)
Execute any deferred select calls stored in the LOBValueWriter instance.
|
Vector |
getColumnInfo(String catalog,
String schema,
String tableName,
String columnName,
AbstractSession session)
Get a description of table columns available in a catalog.
|
protected Vector |
getColumnNames(ResultSet resultSet,
AbstractSession session)
Return the column names from a result sets meta data.
|
Connection |
getConnection()
Return the receiver's connection to its data source.
|
DatabaseMetaData |
getConnectionMetaData()
return the cached metaData
|
LOBValueWriter |
getLOBWriter()
Return the LOBValueWriter instance.
|
protected Object |
getObject(ResultSet resultSet,
DatabaseField field,
ResultSetMetaData metaData,
int columnNumber,
DatabasePlatform platform,
boolean optimizeData,
AbstractSession session)
Return an object retrieved from resultSet with the getObject() method.
|
protected Object |
getObjectThroughOptimizedDataConversion(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 Hashtable |
getStatementCache()
The statement cache stores a fixed sized number of prepared statements.
|
Vector |
getTableInfo(String catalog,
String schema,
String tableName,
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.
|
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(Statement statement,
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(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 Vector |
sortFields(Vector fields,
Vector columnNames)
This method will sort the fields in correct order based
on the column names.
|
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, usesExternalTransactionController
public static boolean shouldUseDynamicStatements
protected Hashtable statementCache
protected DatabaseMetaData metaData
protected LOBValueWriter lobWriter
protected boolean shouldUseThreadCursors
protected Statement dynamicStatement
protected boolean isDynamicStatementInUse
public void flushSelectCalls(AbstractSession session)
flushSelectCalls
in interface Accessor
flushSelectCalls
in class DatasourceAccessor
LOBValueWriter
,
DatasourceCallQueryMechanism.insertObject()
public LOBValueWriter getLOBWriter()
LOBValueWriter
public Statement allocateDynamicStatement() throws SQLException
SQLException
public boolean isDynamicStatementInUse()
public void setIsDynamicStatementInUse(boolean isDynamicStatementInUse)
public void basicBeginTransaction(AbstractSession session) throws DatabaseException
basicBeginTransaction
in class DatasourceAccessor
DatabaseException
protected void buildConnectLog(AbstractSession session)
buildConnectLog
in class DatasourceAccessor
public AbstractRecord buildOutputRow(CallableStatement statement, DatabaseCall call, AbstractSession session) throws DatabaseException
DatabaseException
public Vector buildSortedFields(Vector fields, ResultSet resultSet, AbstractSession session) throws DatabaseException
DatabaseException
protected void connect(Login login) throws DatabaseException
connect
in class DatasourceAccessor
DatabaseException
protected void checkTransactionIsolation() throws DatabaseException
DatabaseException
public void clearStatementCache(AbstractSession session)
public void closeCursor(ResultSet resultSet) throws DatabaseException
DatabaseException
public void closeStatement(Statement statement, AbstractSession session) throws SQLException
SQLException
public void commitTransaction(AbstractSession session) throws DatabaseException
commitTransaction
in interface Accessor
commitTransaction
in class DatasourceAccessor
DatabaseException
public void basicCommitTransaction(AbstractSession session) throws DatabaseException
basicCommitTransaction
in class DatasourceAccessor
DatabaseException
public AbstractRecord cursorRetrieveNextRow(Vector fields, ResultSet resultSet, AbstractSession session) throws DatabaseException
DatabaseException
public AbstractRecord cursorRetrievePreviousRow(Vector fields, ResultSet resultSet, AbstractSession session) throws DatabaseException
DatabaseException
public void closeDatasourceConnection() throws DatabaseException
closeDatasourceConnection
in class DatasourceAccessor
DatabaseException
public void disconnect(AbstractSession session) throws DatabaseException
disconnect
in interface Accessor
disconnect
in class DatasourceAccessor
DatabaseException
public void closeConnection()
closeConnection
in interface Accessor
closeConnection
in class DatasourceAccessor
protected void executeBatchedStatement(PreparedStatement statement, AbstractSession session) throws DatabaseException
DatabaseException
public Object executeCall(Call call, AbstractRecord translationRow, AbstractSession session) throws DatabaseException
executeCall
in interface Accessor
executeCall
in class DatasourceAccessor
DatabaseException
public Object basicExecuteCall(Call call, AbstractRecord translationRow, AbstractSession session) throws DatabaseException
basicExecuteCall
in class DatasourceAccessor
DatabaseException
protected Vector buildThreadCursoredResult(DatabaseCall dbCall, ResultSet resultSet, Statement statement, ResultSetMetaData metaData, AbstractSession session)
public Integer executeDirectNoSelect(Statement statement, DatabaseCall call, AbstractSession session) throws DatabaseException
DatabaseException
protected void executeJDK12BatchStatement(Statement statement, DatabaseCall dbCall, AbstractSession session) throws DatabaseException
DatabaseException
protected Integer executeNoSelect(DatabaseCall call, Statement statement, AbstractSession session) throws DatabaseException
DatabaseException
protected ResultSet executeSelect(DatabaseCall call, Statement statement, AbstractSession session) throws SQLException
SQLException
protected AbstractRecord fetchRow(Vector fields, ResultSet resultSet, 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.
DatabaseException
public Vector getColumnInfo(String catalog, String schema, String tableName, 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 Accessor
getColumnInfo
in class DatasourceAccessor
catalog
- 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 patternDatabaseException
protected Vector getColumnNames(ResultSet resultSet, AbstractSession session) throws SQLException
SQLException
public Connection getConnection() throws DatabaseException
getConnection
in interface Accessor
getConnection
in class DatasourceAccessor
DatabaseException
Connection
public DatabasePlatform getPlatform()
public DatabaseMetaData getConnectionMetaData() throws SQLException
SQLException
protected Object getObject(ResultSet resultSet, DatabaseField field, ResultSetMetaData metaData, int columnNumber, DatabasePlatform platform, boolean optimizeData, AbstractSession session) throws DatabaseException
DatabaseException
protected Object getObjectThroughOptimizedDataConversion(ResultSet resultSet, DatabaseField field, int type, int columnNumber, DatabasePlatform platform, AbstractSession session) throws SQLException
SQLException
protected boolean hasStatementCache()
protected Hashtable getStatementCache()
public Vector getTableInfo(String catalog, String schema, String tableName, 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 Accessor
getTableInfo
in class DatasourceAccessor
catalog
- 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 typesDatabaseException
public boolean isDatasourceConnected()
isDatasourceConnected
in class DatasourceAccessor
public boolean shouldUseThreadCursors()
public void setShouldUseThreadCursors(boolean shouldUseThreadCursors)
public Statement prepareStatement(DatabaseCall call, AbstractSession session) throws SQLException
SQLException
protected void reconnect(AbstractSession session)
reconnect
in class DatasourceAccessor
protected void releaseStatement(Statement statement, String sqlString, DatabaseCall call, AbstractSession session) throws SQLException
SQLException
public void basicRollbackTransaction(AbstractSession session) throws DatabaseException
basicRollbackTransaction
in class DatasourceAccessor
DatabaseException
protected void setStatementCache(Hashtable statementCache)
protected Vector sortFields(Vector fields, Vector columnNames)
public void writesCompleted(AbstractSession session)
writesCompleted
in interface Accessor
writesCompleted
in class DatasourceAccessor
Copyright © 2023. All rights reserved.