org.eclipse.persistence.transaction
Class AbstractTransactionController

java.lang.Object
  extended by org.eclipse.persistence.transaction.AbstractTransactionController
All Implemented Interfaces:
ExternalTransactionController
Direct Known Subclasses:
JTATransactionController

public abstract class AbstractTransactionController
extends 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.

See Also:
AbstractSynchronizationListener, ExternalTransactionController

Constructor Summary
AbstractTransactionController()
          INTERNAL: Return a new controller.
 
Method Summary
 void addUnitOfWork(Object transactionKey, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl activeUnitOfWork)
          INTERNAL: Add a UnitOfWork object to the Hashtable keyed on the external transaction object.
 void beginTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Begin an external transaction.
 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.
 void clearSequencingListeners()
          INTERNAL: Clears sequencing listeners.
 void commitTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Commit the external transaction.
 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.
 org.eclipse.persistence.internal.sessions.UnitOfWorkImpl getActiveUnitOfWork()
          INTERNAL: Return the active unit of work for the current external transaction.
 SynchronizationListenerFactory getListenerFactory()
          INTERNAL: Get the factory used to generate synchronization listeners.
 org.eclipse.persistence.internal.sessions.AbstractSession getSession()
          INTERNAL: Return the manager's session.
 Object getTransaction()
          INTERNAL: Return the active external transaction object, or null if none is active.
 Object getTransactionKey(Object transaction)
          INTERNAL: Return a key for the specified external transaction object.
 Object getTransactionStatus()
          INTERNAL: Return the transaction status.
 Map getUnitsOfWork()
          INTERNAL: Return the hashtable keyed on the external transaction objects with values that are the associated units of work.
 boolean hasActiveUnitOfWork()
          INTERNAL: Return true if there is a unit of work associated with the active external transaction.
 void initializeSequencingListeners()
          INTERNAL: Initializes sequencing listeners.
abstract  boolean isRolledBack_impl(Object status)
          INTERNAL: Return true if the transaction is in the rolled back state.
 boolean isSequencingCallbackRequired()
          INTERNAL: Indicates whether sequencing callback may be required.
 Object jndiLookup(String jndiName)
          PUBLIC: Look up a given name in JNDI.
 void logTxStateTrace(org.eclipse.persistence.internal.sessions.AbstractSession session, String msgInd, Object status)
           
 void logTxTrace(org.eclipse.persistence.internal.sessions.AbstractSession session, String msgInd, Object[] args)
           
 org.eclipse.persistence.internal.sessions.UnitOfWorkImpl lookupActiveUnitOfWork()
          INTERNAL: Return the unit of work associated with the active external transaction.
 org.eclipse.persistence.internal.sessions.UnitOfWorkImpl lookupActiveUnitOfWork(Object transaction)
          INTERNAL: Return the unit of work associated with the active external transaction.
 void markTransactionForRollback()
          INTERNAL: Mark the external transaction for rollback.
 boolean noTransactionOrRolledBackOrCommited()
          INTERNAL: Used the EJB 3.0 to determine if a transaction is in a state where an EntityManager can be closed
 int numSessionsRequiringSequencingCallback()
          INTERNAL: Indicates how many sessions require sequencing callbacks.
 void registerSynchronizationListener(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.
 void removeSequencingListener(Object transactionKey)
          INTERNAL: Clears sequencingCallbacks.
 void removeUnitOfWork(Object transactionKey)
          INTERNAL: Remove the unit of work associated with the transaction passed in.
 void rollbackTransaction(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Roll back the external transaction.
 void setListenerFactory(SynchronizationListenerFactory factory)
          INTERNAL: Set the factory used to generate synchronization listeners.
 void setSession(org.eclipse.persistence.internal.sessions.AbstractSession session)
          INTERNAL: Set the manager's session.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTransactionController

public AbstractTransactionController()
INTERNAL: Return a new controller.

Method Detail

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 transaction
session - 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:
beginTransaction in interface ExternalTransactionController
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:
commitTransaction in interface ExternalTransactionController
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:
rollbackTransaction in interface ExternalTransactionController
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:
markTransactionForRollback in interface ExternalTransactionController

getTransaction

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.


getTransactionKey

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


getTransactionStatus

public 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(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:
getActiveUnitOfWork in interface ExternalTransactionController

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(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(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(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:
getSession in interface ExternalTransactionController

setSession

public void setSession(org.eclipse.persistence.internal.sessions.AbstractSession session)
INTERNAL: Set the manager's session.

Specified by:
setSession in interface ExternalTransactionController

getUnitsOfWork

public Map getUnitsOfWork()
INTERNAL: Return the hashtable keyed on the external transaction objects with values that are the associated 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 DatabaseException
INTERNAL: Associate the given unit of work and EclipseLink session with the current external transaction. This method is offered only for backwards compatibility.

Specified by:
registerSynchronizationListener in interface ExternalTransactionController
Throws:
DatabaseException

jndiLookup

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 - 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. Always clears sequencing listeners first. 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, after it's determined whether sequencing callbacks (and therefore listeners) will be required.

Specified by:
initializeSequencingListeners in interface ExternalTransactionController

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:
getActiveSequencingCallback in interface ExternalTransactionController

clearSequencingListeners

public void clearSequencingListeners()
INTERNAL: Clears sequencing listeners. Called by initializeSequencingListeners and by sequencing on disconnect.

Specified by:
clearSequencingListeners in interface ExternalTransactionController

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(Object transactionKey)
INTERNAL: Clears sequencingCallbacks. Called by initializeSequencingCallbacks and by sequencing on disconnect.


logTxTrace

public void logTxTrace(org.eclipse.persistence.internal.sessions.AbstractSession session,
                       String msgInd,
                       Object[] args)

logTxStateTrace

public void logTxStateTrace(org.eclipse.persistence.internal.sessions.AbstractSession session,
                            String msgInd,
                            Object status)