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.
Modifier and Type | Field and Description |
---|---|
protected ThreadLocal |
activeUnitOfWorkThreadLocal
PERF: Cache the active uow in a thread local.
|
protected SynchronizationListenerFactory |
listenerFactory
Generates listener instances for synchronization
|
protected AbstractSession |
session
The session this controller is responsible for controlling
|
protected Hashtable |
unitsOfWork
Table of external transaction object keys and unit of work values
|
Constructor and Description |
---|
AbstractTransactionController()
INTERNAL:
Return a new controller.
|
Modifier and Type | Method and Description |
---|---|
void |
addUnitOfWork(Object transaction,
UnitOfWorkImpl activeUnitOfWork)
INTERNAL:
Add a UnitOfWork object to the Hashtable keyed on the external transaction object.
|
protected abstract void |
beginTransaction_impl()
INTERNAL:
Begin an external transaction.
|
void |
beginTransaction(AbstractSession session)
INTERNAL:
Begin an external transaction.
|
void |
bindToCurrentTransaction(UnitOfWorkImpl unitOfWork,
AbstractSession session)
INTERNAL:
Associate the given unit of work and TopLink session with the active external
transaction.
|
protected abstract boolean |
canBeginTransaction_impl(Object status)
INTERNAL:
Return true if the status indicates that a transaction can be started.
|
protected abstract boolean |
canCommitTransaction_impl(Object status)
INTERNAL:
Return true if the status indicates that a transaction can be committed.
|
protected abstract boolean |
canIssueSQLToDatabase_impl(Object status)
INTERNAL:
Return true if the status indicates that the SQL should be issued to the db.
|
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.
|
protected abstract boolean |
canRollbackTransaction_impl(Object status)
INTERNAL:
Return true if the status indicates that a transaction can be rolled back.
|
protected abstract void |
commitTransaction_impl()
INTERNAL:
Commit the external transaction.
|
void |
commitTransaction(AbstractSession session)
INTERNAL:
Commit the external transaction.
|
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.
|
AbstractSession |
getSession()
INTERNAL:
Return the manager's session.
|
protected abstract Object |
getTransaction_impl()
INTERNAL:
Return the active external transaction for the calling thread, or null if
none is currently active for this thread.
|
Object |
getTransaction()
INTERNAL:
Return the active external transaction object, or null if
none is active.
|
protected abstract Object |
getTransactionKey_impl(Object transaction)
INTERNAL:
Return a key for the specified external transaction object.
|
Object |
getTransactionKey(Object transaction)
INTERNAL:
Return a key for the specified external transaction object.
|
protected abstract Object |
getTransactionStatus_impl()
INTERNAL:
Return the transaction status.
|
Object |
getTransactionStatus()
INTERNAL:
Return the transaction status.
|
Hashtable |
getUnitsOfWork()
INTERNAL:
Return the hashtable keyed on the external transaction objectss 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.
|
abstract boolean |
isRolledBack_impl(Object status)
INTERNAL:
Return true if the transaction is in the roleld back state.
|
Object |
jndiLookup(String jndiName)
PUBLIC:
Look up a given name in JNDI.
|
void |
logTxStateTrace(AbstractSession session,
String msgInd,
Object status) |
void |
logTxTrace(AbstractSession session,
String msgInd,
Object[] args) |
UnitOfWorkImpl |
lookupActiveUnitOfWork()
INTERNAL:
Return the unit of work associated with the active external transaction.
|
UnitOfWorkImpl |
lookupActiveUnitOfWork(Object transaction)
INTERNAL:
Return the unit of work associated with the active external transaction.
|
protected abstract void |
markTransactionForRollback_impl()
INTERNAL:
Mark the external transaction for rollback.
|
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
|
protected abstract void |
registerSynchronization_impl(AbstractSynchronizationListener listener,
Object txn)
INTERNAL:
Register the specified synchronization listener with the given active
transaction.
|
void |
registerSynchronizationListener(UnitOfWorkImpl uow,
AbstractSession session)
INTERNAL:
Associate the given unit of work and TopLink session with the current external
transaction.
|
void |
removeUnitOfWork(Object transaction)
INTERNAL:
Remove the unit of work associated with the transaction passed in.
|
protected abstract void |
rollbackTransaction_impl()
INTERNAL:
Roll back the external transaction.
|
void |
rollbackTransaction(AbstractSession session)
INTERNAL:
Roll back the external transaction.
|
void |
setListenerFactory(SynchronizationListenerFactory factory)
INTERNAL:
Set the factory used to generate synchronization listeners.
|
void |
setSession(AbstractSession session)
INTERNAL:
Set the manager's session.
|
protected void |
setUnitsOfWork(Hashtable 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.
|
protected Hashtable unitsOfWork
protected AbstractSession session
protected SynchronizationListenerFactory listenerFactory
protected ThreadLocal activeUnitOfWorkThreadLocal
public AbstractTransactionController()
public void bindToCurrentTransaction(UnitOfWorkImpl unitOfWork, AbstractSession session)
unitOfWork
- The unit of work that is to be bound to the active transactionsession
- The session ancestor of the unit of workpublic void beginTransaction(AbstractSession session)
beginTransaction
in interface ExternalTransactionController
session
- The session for which the transaction is being begun.public void commitTransaction(AbstractSession session)
commitTransaction
in interface ExternalTransactionController
session
- The session for which the transaction is being committed.public void rollbackTransaction(AbstractSession session)
rollbackTransaction
in interface ExternalTransactionController
session
- The session for which the transaction is being rolled back.public void markTransactionForRollback()
markTransactionForRollback
in interface ExternalTransactionController
public Object getTransaction()
public Object getTransactionKey(Object transaction)
public Object getTransactionStatus()
public boolean noTransactionOrRolledBackOrCommited()
public abstract boolean isRolledBack_impl(Object status)
public boolean hasActiveUnitOfWork()
public UnitOfWorkImpl getActiveUnitOfWork()
getActiveUnitOfWork
in interface ExternalTransactionController
public UnitOfWorkImpl lookupActiveUnitOfWork()
public UnitOfWorkImpl lookupActiveUnitOfWork(Object transaction)
public void addUnitOfWork(Object transaction, UnitOfWorkImpl activeUnitOfWork)
public void removeUnitOfWork(Object transaction)
public AbstractSession getSession()
getSession
in interface ExternalTransactionController
public void setSession(AbstractSession session)
setSession
in interface ExternalTransactionController
public Hashtable getUnitsOfWork()
protected void setUnitsOfWork(Hashtable unitsOfWork)
public SynchronizationListenerFactory getListenerFactory()
public void setListenerFactory(SynchronizationListenerFactory factory)
public void registerSynchronizationListener(UnitOfWorkImpl uow, AbstractSession session) throws DatabaseException
registerSynchronizationListener
in interface ExternalTransactionController
DatabaseException
public Object jndiLookup(String jndiName)
The lookup assumes that it is taking place on the server side, and that the InitialContext can be used without requiring any special properties.
jndiName
- The name to look upTransactionException
- Thrown in case of lookup failurepublic void logTxTrace(AbstractSession session, String msgInd, Object[] args)
public void logTxStateTrace(AbstractSession session, String msgInd, Object status)
protected abstract void registerSynchronization_impl(AbstractSynchronizationListener listener, Object txn) throws Exception
listener
- The synchronization listener created for this transactiontxn
- The active transaction for which notification is being requestedException
protected abstract Object getTransaction_impl() throws Exception
Exception
protected abstract Object getTransactionKey_impl(Object transaction) throws Exception
transaction
- The transaction to which the returned key applies (may be null)Exception
protected abstract Object getTransactionStatus_impl() throws Exception
Exception
protected abstract void beginTransaction_impl() throws Exception
Exception
protected abstract void commitTransaction_impl() throws Exception
Exception
protected abstract void rollbackTransaction_impl() throws Exception
Exception
protected abstract void markTransactionForRollback_impl() throws Exception
Exception
protected abstract boolean canBeginTransaction_impl(Object status)
status
- The current transaction statusprotected abstract boolean canCommitTransaction_impl(Object status)
status
- The current transaction statusprotected abstract boolean canRollbackTransaction_impl(Object status)
status
- The current transaction statusprotected abstract boolean canIssueSQLToDatabase_impl(Object status)
status
- The current transaction statusprotected abstract boolean canMergeUnitOfWork_impl(Object status)
status
- The current transaction statusCopyright © 2024. All rights reserved.