Module org.eclipse.persistence.core
Class DatasourceAccessor
- java.lang.Object
-
- org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor
-
- Direct Known Subclasses:
DatabaseAccessor,EISAccessor,XMLAccessor
public abstract class DatasourceAccessor extends Object implements Accessor
INTERNAL:DatasourceAccessoris an abstract implementation of theAccessorinterface providing common functionality to the concrete database and EIS accessors. It is responsible for connecting, transactions, call execution- Since:
- OracleAS TopLink 10g (10.0.3) 05/28/2008-1.0M8 Andrei Ilitchev. - 224964: Provide support for Proxy Authentication through JPA. Added ConnectionCustomizer, also fixed postConnect/preDisconnect ExternalConnection calls so that they called in case of reads, too.
- Author:
- James
- See Also:
Call,Login
-
-
Field Summary
Fields Modifier and Type Field Description protected intcallCountKeep track of the number of concurrent active calls.protected AbstractSessioncurrentSessionUsed only in externalConnectionPooling case.protected ConnectionCustomizercustomizerAllows session-specific connection customization.protected ObjectdatasourceConnectionStore the reference to the driver level connection.protected booleanisConnectedKeep track of whether the accessor is "connected".protected booleanisInTransactionKeep track if the accessor is within a transaction contextprotected booleanisValidThis attribute is used to determine if the connection should be returned to the pool or removed from the pool and closed.protected LoginloginStore the login information that connected this accessor.protected DatasourcePlatformplatformThis is also required to ensure all accessors for a session are using the same platform.protected ConnectionPoolpoolprotected booleanpossibleFailureThis attribute is used to track failures on an accessor that may be communication based.static StringREAD_STATEMENTS_COUNT_PROPERTYintreadStatementsCountKeep track of the number of the read statement that being executed.protected SequencingCallbacksequencingCallbackDuring (not external) transaction, SequencingManager may set SequencingCallback on the accessor, The callback's only method is called when transaction commits, after transaction is completed the callback is discarded.static booleanshouldCheckConnectionBack-door to allow isConnect checks.static StringSTOREDPROCEDURE_STATEMENTS_COUNT_PROPERTYintstoredProcedureStatementsCountKeep track of the number of the storedprocedure statement that being executed.protected booleanusesExternalConnectionPoolingPERF: Cache connection pooling flag.static StringWRITE_STATEMENTS_COUNT_PROPERTYintwriteStatementsCountKeep track of the number of the write statement that being executed.
-
Constructor Summary
Constructors Modifier Constructor Description protectedDatasourceAccessor()Default Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidbasicBeginTransaction(AbstractSession session)Begin the driver level transaction.protected abstract voidbasicCommitTransaction(AbstractSession session)Commit the driver level transaction.protected abstract ObjectbasicExecuteCall(Call call, AbstractRecord row, AbstractSession session)Execute the call to driver level datasource.protected abstract voidbasicRollbackTransaction(AbstractSession session)Rollback the driver level transaction.voidbeginTransaction(AbstractSession session)Begin a transaction on the database.protected abstract voidbuildConnectLog(AbstractSession session)Build a log string of any driver metadata that can be obtained.Objectclone()Clone the accessor.voidcloseConnection()Close the accessor's connection.protected abstract voidcloseDatasourceConnection()Close the connection to the driver level datasource.voidcloseJTSConnection()Called from beforeCompletion external transaction synchronization listener callback to close the external connection corresponding to the completing external transaction.voidcommitTransaction(AbstractSession session)Commit a transaction on the database.voidconnect(Login login, AbstractSession session)Connect to the datasource.protected voidconnectInternal(Login login, AbstractSession session)Connect to the database.voidcreateCustomizer(AbstractSession session)Attempts to create ConnectionCustomizer.voiddecrementCallCount()Used for load balancing and external pooling.voiddisconnect(AbstractSession session)Disconnect from the datasource.ObjectexecuteCall(Call call, AbstractRecord translationRow, AbstractSession session)Execute the call.voidflushSelectCalls(AbstractSession session)Added as a result of Bug 2804663 - satisfy the Accessor interface implementation.intgetCallCount()Used for load balancing and external pooling.Vector<AbstractRecord>getColumnInfo(String catalog, String schema, String tableName, String columnName, AbstractSession session)Return column information for the specified database objects.Vector<AbstractRecord>getColumnInfo(String tableName, String columnName, AbstractSession session)Return the column metadata for the specified selection criteria limited to the context of the currentAccessor.ConnectiongetConnection()Helper method to return the JDBC connection for DatabaseAccessor.ObjectgetDatasourceConnection()Return the driver level connection.DatasourcePlatformgetDatasourcePlatform()Return the platform.LogingetLogin()Return the loginConnectionPoolgetPool()Return the associated connection pool this connection was obtained from.intgetReadStatementsCount()Return the number of read statements.SequencingCallbackgetSequencingCallback(SequencingCallbackFactory sequencingCallbackFactory)Return sequencing callback.intgetStoredProcedureStatementsCount()Return the number of stored procedure call.Vector<AbstractRecord>getTableInfo(String tableName, String[] types, AbstractSession session)Return the table metadata for the specified selection criteria limited to the context of the currentAccessor.Vector<AbstractRecord>getTableInfo(String catalog, String schema, String tableName, String[] types, AbstractSession session)Return table information for the specified database objects.intgetWriteStatementsCount()Return the number of write statements.voidincrementCallCount(AbstractSession session)Used for load balancing and external pooling.booleanisConnected()Return true if the accessor is currently connected to a data source.protected abstract booleanisDatasourceConnected()Return if the driver level connection is connected.booleanisInTransaction()Return the transaction status of the receiver.booleanisPossibleFailure()booleanisValid()Returns true if this Accessor can continue to be used.protected voidreconnect(AbstractSession session)Attempt to save some of the cost associated with getting a fresh connection.voidreestablishConnection(AbstractSession session)PUBLIC: Reconnect to the database.protected voidreestablishCustomizer()This method is called by reestablishConnection.voidreleaseCustomizer()Clear customizer if it's active and set it to null.voidreleaseCustomizer(AbstractSession session)Clear and remove customizer if its session is the same as the passed one; in case prevCustomizer exists set it as a new customizer.voidreset()Reset statement count.voidrollbackTransaction(AbstractSession session)Rollback the transaction on the datasource.protected voidsetCallCount(int callCount)Used for load balancing and external pooling.protected voidsetCustomizer(ConnectionCustomizer newCustomizer)Set customizer, customize the connection if it's available.protected voidsetDatasourceConnection(Object connection)If client requires to manually set connection they can use the connection manager.voidsetDatasourcePlatform(DatasourcePlatform platform)Set the platform.protected voidsetIsConnected(boolean isConnected)Set whether the accessor has a connection to the "data store".protected voidsetIsInTransaction(boolean value)Set the transaction transaction status of the receiver.voidsetIsValid(boolean isValid)This should be set to false if a communication failure occurred during a call execution.protected voidsetLogin(Login login)SECURE: set the loginvoidsetPool(ConnectionPool pool)Set the associated connection pool this connection was obtained from.voidsetPossibleFailure(boolean possibleFailure)booleanusesExternalConnectionPooling()Return true if some external connection pool is in use.booleanusesExternalTransactionController()Return true if some external transaction service is controlling transactions.voidwritesCompleted(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.
-
-
-
Field Detail
-
datasourceConnection
protected Object datasourceConnection
Store the reference to the driver level connection.
-
login
protected Login login
Store the login information that connected this accessor.
-
callCount
protected int callCount
Keep track of the number of concurrent active calls. This is used for connection pooling for loadbalancing and for external connection pooling.
-
storedProcedureStatementsCount
public int storedProcedureStatementsCount
Keep track of the number of the storedprocedure statement that being executed.
-
readStatementsCount
public int readStatementsCount
Keep track of the number of the read statement that being executed.
-
writeStatementsCount
public int writeStatementsCount
Keep track of the number of the write statement that being executed.
-
READ_STATEMENTS_COUNT_PROPERTY
public static final String READ_STATEMENTS_COUNT_PROPERTY
- See Also:
- Constant Field Values
-
WRITE_STATEMENTS_COUNT_PROPERTY
public static final String WRITE_STATEMENTS_COUNT_PROPERTY
- See Also:
- Constant Field Values
-
STOREDPROCEDURE_STATEMENTS_COUNT_PROPERTY
public static final String STOREDPROCEDURE_STATEMENTS_COUNT_PROPERTY
- See Also:
- Constant Field Values
-
isInTransaction
protected boolean isInTransaction
Keep track if the accessor is within a transaction context
-
isConnected
protected boolean isConnected
Keep track of whether the accessor is "connected".
-
platform
protected DatasourcePlatform platform
This is also required to ensure all accessors for a session are using the same platform.
-
isValid
protected boolean isValid
This attribute is used to determine if the connection should be returned to the pool or removed from the pool and closed. It will be set to false if an exception occurs during Call execution.
-
sequencingCallback
protected transient SequencingCallback sequencingCallback
During (not external) transaction, SequencingManager may set SequencingCallback on the accessor, The callback's only method is called when transaction commits, after transaction is completed the callback is discarded.
-
possibleFailure
protected boolean possibleFailure
This attribute is used to track failures on an accessor that may be communication based. If a failure is detected executing a call with a query timeout this flag is set. If an error happens twice in a row on the same accessor then that accessor will be checked for a comm error. If there is no query timeout then the flag is not set and the accessor will be checked immediately.
-
currentSession
protected transient AbstractSession currentSession
Used only in externalConnectionPooling case. Indicates which session is currently using connection. Allows to rise appropriate session's event when connection is already/still alive. Events will be risen when ClientSession or DatabaseSession acquires connection in the beginning and releases connection in the end of transaction (in afterCompletion in jta case). In case the session requires exclusive connection (ExclusiveIsolatedClientSession) the events will be risen every time the session acquires or releases connection - which is a rare event - the connection is kept for the duration of jta transaction, after jta transaction is completed the new connection is acquired on a first query execution and kept until the next beginTransaction call. In non-jta case the connection is acquired for session's life and release only by session's release. Note that the attribute is nullified only in one place - by closeConnection method.
-
usesExternalConnectionPooling
protected boolean usesExternalConnectionPooling
PERF: Cache connection pooling flag.
-
shouldCheckConnection
public static boolean shouldCheckConnection
Back-door to allow isConnect checks. Since we now support fail-over and retry, removing old isConnected usage which can cause major performance issues (on Sybase), and minor ones in general.
-
customizer
protected ConnectionCustomizer customizer
Allows session-specific connection customization.
-
pool
protected ConnectionPool pool
-
-
Method Detail
-
clone
public Object clone()
Clone the accessor.
-
closeJTSConnection
public void closeJTSConnection()
Called from beforeCompletion external transaction synchronization listener callback to close the external connection corresponding to the completing external transaction. Final sql calls could be sent through the connection by this method before it closes the connection.- Specified by:
closeJTSConnectionin interfaceAccessor
-
setIsInTransaction
protected void setIsInTransaction(boolean value)
Set the transaction transaction status of the receiver.
-
setIsValid
public void setIsValid(boolean isValid)
This should be set to false if a communication failure occurred during a call execution. In the case of an invalid accessor the Accessor will not be returned to the pool.- Specified by:
setIsValidin interfaceAccessor
-
isInTransaction
public boolean isInTransaction()
Return the transaction status of the receiver.- Specified by:
isInTransactionin interfaceAccessor
-
isValid
public boolean isValid()
Returns true if this Accessor can continue to be used. This will be false if a communication failure occurred during a call execution. In the case of an invalid accessor the Accessor will not be returned to the pool.
-
isPossibleFailure
public boolean isPossibleFailure()
-
setPossibleFailure
public void setPossibleFailure(boolean possibleFailure)
-
usesExternalConnectionPooling
public boolean usesExternalConnectionPooling()
Return true if some external connection pool is in use.- Specified by:
usesExternalConnectionPoolingin interfaceAccessor
-
beginTransaction
public void beginTransaction(AbstractSession session) throws DatabaseException
Begin a transaction on the database. If not using managed transaction begin a local transaction.- Specified by:
beginTransactionin interfaceAccessor- Throws:
DatabaseException
-
basicBeginTransaction
protected abstract void basicBeginTransaction(AbstractSession session)
Begin the driver level transaction.
-
basicCommitTransaction
protected abstract void basicCommitTransaction(AbstractSession session)
Commit the driver level transaction.
-
basicRollbackTransaction
protected abstract void basicRollbackTransaction(AbstractSession session)
Rollback the driver level transaction.
-
decrementCallCount
public void decrementCallCount()
Used for load balancing and external pooling.- Specified by:
decrementCallCountin interfaceAccessor
-
incrementCallCount
public void incrementCallCount(AbstractSession session)
Used for load balancing and external pooling.- Specified by:
incrementCallCountin interfaceAccessor
-
connectInternal
protected void connectInternal(Login login, AbstractSession session) throws DatabaseException
Connect to the database. Exceptions are caught and re-thrown as EclipseLink exceptions.- Throws:
DatabaseException
-
setIsConnected
protected void setIsConnected(boolean isConnected)
Set whether the accessor has a connection to the "data store".
-
setCallCount
protected void setCallCount(int callCount)
Used for load balancing and external pooling.
-
getCallCount
public int getCallCount()
Used for load balancing and external pooling.- Specified by:
getCallCountin interfaceAccessor
-
commitTransaction
public void commitTransaction(AbstractSession session) throws DatabaseException
Commit a transaction on the database. If using non-managed transaction commit the local transaction.- Specified by:
commitTransactionin interfaceAccessor- Throws:
DatabaseException
-
connect
public void connect(Login login, AbstractSession session) throws DatabaseException
Connect to the datasource. Through using a CCI ConnectionFactory. Catch exceptions and re-throw as EclipseLink exceptions.- Specified by:
connectin interfaceAccessor- Throws:
DatabaseException
-
closeDatasourceConnection
protected abstract void closeDatasourceConnection()
Close the connection to the driver level datasource.
-
basicExecuteCall
protected abstract Object basicExecuteCall(Call call, AbstractRecord row, AbstractSession session)
Execute the call to driver level datasource.
-
buildConnectLog
protected abstract void buildConnectLog(AbstractSession session)
Build a log string of any driver metadata that can be obtained.
-
getLogin
public Login getLogin()
Return the login
-
setLogin
protected void setLogin(Login login)
SECURE: set the login
-
disconnect
public void disconnect(AbstractSession session) throws DatabaseException
Disconnect from the datasource.- Specified by:
disconnectin interfaceAccessor- Throws:
DatabaseException
-
closeConnection
public void closeConnection()
Close the accessor's connection. This is used only for external connection pooling when it is intended for the connection to be reconnected in the future.- Specified by:
closeConnectionin interfaceAccessor
-
executeCall
public Object executeCall(Call call, AbstractRecord translationRow, AbstractSession session) throws DatabaseException
Execute the call.- Specified by:
executeCallin interfaceAccessor- Returns:
- depending of the type either the row count, row or vector of rows.
- Throws:
DatabaseException
-
reestablishConnection
public void reestablishConnection(AbstractSession session) throws DatabaseException
PUBLIC: Reconnect to the database. This can be used if the connection was disconnected or timedout. This ensures that the security is checked as it is public. Because the messages can take a long time to build, pre-check whether messages should be logged.- Specified by:
reestablishConnectionin interfaceAccessor- Throws:
DatabaseException
-
reconnect
protected void reconnect(AbstractSession session) throws DatabaseException
Attempt to save some of the cost associated with getting a fresh connection. Assume the DatabaseDriver has been cached, if appropriate. Note: Connections that are participating in transactions will not be refreshed.^M- Throws:
DatabaseException
-
getDatasourcePlatform
public DatasourcePlatform getDatasourcePlatform()
Return the platform.
-
setDatasourcePlatform
public void setDatasourcePlatform(DatasourcePlatform platform)
Set the platform. This should be set to the session's platform, not the connections which may not be configured correctly.
-
getDatasourceConnection
public Object getDatasourceConnection()
Return the driver level connection.- Specified by:
getDatasourceConnectionin interfaceAccessor
-
getConnection
public Connection getConnection()
Helper method to return the JDBC connection for DatabaseAccessor. Was going to deprecate this, but since most clients are JDBC this is useful.- Specified by:
getConnectionin interfaceAccessor
-
getColumnInfo
public Vector<AbstractRecord> getColumnInfo(String catalog, String schema, String tableName, String columnName, AbstractSession session) throws DatabaseException
Return column information for the specified database objects.- Specified by:
getColumnInfoin interfaceAccessor- Throws:
DatabaseException
-
getColumnInfo
public Vector<AbstractRecord> getColumnInfo(String tableName, String columnName, AbstractSession session) throws DatabaseException
Description copied from interface:AccessorReturn the column metadata for the specified selection criteria limited to the context of the currentAccessor.- Specified by:
getColumnInfoin interfaceAccessor- Throws:
DatabaseException
-
getReadStatementsCount
public int getReadStatementsCount()
Return the number of read statements.
-
getWriteStatementsCount
public int getWriteStatementsCount()
Return the number of write statements.
-
getStoredProcedureStatementsCount
public int getStoredProcedureStatementsCount()
Return the number of stored procedure call.
-
getTableInfo
public Vector<AbstractRecord> getTableInfo(String catalog, String schema, String tableName, String[] types, AbstractSession session) throws DatabaseException
Return table information for the specified database objects.- Specified by:
getTableInfoin interfaceAccessor- Throws:
DatabaseException
-
getTableInfo
public Vector<AbstractRecord> getTableInfo(String tableName, String[] types, AbstractSession session) throws DatabaseException
Description copied from interface:AccessorReturn the table metadata for the specified selection criteria limited to the context of the currentAccessor.- Specified by:
getTableInfoin interfaceAccessor- Throws:
DatabaseException
-
setDatasourceConnection
protected void setDatasourceConnection(Object connection)
If client requires to manually set connection they can use the connection manager.
-
rollbackTransaction
public void rollbackTransaction(AbstractSession session) throws DatabaseException
Rollback the transaction on the datasource. If not using managed transaction rollback the local transaction.- Specified by:
rollbackTransactionin interfaceAccessor- Throws:
DatabaseException
-
usesExternalTransactionController
public boolean usesExternalTransactionController()
Return true if some external transaction service is controlling transactions.- Specified by:
usesExternalTransactionControllerin interfaceAccessor
-
isConnected
public boolean isConnected()
Return true if the accessor is currently connected to a data source. Return false otherwise.- Specified by:
isConnectedin interfaceAccessor
-
isDatasourceConnected
protected abstract boolean isDatasourceConnected()
Return if the driver level connection is connected.
-
flushSelectCalls
public void flushSelectCalls(AbstractSession session)
Added as a result of Bug 2804663 - satisfy the Accessor interface implementation.- Specified by:
flushSelectCallsin interfaceAccessor- See Also:
LOBValueWriter.buildAndExecuteSelectCalls(AbstractSession)
-
writesCompleted
public 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. It will be called from commitTransaction and may be called from writeChanges. Its main purpose is to ensure that the batched statements have been executed- Specified by:
writesCompletedin interfaceAccessor
-
getSequencingCallback
public SequencingCallback getSequencingCallback(SequencingCallbackFactory sequencingCallbackFactory)
Return sequencing callback.- Specified by:
getSequencingCallbackin interfaceAccessor
-
createCustomizer
public void createCustomizer(AbstractSession session)
Attempts to create ConnectionCustomizer. If created the customizer is cached by the accessor. Called by the owner of accessor (DatabaseSession, ServerSession through ConnectionPool) just once, typically right after the accessor is created. Also called by ClientSession when it acquires write accessor. If accessor already has a customizer set by ConnectionPool then ClientSession's customizer compared with the existing one and if they are not equal (don't produce identical customization) then the new customizer set onto accessor, caching the old customizer so that it could be restored later.- Specified by:
createCustomizerin interfaceAccessor
-
setCustomizer
protected void setCustomizer(ConnectionCustomizer newCustomizer)
Set customizer, customize the connection if it's available.
-
releaseCustomizer
public void releaseCustomizer()
Clear customizer if it's active and set it to null. Called by the same object that has created customizer (DatabaseSession, ConnectionPool) when the latter is no longer required, typically before releasing the accessor. Ignored if there's no customizer.- Specified by:
releaseCustomizerin interfaceAccessor
-
releaseCustomizer
public void releaseCustomizer(AbstractSession session)
Clear and remove customizer if its session is the same as the passed one; in case prevCustomizer exists set it as a new customizer. Called when ClientSession releases write accessor: if the customizer was created by the ClientSession it's removed, and the previous customizer (that ConnectionPool had set) is brought back; otherwise the customizer (created by ConnectionPool) is kept. Ignored if there's no customizer.- Specified by:
releaseCustomizerin interfaceAccessor
-
reestablishCustomizer
protected void reestablishCustomizer()
This method is called by reestablishConnection. Nothing needs to be done in case customize is not active (customization hasn't been applied yet). to repair existing customizer after connection became invalid. However if connection has been customized then if connection is still there and deemed to be valid - clear customization. Otherwise (or if clear fails) remove customizer and set its prevCustomizer as a new customizer, then re-create customizer using the same session as the original one.
-
getPool
public ConnectionPool getPool()
Return the associated connection pool this connection was obtained from.
-
setPool
public void setPool(ConnectionPool pool)
Set the associated connection pool this connection was obtained from.
-
-