com.interface21.transaction.support
Class AbstractPlatformTransactionManager

java.lang.Object
  |
  +--com.interface21.transaction.support.AbstractPlatformTransactionManager
All Implemented Interfaces:
PlatformTransactionManager
Direct Known Subclasses:
DataSourceTransactionManager, HibernateTransactionManager, JdoTransactionManager, JtaTransactionManager

public abstract class AbstractPlatformTransactionManager
extends java.lang.Object
implements PlatformTransactionManager

Abstract class that allows for easy implementation of PlatformTransactionManager. Provides the following case handling:

Since:
28.03.2003
Author:
Juergen Hoeller
See Also:
setAllowNonTransactionalExecution(boolean), setTransactionSynchronization(boolean)

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
AbstractPlatformTransactionManager()
           
 
Method Summary
 void commit(TransactionStatus status)
          This implementation of commit handles programmatic rollback requests, i.e. status.isRollbackOnly(), and non-transactional execution.
protected abstract  void doBegin(java.lang.Object transaction, int isolationLevel, int timeout)
          Begin a new transaction with the given isolation level.
protected abstract  void doCommit(TransactionStatus status)
          Perform an actual commit on the given transaction.
protected abstract  java.lang.Object doGetTransaction()
          Return a current transaction object, i.e. a JTA UserTransaction.
protected abstract  void doRollback(TransactionStatus status)
          Perform an actual rollback on the given transaction.
protected abstract  void doSetRollbackOnly(TransactionStatus status)
          Set the given transaction rollback-only.
 boolean getAllowNonTransactionalExecution()
          Return if transaction support does not need to be available.
 TransactionStatus getTransaction(TransactionDefinition definition)
          This implementation of getTransaction handles propagation behavior and checks non-transactional execution (on CannotCreateTransactionException).
 boolean getTransactionSynchronization()
          Return if this transaction manager should activate the thread-bound transaction synchronization support.
protected abstract  boolean isExistingTransaction(java.lang.Object transaction)
          Check if the given transaction object indicates an existing, i.e. already begun, transaction.
 void rollback(TransactionStatus status)
          This implementation of rollback handles participating in existing transactions and non-transactional execution.
 void setAllowNonTransactionalExecution(boolean allowNonTransactionalExecution)
          Set if transaction support does not need to be available, e.g. when JTA isn't available in the container.
 void setTransactionSynchronization(boolean transactionSynchronization)
          Set if this transaction manager should activate the thread-bound transaction synchronization support.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

AbstractPlatformTransactionManager

public AbstractPlatformTransactionManager()
Method Detail

setAllowNonTransactionalExecution

public final void setAllowNonTransactionalExecution(boolean allowNonTransactionalExecution)
Set if transaction support does not need to be available, e.g. when JTA isn't available in the container. Non-transactional fallback behavior is enabled in this case.

getAllowNonTransactionalExecution

public final boolean getAllowNonTransactionalExecution()
Return if transaction support does not need to be available.

setTransactionSynchronization

public final void setTransactionSynchronization(boolean transactionSynchronization)
Set if this transaction manager should activate the thread-bound transaction synchronization support. The default can very between transaction manager implementations, this class specifies false.

Note that transaction synchronization isn't supported for multiple concurrent transactions. Only one transaction manager is allowed to activate it at any time.

See Also:
TransactionSynchronizationManager

getTransactionSynchronization

public final boolean getTransactionSynchronization()
Return if this transaction manager should activate the thread-bound transaction synchronization support.

getTransaction

public final TransactionStatus getTransaction(TransactionDefinition definition)
                                       throws TransactionException
This implementation of getTransaction handles propagation behavior and checks non-transactional execution (on CannotCreateTransactionException). Delegates to doGetTransaction, isExistingTransaction, doBegin.
Specified by:
getTransaction in interface PlatformTransactionManager
Following copied from interface: com.interface21.transaction.PlatformTransactionManager
Parameters:
definition - TransactionDefinition instance (can be null for defaults), describing propagation behavior, isolation level, timeout etc.
Returns:
transaction status object representing the new or current transaction
Throws:
TransactionException - in case of lookup, creation, or system errors

commit

public final void commit(TransactionStatus status)
                  throws TransactionException
This implementation of commit handles programmatic rollback requests, i.e. status.isRollbackOnly(), and non-transactional execution. Delegates to doCommit and rollback.
Specified by:
commit in interface PlatformTransactionManager
Following copied from interface: com.interface21.transaction.PlatformTransactionManager
Parameters:
status - object returned by the getTransaction() method.
Throws:
TransactionException - in case of commit or system errors

rollback

public final void rollback(TransactionStatus status)
                    throws TransactionException
This implementation of rollback handles participating in existing transactions and non-transactional execution. Delegates to doRollback and doSetRollbackOnly.
Specified by:
rollback in interface PlatformTransactionManager
Following copied from interface: com.interface21.transaction.PlatformTransactionManager
Parameters:
status - object returned by the getTransaction() method.
Throws:
TransactionException - in case of system errors

doGetTransaction

protected abstract java.lang.Object doGetTransaction()
                                              throws CannotCreateTransactionException,
                                                     TransactionException
Return a current transaction object, i.e. a JTA UserTransaction.
Returns:
the current transaction object
Throws:
CannotCreateTransactionException - if transaction support is not available (e.g. no JTA UserTransaction retrievable from JNDI)
TransactionException - in case of lookup or system errors

isExistingTransaction

protected abstract boolean isExistingTransaction(java.lang.Object transaction)
                                          throws TransactionException
Check if the given transaction object indicates an existing, i.e. already begun, transaction.
Parameters:
transaction - transaction object returned by doGetTransaction()
Returns:
if there is an existing transaction
Throws:
TransactionException - in case of system errors

doBegin

protected abstract void doBegin(java.lang.Object transaction,
                                int isolationLevel,
                                int timeout)
                         throws TransactionException
Begin a new transaction with the given isolation level.
Parameters:
transaction - transaction object returned by doGetTransaction()
isolationLevel - desired isolation level
timeout - transaction timeout (in seconds)
Throws:
TransactionException - in case of creation or system errors

doCommit

protected abstract void doCommit(TransactionStatus status)
                          throws TransactionException
Perform an actual commit on the given transaction. An implementation does not need to check the rollback-only flag.
Parameters:
status - status representation of the transaction
Throws:
TransactionException - in case of commit or system errors

doRollback

protected abstract void doRollback(TransactionStatus status)
                            throws TransactionException
Perform an actual rollback on the given transaction. An implementation does not need to check the new transaction flag.
Parameters:
status - status representation of the transaction
Throws:
TransactionException - in case of system errors

doSetRollbackOnly

protected abstract void doSetRollbackOnly(TransactionStatus status)
                                   throws TransactionException
Set the given transaction rollback-only. Only called on rollback if the current transaction takes part in an existing one.
Parameters:
status - status representation of the transaction
Throws:
TransactionException - in case of system errors


Rod Johnson and Spring contributors 2001-2003.