Class AbstractTransactionController
- java.lang.Object
-
- org.eclipse.persistence.transaction.AbstractTransactionController
-
- All Implemented Interfaces:
ExternalTransactionController
- Direct Known Subclasses:
JTATransactionController
public abstract class AbstractTransactionController extends java.lang.Object implements ExternalTransactionController
Purpose: Abstract implementation of an ExternalTransactionController.
Description: This class implements the ExternalTransactionController interface. Concrete implementations of this class are responsible for performing the coordination with the external transaction manager through whatever means available to that manager. Different transaction services may do this in slightly different ways, but most common ones (JTA and JTS/OTS) will use a synchronization interface.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ThreadLocalactiveUnitOfWorkThreadLocalPERF: Cache the active uow in a thread local.protected java.util.concurrent.ConcurrentMap<java.lang.Object,AbstractSynchronizationListener>currentlyProcessedListenersNon-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0protected ExceptionHandlerexceptionHandlerAllow exception in before/after completion to be wrapped.protected SynchronizationListenerFactorylistenerFactoryGenerates listener instances for synchronizationprotected intnumSessionsRequiringSequencingCallbackmore - the session is a session broker with several members requiring sequencing callbacks.protected java.util.concurrent.ConcurrentMap<java.lang.Object,AbstractSynchronizationListener>sequencingListenersNon-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0protected org.eclipse.persistence.internal.sessions.AbstractSessionsessionThe session this controller is responsible for controllingprotected java.util.concurrent.ConcurrentMapunitsOfWorkTable of external transaction object keys and unit of work values
-
Constructor Summary
Constructors Constructor Description AbstractTransactionController()INTERNAL: Return a new controller.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddUnitOfWork(java.lang.Object transactionKey, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl activeUnitOfWork)INTERNAL: Add a UnitOfWork object to the Hashtable keyed on the external transaction object.voidbeginTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Begin an external transaction.protected abstract voidbeginTransaction_impl()INTERNAL: Begin an external transaction.voidbindToCurrentTransaction(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Associate the given unit of work and EclipseLink session with the active external transaction.protected abstract booleancanBeginTransaction_impl(java.lang.Object status)INTERNAL: Return true if the status indicates that a transaction can be started.protected abstract booleancanCommitTransaction_impl(java.lang.Object status)INTERNAL: Return true if the status indicates that a transaction can be committed.protected abstract booleancanIssueSQLToDatabase_impl(java.lang.Object status)INTERNAL: Return true if the status indicates that the SQL should be issued to the db.protected abstract booleancanMergeUnitOfWork_impl(java.lang.Object status)INTERNAL: Return true if the status indicates that the unit of work should be merged into the shared cache.protected abstract booleancanRollbackTransaction_impl(java.lang.Object status)INTERNAL: Return true if the status indicates that a transaction can be rolled back.voidclearSequencingListeners()INTERNAL: Clears sequencing listeners.voidcommitTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Commit the external transaction.protected abstract voidcommitTransaction_impl()INTERNAL: Commit the external transaction.org.eclipse.persistence.internal.sequencing.SequencingCallbackgetActiveSequencingCallback(DatabaseSession dbSession, org.eclipse.persistence.internal.sequencing.SequencingCallbackFactory sequencingCallbackFactory)INTERNAL: Returns sequencingCallback for the current active external transaction.org.eclipse.persistence.internal.sessions.UnitOfWorkImplgetActiveUnitOfWork()INTERNAL: Return the active unit of work for the current external transaction.ExceptionHandlergetExceptionHandler()Return the exception handler used to handle or wrap exceptions thrown in before/after completion.SynchronizationListenerFactorygetListenerFactory()INTERNAL: Get the factory used to generate synchronization listeners.org.eclipse.persistence.internal.sessions.AbstractSessiongetSession()INTERNAL: Return the manager's session.java.lang.ObjectgetTransaction()INTERNAL: Return the active external transaction object, or null if none is active.protected abstract java.lang.ObjectgetTransaction_impl()INTERNAL: Return the active external transaction for the calling thread, or null if none is currently active for this thread.java.lang.ObjectgetTransactionKey(java.lang.Object transaction)INTERNAL: Return a key for the specified external transaction object.protected abstract java.lang.ObjectgetTransactionKey_impl(java.lang.Object transaction)INTERNAL: Return a key for the specified external transaction object.java.lang.ObjectgetTransactionStatus()INTERNAL: Return the transaction status.protected abstract java.lang.ObjectgetTransactionStatus_impl()INTERNAL: Return the transaction status.java.util.MapgetUnitsOfWork()INTERNAL: Return the hashtable keyed on the external transaction objects with values that are the associated units of work.booleanhasActiveUnitOfWork()INTERNAL: Return true if there is a unit of work associated with the active external transaction.voidinitializeSequencingListeners()INTERNAL: Initializes sequencing listeners.abstract booleanisRolledBack_impl(java.lang.Object status)INTERNAL: Return true if the transaction is in the rolled back state.booleanisSequencingCallbackRequired()INTERNAL: Indicates whether sequencing callback may be required.java.lang.ObjectjndiLookup(java.lang.String jndiName)PUBLIC: Look up a given name in JNDI.voidlogTxStateTrace(org.eclipse.persistence.internal.sessions.AbstractSession session, java.lang.String msgInd, java.lang.Object status)voidlogTxTrace(org.eclipse.persistence.internal.sessions.AbstractSession session, java.lang.String msgInd, java.lang.Object[] args)org.eclipse.persistence.internal.sessions.UnitOfWorkImpllookupActiveUnitOfWork()INTERNAL: Return the unit of work associated with the active external transaction.org.eclipse.persistence.internal.sessions.UnitOfWorkImpllookupActiveUnitOfWork(java.lang.Object transaction)INTERNAL: Return the unit of work associated with the active external transaction.voidmarkTransactionForRollback()INTERNAL: Mark the external transaction for rollback.protected abstract voidmarkTransactionForRollback_impl()INTERNAL: Mark the external transaction for rollback.booleannoTransactionOrRolledBackOrCommited()INTERNAL: Used the EJB 3.0 to determine if a transaction is in a state where an EntityManager can be closedintnumSessionsRequiringSequencingCallback()INTERNAL: Indicates how many sessions require sequencing callbacks.protected abstract voidregisterSynchronization_impl(AbstractSynchronizationListener listener, java.lang.Object txn)INTERNAL: Register the specified synchronization listener with the given active transaction.voidregisterSynchronizationListener(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Associate the given unit of work and EclipseLink session with the current external transaction.voidremoveSequencingListener(java.lang.Object transactionKey)INTERNAL: Clears sequencingCallbacks.voidremoveUnitOfWork(java.lang.Object transactionKey)INTERNAL: Remove the unit of work associated with the transaction passed in.voidrollbackTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Roll back the external transaction.protected abstract voidrollbackTransaction_impl()INTERNAL: Roll back the external transaction.voidsetExceptionHandler(ExceptionHandler exceptionHandler)Set an exception handler to handle or wrap exceptions thrown in before/after completion.voidsetListenerFactory(SynchronizationListenerFactory factory)INTERNAL: Set the factory used to generate synchronization listeners.voidsetSession(org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Set the manager's session.protected voidsetUnitsOfWork(java.util.concurrent.ConcurrentMap unitsOfWork)INTERNAL: Set the table of transactions to units of work.protected abstract java.lang.StringstatusToString_impl(java.lang.Object status)INTERNAL: Convert the status to a string for tracing.
-
-
-
Field Detail
-
unitsOfWork
protected java.util.concurrent.ConcurrentMap unitsOfWork
Table of external transaction object keys and unit of work values
-
session
protected org.eclipse.persistence.internal.sessions.AbstractSession session
The session this controller is responsible for controlling
-
listenerFactory
protected SynchronizationListenerFactory listenerFactory
Generates listener instances for synchronization
-
activeUnitOfWorkThreadLocal
protected java.lang.ThreadLocal activeUnitOfWorkThreadLocal
PERF: Cache the active uow in a thread local.
-
sequencingListeners
protected java.util.concurrent.ConcurrentMap<java.lang.Object,AbstractSynchronizationListener> sequencingListeners
Non-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0
-
currentlyProcessedListeners
protected java.util.concurrent.ConcurrentMap<java.lang.Object,AbstractSynchronizationListener> currentlyProcessedListeners
Non-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0
-
numSessionsRequiringSequencingCallback
protected int numSessionsRequiringSequencingCallback
more - the session is a session broker with several members requiring sequencing callbacks.
-
exceptionHandler
protected ExceptionHandler exceptionHandler
Allow exception in before/after completion to be wrapped.
-
-
Method Detail
-
getExceptionHandler
public ExceptionHandler getExceptionHandler()
Return the exception handler used to handle or wrap exceptions thrown in before/after completion.- Specified by:
getExceptionHandlerin interfaceExternalTransactionController
-
setExceptionHandler
public void setExceptionHandler(ExceptionHandler exceptionHandler)
Set an exception handler to handle or wrap exceptions thrown in before/after completion.- Specified by:
setExceptionHandlerin interfaceExternalTransactionController
-
bindToCurrentTransaction
public void bindToCurrentTransaction(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl unitOfWork, org.eclipse.persistence.internal.sessions.AbstractSession session)INTERNAL: Associate the given unit of work and EclipseLink session with the active external transaction. This may be done by whatever means supported by the transaction manager (i.e. through a synchronization protocol).- Parameters:
unitOfWork- The unit of work that is to be bound to the active transactionsession- The session ancestor of the unit of work
-
beginTransaction
public void beginTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Begin an external transaction.- Specified by:
beginTransactionin interfaceExternalTransactionController- Parameters:
session- The session for which the transaction is being begun.
-
commitTransaction
public void commitTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Commit the external transaction.- Specified by:
commitTransactionin interfaceExternalTransactionController- Parameters:
session- The session for which the transaction is being committed.
-
rollbackTransaction
public void rollbackTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Roll back the external transaction.- Specified by:
rollbackTransactionin interfaceExternalTransactionController- Parameters:
session- The session for which the transaction is being rolled back.
-
markTransactionForRollback
public void markTransactionForRollback()
INTERNAL: Mark the external transaction for rollback.- Specified by:
markTransactionForRollbackin interfaceExternalTransactionController
-
getTransaction
public java.lang.Object getTransaction()
INTERNAL: Return the active external transaction object, or null if none is active. This may be in whatever form the transaction system uses.
-
getTransactionKey
public java.lang.Object getTransactionKey(java.lang.Object transaction)
INTERNAL: Return a key for the specified external transaction object. The key is just something that can be inserted into a hashtable (must support hashCode() and equals() methods).
-
getTransactionStatus
public java.lang.Object getTransactionStatus()
INTERNAL: Return the transaction status. This may be any type of status or value, depending upon the transaction system.
-
noTransactionOrRolledBackOrCommited
public boolean noTransactionOrRolledBackOrCommited()
INTERNAL: Used the EJB 3.0 to determine if a transaction is in a state where an EntityManager can be closed
-
isRolledBack_impl
public abstract boolean isRolledBack_impl(java.lang.Object status)
INTERNAL: Return true if the transaction is in the rolled back state.
-
hasActiveUnitOfWork
public boolean hasActiveUnitOfWork()
INTERNAL: Return true if there is a unit of work associated with the active external transaction. Return false if no transaction is current, or if no uow has been associated with the active transaction yet.
-
getActiveUnitOfWork
public org.eclipse.persistence.internal.sessions.UnitOfWorkImpl getActiveUnitOfWork()
INTERNAL: Return the active unit of work for the current external transaction. If no transaction is active then return null. If a transaction is active but no unit of work has been bound to it then create and return one.- Specified by:
getActiveUnitOfWorkin interfaceExternalTransactionController
-
lookupActiveUnitOfWork
public org.eclipse.persistence.internal.sessions.UnitOfWorkImpl lookupActiveUnitOfWork()
INTERNAL: Return the unit of work associated with the active external transaction. Return null if no transaction is active, or if no uow has been associated with the active transaction yet.
-
lookupActiveUnitOfWork
public org.eclipse.persistence.internal.sessions.UnitOfWorkImpl lookupActiveUnitOfWork(java.lang.Object transaction)
INTERNAL: Return the unit of work associated with the active external transaction. Return null if no transaction is active, or if no uow has been associated with the active transaction yet.
-
addUnitOfWork
public void addUnitOfWork(java.lang.Object transactionKey, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl activeUnitOfWork)INTERNAL: Add a UnitOfWork object to the Hashtable keyed on the external transaction object.
-
removeUnitOfWork
public void removeUnitOfWork(java.lang.Object transactionKey)
INTERNAL: Remove the unit of work associated with the transaction passed in.
-
getSession
public org.eclipse.persistence.internal.sessions.AbstractSession getSession()
INTERNAL: Return the manager's session.- Specified by:
getSessionin interfaceExternalTransactionController
-
setSession
public void setSession(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Set the manager's session.- Specified by:
setSessionin interfaceExternalTransactionController
-
getUnitsOfWork
public java.util.Map getUnitsOfWork()
INTERNAL: Return the hashtable keyed on the external transaction objects with values that are the associated units of work.
-
setUnitsOfWork
protected void setUnitsOfWork(java.util.concurrent.ConcurrentMap unitsOfWork)
INTERNAL: Set the table of transactions to units of work.
-
getListenerFactory
public SynchronizationListenerFactory getListenerFactory()
INTERNAL: Get the factory used to generate synchronization listeners.
-
setListenerFactory
public void setListenerFactory(SynchronizationListenerFactory factory)
INTERNAL: Set the factory used to generate synchronization listeners. This should be set if a listener other than the default one is being used.
-
registerSynchronizationListener
public void registerSynchronizationListener(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, org.eclipse.persistence.internal.sessions.AbstractSession session) throws DatabaseExceptionINTERNAL: Associate the given unit of work and EclipseLink session with the current external transaction. This method is offered only for backwards compatibility.- Specified by:
registerSynchronizationListenerin interfaceExternalTransactionController- Throws:
DatabaseException
-
jndiLookup
public java.lang.Object jndiLookup(java.lang.String jndiName)
PUBLIC: Look up a given name in JNDI. This can be used by a subclass or even an application to look up transaction artifacts that are required for the implementation.The lookup assumes that it is taking place on the server side, and that the InitialContext can be used without requiring any special properties.
- Parameters:
jndiName- The name to look up- Returns:
- The object bound in JNDI to the specified name
- Throws:
TransactionException- Thrown in case of lookup failure
-
initializeSequencingListeners
public void initializeSequencingListeners()
INTERNAL: Initializes sequencing listeners. There are two methods calling this method: 1. setSession method - this could lead to initialization of sequencing listeners only if sequencing already connected (that would happen if setSession is called after session.login, which is normally not the case). 2. in the very end of connecting sequencing or adding descriptors to sequencing, after it's determined whether sequencing callbacks (and therefore listeners) will be required. In SessionBroker case each member's sequencing may call this method. Note that the number of sessions requiring callbacks may never decrease, therefore if isSequencingCallbackRequired method has returned true once, it will always return true after that (unless clearSequencingListeners method is called).- Specified by:
initializeSequencingListenersin interfaceExternalTransactionController
-
getActiveSequencingCallback
public org.eclipse.persistence.internal.sequencing.SequencingCallback getActiveSequencingCallback(DatabaseSession dbSession, org.eclipse.persistence.internal.sequencing.SequencingCallbackFactory sequencingCallbackFactory)
INTERNAL: Returns sequencingCallback for the current active external transaction. DatabaseSession is passed for the sake of SessionBroker case. This method requires active external transaction.- Specified by:
getActiveSequencingCallbackin interfaceExternalTransactionController
-
clearSequencingListeners
public void clearSequencingListeners()
INTERNAL: Clears sequencing listeners. Called by initializeSequencingListeners and by sequencing on disconnect.- Specified by:
clearSequencingListenersin interfaceExternalTransactionController
-
isSequencingCallbackRequired
public boolean isSequencingCallbackRequired()
INTERNAL: Indicates whether sequencing callback may be required.
-
numSessionsRequiringSequencingCallback
public int numSessionsRequiringSequencingCallback()
INTERNAL: Indicates how many sessions require sequencing callbacks.
-
removeSequencingListener
public void removeSequencingListener(java.lang.Object transactionKey)
INTERNAL: Clears sequencingCallbacks. Called by initializeSequencingCallbacks and by sequencing on disconnect.
-
logTxTrace
public void logTxTrace(org.eclipse.persistence.internal.sessions.AbstractSession session, java.lang.String msgInd, java.lang.Object[] args)
-
logTxStateTrace
public void logTxStateTrace(org.eclipse.persistence.internal.sessions.AbstractSession session, java.lang.String msgInd, java.lang.Object status)
-
registerSynchronization_impl
protected abstract void registerSynchronization_impl(AbstractSynchronizationListener listener, java.lang.Object txn) throws java.lang.Exception
INTERNAL: Register the specified synchronization listener with the given active transaction.- Parameters:
listener- The synchronization listener created for this transactiontxn- The active transaction for which notification is being requested- Throws:
java.lang.Exception
-
getTransaction_impl
protected abstract java.lang.Object getTransaction_impl() throws java.lang.ExceptionINTERNAL: Return the active external transaction for the calling thread, or null if none is currently active for this thread.- Returns:
- The active transaction object, or null if no transaction is active
- Throws:
java.lang.Exception
-
getTransactionKey_impl
protected abstract java.lang.Object getTransactionKey_impl(java.lang.Object transaction) throws java.lang.ExceptionINTERNAL: Return a key for the specified external transaction object. The key is just something that can be inserted into a hashtable (must support hashCode() and equals() methods).- Parameters:
transaction- The transaction to which the returned key applies (may be null)- Returns:
- A key for the passed in transaction, or null if no transaction specified
- Throws:
java.lang.Exception
-
getTransactionStatus_impl
protected abstract java.lang.Object getTransactionStatus_impl() throws java.lang.ExceptionINTERNAL: Return the transaction status. This may be any type of status or value, depending upon the transaction system.- Returns:
- The current transaction status
- Throws:
java.lang.Exception
-
beginTransaction_impl
protected abstract void beginTransaction_impl() throws java.lang.ExceptionINTERNAL: Begin an external transaction. Do this in a way appropriate to the transaction subsystem.- Throws:
java.lang.Exception
-
commitTransaction_impl
protected abstract void commitTransaction_impl() throws java.lang.ExceptionINTERNAL: Commit the external transaction. Do this in a way appropriate to the transaction subsystem.- Throws:
java.lang.Exception
-
rollbackTransaction_impl
protected abstract void rollbackTransaction_impl() throws java.lang.ExceptionINTERNAL: Roll back the external transaction. Do this in a way appropriate to the transaction subsystem.- Throws:
java.lang.Exception
-
markTransactionForRollback_impl
protected abstract void markTransactionForRollback_impl() throws java.lang.ExceptionINTERNAL: Mark the external transaction for rollback. Do this in a way appropriate to the transaction subsystem.- Throws:
java.lang.Exception
-
canBeginTransaction_impl
protected abstract boolean canBeginTransaction_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that a transaction can be started. This would normally mean that no transaction is currently active. The status is interpreted by the transaction subsystem.- Parameters:
status- The current transaction status- Returns:
- true if the current state allows for a transaction to be started
-
canCommitTransaction_impl
protected abstract boolean canCommitTransaction_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that a transaction can be committed. This would normally mean that a transaction is currently active. The status is interpreted by the transaction subsystem.- Parameters:
status- The current transaction status- Returns:
- true if the current state allows for a transaction to be committed
-
canRollbackTransaction_impl
protected abstract boolean canRollbackTransaction_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that a transaction can be rolled back. This would normally mean that a transaction is currently active. The status is interpreted by the transaction subsystem.- Parameters:
status- The current transaction status- Returns:
- true if the current state allows for a transaction to be rolled back
-
canIssueSQLToDatabase_impl
protected abstract boolean canIssueSQLToDatabase_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that the SQL should be issued to the db. This would normally mean that a transaction was active and not being rolled back or marked for rollback. The status is interpreted by the transaction subsystem.- Parameters:
status- The current transaction status- Returns:
- true if the current state allows for the SQL to be sent to the database
-
canMergeUnitOfWork_impl
protected abstract boolean canMergeUnitOfWork_impl(java.lang.Object status)
INTERNAL: Return true if the status indicates that the unit of work should be merged into the shared cache. This would normally mean that the transaction was committed successfully. The status is interpreted by the transaction subsystem.- Parameters:
status- The current transaction status- Returns:
- true if the current state dictates that the unit of work should be merged
-
statusToString_impl
protected abstract java.lang.String statusToString_impl(java.lang.Object status)
INTERNAL: Convert the status to a string for tracing.
-
-