Top Description Fields Constructors Methods
org.eclipse.persistence.transaction

public abstract Class AbstractTransactionController

extends Object
implements ExternalTransactionController
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.sessions.ExternalTransactionController
Known Direct Subclasses
org.eclipse.persistence.transaction.JTATransactionController
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, javax.naming.Context, .InitialContext, .NamingException, org.eclipse.persistence.exceptions.DatabaseException, .ExceptionHandler, .TransactionException, org.eclipse.persistence.internal.sequencing.SequencingCallback, .SequencingCallbackFactory, org.eclipse.persistence.internal.sessions.AbstractSession, .DatabaseSessionImpl, .UnitOfWorkImpl, org.eclipse.persistence.logging.SessionLog, org.eclipse.persistence.sessions.DatabaseSession, .ExternalTransactionController, org.eclipse.persistence.sessions.broker.SessionBroker

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.

See Also
AbstractSynchronizationListener, org.eclipse.persistence.sessions.ExternalTransactionController

Field Summary

Modifier and TypeField and Description
protected ThreadLocal<UnitOfWorkImpl>
activeUnitOfWorkThreadLocal

PERF: Cache the active uow in a thread local.

protected ConcurrentMap<Object, AbstractSynchronizationListener>
currentlyProcessedListeners

Non-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0

protected ExceptionHandler
exceptionHandler

Allow exception in before/after completion to be wrapped.

protected SynchronizationListenerFactory
listenerFactory

Generates listener instances for synchronization

protected int
numSessionsRequiringSequencingCallback

more - the session is a session broker with several members requiring sequencing callbacks.

protected ConcurrentMap<Object, AbstractSynchronizationListener>
sequencingListeners

Non-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0

protected AbstractSession
session

The session this controller is responsible for controlling

protected ConcurrentMap<Object, UnitOfWorkImpl>
unitsOfWork

Table of external transaction object keys and unit of work values

Constructor Summary

AccessConstructor and Description
protected
AbstractTransactionController()

INTERNAL: Return a new controller.

Method Summary

Modifier and TypeMethod and Description
public void
addUnitOfWork(Object transactionKey, UnitOfWorkImpl activeUnitOfWork)

INTERNAL: Add a UnitOfWork object to the Hashtable keyed on the external transaction object.

public void
beginTransaction(AbstractSession
The session for which the transaction is being begun.
session
)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.beginTransaction.

INTERNAL: Begin an external transaction.
protected abstract void
beginTransaction_impl()

INTERNAL: Begin an external transaction.

public void
bindToCurrentTransaction(UnitOfWorkImpl
The unit of work that is to be bound to the active transaction
unitOfWork
,
AbstractSession
The session ancestor of the unit of work
session
)

INTERNAL: Associate the given unit of work and EclipseLink session with the active external transaction.

protected abstract boolean

Returns:

true if the current state allows for a transaction to be started
canBeginTransaction_impl
(Object
The current transaction status
status
)

INTERNAL: Return true if the status indicates that a transaction can be started.

protected abstract boolean

Returns:

true if the current state allows for a transaction to be committed
canCommitTransaction_impl
(Object
The current transaction status
status
)

INTERNAL: Return true if the status indicates that a transaction can be committed.

protected abstract boolean

Returns:

true if the current state allows for the SQL to be sent to the database
canIssueSQLToDatabase_impl
(Object
The current transaction status
status
)

INTERNAL: Return true if the status indicates that the SQL should be issued to the db.

protected abstract boolean

Returns:

true if the current state dictates that the unit of work should be merged
canMergeUnitOfWork_impl
(Object
The current transaction status
status
)

INTERNAL: Return true if the status indicates that the unit of work should be merged into the shared cache.

protected abstract boolean

Returns:

true if the current state allows for a transaction to be rolled back
canRollbackTransaction_impl
(Object
The current transaction status
status
)

INTERNAL: Return true if the status indicates that a transaction can be rolled back.

public void
public void
commitTransaction(AbstractSession
The session for which the transaction is being committed.
session
)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.commitTransaction.

INTERNAL: Commit the external transaction.
protected abstract void
commitTransaction_impl()

INTERNAL: Commit the external transaction.

public SequencingCallback
getActiveSequencingCallback(DatabaseSession dbSession, SequencingCallbackFactory sequencingCallbackFactory)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.getActiveSequencingCallback.

INTERNAL: Returns sequencingCallback for the current active external transaction.
public UnitOfWorkImpl
getActiveUnitOfWork()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.getActiveUnitOfWork.

INTERNAL: Return the active unit of work for the current external transaction.
public ExceptionHandler
getExceptionHandler()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.getExceptionHandler.

Return the exception handler used to handle or wrap exceptions thrown in before/after completion.
public SynchronizationListenerFactory
getListenerFactory()

INTERNAL: Get the factory used to generate synchronization listeners.

public AbstractSession
public Object
getTransaction()

INTERNAL: Return the active external transaction object, or null if none is active.

protected abstract Object

Returns:

The active transaction object, or null if no transaction is active
getTransaction_impl
()

INTERNAL: Return the active external transaction for the calling thread, or null if none is currently active for this thread.

public Object
getTransactionKey(Object transaction)

INTERNAL: Return a key for the specified external transaction object.

protected abstract Object

Returns:

A key for the passed in transaction, or null if no transaction specified
getTransactionKey_impl
(Object
The transaction to which the returned key applies (may be null)
transaction
)

INTERNAL: Return a key for the specified external transaction object.

public Object
getTransactionStatus()

INTERNAL: Return the transaction status.

protected abstract Object

Returns:

The current transaction status
getTransactionStatus_impl
()

INTERNAL: Return the transaction status.

public Map<Object, UnitOfWorkImpl>
getUnitsOfWork()

INTERNAL: Return the hashtable keyed on the external transaction objects with values that are the associated units of work.

public boolean
hasActiveUnitOfWork()

INTERNAL: Return true if there is a unit of work associated with the active external transaction.

public void
public abstract boolean
isRolledBack_impl(Object status)

INTERNAL: Return true if the transaction is in the rolled back state.

public boolean
isSequencingCallbackRequired()

INTERNAL: Indicates whether sequencing callback may be required.

public Object

Returns:

The object bound in JNDI to the specified name
jndiLookup
(String
The name to look up
jndiName
)

PUBLIC: Look up a given name in JNDI.

public void
logTxStateTrace(AbstractSession session, String msgInd, Object status)

public void
logTxTrace(AbstractSession session, String msgInd, Object[] args)

public UnitOfWorkImpl
lookupActiveUnitOfWork()

INTERNAL: Return the unit of work associated with the active external transaction.

public UnitOfWorkImpl
lookupActiveUnitOfWork(Object transaction)

INTERNAL: Return the unit of work associated with the active external transaction.

public void
protected abstract void
markTransactionForRollback_impl()

INTERNAL: Mark the external transaction for rollback.

public boolean
noTransactionOrRolledBackOrCommited()

INTERNAL: Used the EJB 3.0 to determine if a transaction is in a state where an EntityManager can be closed

public int
numSessionsRequiringSequencingCallback()

INTERNAL: Indicates how many sessions require sequencing callbacks.

protected abstract void
registerSynchronization_impl(AbstractSynchronizationListener
The synchronization listener created for this transaction
listener
,
Object
The active transaction for which notification is being requested
txn
)

INTERNAL: Register the specified synchronization listener with the given active transaction.

public void
registerSynchronizationListener(UnitOfWorkImpl uow, AbstractSession session)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.registerSynchronizationListener.

INTERNAL: Associate the given unit of work and EclipseLink session with the current external transaction.
public void
removeSequencingListener(Object transactionKey)

INTERNAL: Clears sequencingCallbacks.

public void
removeUnitOfWork(Object transactionKey)

INTERNAL: Remove the unit of work associated with the transaction passed in.

public void
rollbackTransaction(AbstractSession
The session for which the transaction is being rolled back.
session
)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.rollbackTransaction.

INTERNAL: Roll back the external transaction.
protected abstract void
rollbackTransaction_impl()

INTERNAL: Roll back the external transaction.

public void
setExceptionHandler(ExceptionHandler exceptionHandler)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.setExceptionHandler.

Set an exception handler to handle or wrap exceptions thrown in before/after completion.
public void
setListenerFactory(SynchronizationListenerFactory factory)

INTERNAL: Set the factory used to generate synchronization listeners.

public void
protected void
setUnitsOfWork(ConcurrentMap<Object, UnitOfWorkImpl> unitsOfWork)

INTERNAL: Set the table of transactions to units of work.

protected abstract String
statusToString_impl(Object status)

INTERNAL: Convert the status to a string for tracing.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeUnitOfWorkThreadLocalback to summary
protected ThreadLocal<UnitOfWorkImpl> activeUnitOfWorkThreadLocal

PERF: Cache the active uow in a thread local.

currentlyProcessedListenersback to summary
protected ConcurrentMap<Object, AbstractSynchronizationListener> currentlyProcessedListeners

Non-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0

exceptionHandlerback to summary
protected ExceptionHandler exceptionHandler

Allow exception in before/after completion to be wrapped.

listenerFactoryback to summary
protected SynchronizationListenerFactory listenerFactory

Generates listener instances for synchronization

numSessionsRequiringSequencingCallbackback to summary
protected int numSessionsRequiringSequencingCallback

more - the session is a session broker with several members requiring sequencing callbacks.

sequencingListenersback to summary
protected ConcurrentMap<Object, AbstractSynchronizationListener> sequencingListeners

Non-null only in case sequencing callbacks are used: numSessionsRequiringSequencingCallback > 0

sessionback to summary
protected AbstractSession session

The session this controller is responsible for controlling

unitsOfWorkback to summary
protected ConcurrentMap<Object, UnitOfWorkImpl> unitsOfWork

Table of external transaction object keys and unit of work values

Constructor Detail

AbstractTransactionControllerback to summary
protected AbstractTransactionController()

INTERNAL: Return a new controller.

Method Detail

addUnitOfWorkback to summary
public void addUnitOfWork(Object transactionKey, UnitOfWorkImpl activeUnitOfWork)

INTERNAL: Add a UnitOfWork object to the Hashtable keyed on the external transaction object.

beginTransactionback to summary
public void beginTransaction(AbstractSession session)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.beginTransaction.

INTERNAL: Begin an external transaction.

Parameters
session:AbstractSession

The session for which the transaction is being begun.

Annotations
@Override
beginTransaction_implback to summary
protected abstract void beginTransaction_impl() throws Exception

INTERNAL: Begin an external transaction. Do this in a way appropriate to the transaction subsystem.

bindToCurrentTransactionback to summary
public void bindToCurrentTransaction(UnitOfWorkImpl unitOfWork, 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:UnitOfWorkImpl

The unit of work that is to be bound to the active transaction

session:AbstractSession

The session ancestor of the unit of work

canBeginTransaction_implback to summary
protected abstract boolean canBeginTransaction_impl(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:Object

The current transaction status

Returns:boolean

true if the current state allows for a transaction to be started

canCommitTransaction_implback to summary
protected abstract boolean canCommitTransaction_impl(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:Object

The current transaction status

Returns:boolean

true if the current state allows for a transaction to be committed

canIssueSQLToDatabase_implback to summary
protected abstract boolean canIssueSQLToDatabase_impl(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:Object

The current transaction status

Returns:boolean

true if the current state allows for the SQL to be sent to the database

canMergeUnitOfWork_implback to summary
protected abstract boolean canMergeUnitOfWork_impl(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:Object

The current transaction status

Returns:boolean

true if the current state dictates that the unit of work should be merged

canRollbackTransaction_implback to summary
protected abstract boolean canRollbackTransaction_impl(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:Object

The current transaction status

Returns:boolean

true if the current state allows for a transaction to be rolled back

clearSequencingListenersback to summary
public void clearSequencingListeners()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.clearSequencingListeners.

INTERNAL: Clears sequencing listeners. Called by initializeSequencingListeners and by sequencing on disconnect.

Annotations
@Override
commitTransactionback to summary
public void commitTransaction(AbstractSession session)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.commitTransaction.

INTERNAL: Commit the external transaction.

Parameters
session:AbstractSession

The session for which the transaction is being committed.

Annotations
@Override
commitTransaction_implback to summary
protected abstract void commitTransaction_impl() throws Exception

INTERNAL: Commit the external transaction. Do this in a way appropriate to the transaction subsystem.

getActiveSequencingCallbackback to summary
public SequencingCallback getActiveSequencingCallback(DatabaseSession dbSession, SequencingCallbackFactory sequencingCallbackFactory)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.getActiveSequencingCallback.

INTERNAL: Returns sequencingCallback for the current active external transaction. DatabaseSession is passed for the sake of SessionBroker case. This method requires active external transaction.

Annotations
@Override
getActiveUnitOfWorkback to summary
public UnitOfWorkImpl getActiveUnitOfWork()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.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.

Annotations
@Override
getExceptionHandlerback to summary
public ExceptionHandler getExceptionHandler()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.getExceptionHandler.

Return the exception handler used to handle or wrap exceptions thrown in before/after completion.

Annotations
@Override
getListenerFactoryback to summary
public SynchronizationListenerFactory getListenerFactory()

INTERNAL: Get the factory used to generate synchronization listeners.

getSessionback to summary
public AbstractSession getSession()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.getSession.

INTERNAL: Return the manager's session.

Annotations
@Override
getTransactionback to summary
public 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.

getTransaction_implback to summary
protected abstract Object getTransaction_impl() throws Exception

INTERNAL: Return the active external transaction for the calling thread, or null if none is currently active for this thread.

Returns:Object

The active transaction object, or null if no transaction is active

getTransactionKeyback to summary
public Object getTransactionKey(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).

getTransactionKey_implback to summary
protected abstract Object getTransactionKey_impl(Object transaction) throws Exception

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).

Parameters
transaction:Object

The transaction to which the returned key applies (may be null)

Returns:Object

A key for the passed in transaction, or null if no transaction specified

getTransactionStatusback to summary
public Object getTransactionStatus()

INTERNAL: Return the transaction status. This may be any type of status or value, depending upon the transaction system.

getTransactionStatus_implback to summary
protected abstract Object getTransactionStatus_impl() throws Exception

INTERNAL: Return the transaction status. This may be any type of status or value, depending upon the transaction system.

Returns:Object

The current transaction status

getUnitsOfWorkback to summary
public Map<Object, UnitOfWorkImpl> getUnitsOfWork()

INTERNAL: Return the hashtable keyed on the external transaction objects with values that are the associated units of work.

hasActiveUnitOfWorkback to summary
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.

initializeSequencingListenersback to summary
public void initializeSequencingListeners()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.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).

Annotations
@Override
isRolledBack_implback to summary
public abstract boolean isRolledBack_impl(Object status)

INTERNAL: Return true if the transaction is in the rolled back state.

isSequencingCallbackRequiredback to summary
public boolean isSequencingCallbackRequired()

INTERNAL: Indicates whether sequencing callback may be required.

jndiLookupback to summary
public Object jndiLookup(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:String

The name to look up

Returns:Object

The object bound in JNDI to the specified name

Exceptions
TransactionException:
Thrown in case of lookup failure
logTxStateTraceback to summary
public void logTxStateTrace(AbstractSession session, String msgInd, Object status)
logTxTraceback to summary
public void logTxTrace(AbstractSession session, String msgInd, Object[] args)
lookupActiveUnitOfWorkback to summary
public 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.

lookupActiveUnitOfWorkback to summary
public UnitOfWorkImpl lookupActiveUnitOfWork(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.

markTransactionForRollbackback to summary
public void markTransactionForRollback()

Implements org.eclipse.persistence.sessions.ExternalTransactionController.markTransactionForRollback.

INTERNAL: Mark the external transaction for rollback.

Annotations
@Override
markTransactionForRollback_implback to summary
protected abstract void markTransactionForRollback_impl() throws Exception

INTERNAL: Mark the external transaction for rollback. Do this in a way appropriate to the transaction subsystem.

noTransactionOrRolledBackOrCommitedback to summary
public boolean noTransactionOrRolledBackOrCommited()

INTERNAL: Used the EJB 3.0 to determine if a transaction is in a state where an EntityManager can be closed

numSessionsRequiringSequencingCallbackback to summary
public int numSessionsRequiringSequencingCallback()

INTERNAL: Indicates how many sessions require sequencing callbacks.

registerSynchronization_implback to summary
protected abstract void registerSynchronization_impl(AbstractSynchronizationListener listener, Object txn) throws Exception

INTERNAL: Register the specified synchronization listener with the given active transaction.

Parameters
listener:AbstractSynchronizationListener

The synchronization listener created for this transaction

txn:Object

The active transaction for which notification is being requested

registerSynchronizationListenerback to summary
public void registerSynchronizationListener(UnitOfWorkImpl uow, AbstractSession session) throws DatabaseException

Implements org.eclipse.persistence.sessions.ExternalTransactionController.registerSynchronizationListener.

INTERNAL: Associate the given unit of work and EclipseLink session with the current external transaction. This method is offered only for backwards compatibility.

Annotations
@Override
removeSequencingListenerback to summary
public void removeSequencingListener(Object transactionKey)

INTERNAL: Clears sequencingCallbacks. Called by initializeSequencingCallbacks and by sequencing on disconnect.

removeUnitOfWorkback to summary
public void removeUnitOfWork(Object transactionKey)

INTERNAL: Remove the unit of work associated with the transaction passed in.

rollbackTransactionback to summary
public void rollbackTransaction(AbstractSession session)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.rollbackTransaction.

INTERNAL: Roll back the external transaction.

Parameters
session:AbstractSession

The session for which the transaction is being rolled back.

Annotations
@Override
rollbackTransaction_implback to summary
protected abstract void rollbackTransaction_impl() throws Exception

INTERNAL: Roll back the external transaction. Do this in a way appropriate to the transaction subsystem.

setExceptionHandlerback to summary
public void setExceptionHandler(ExceptionHandler exceptionHandler)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.setExceptionHandler.

Set an exception handler to handle or wrap exceptions thrown in before/after completion.

Annotations
@Override
setListenerFactoryback to summary
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.

setSessionback to summary
public void setSession(AbstractSession session)

Implements org.eclipse.persistence.sessions.ExternalTransactionController.setSession.

INTERNAL: Set the manager's session.

Annotations
@Override
setUnitsOfWorkback to summary
protected void setUnitsOfWork(ConcurrentMap<Object, UnitOfWorkImpl> unitsOfWork)

INTERNAL: Set the table of transactions to units of work.

statusToString_implback to summary
protected abstract String statusToString_impl(Object status)

INTERNAL: Convert the status to a string for tracing.