org.springframework.transaction.support
Class AbstractPlatformTransactionManager

Direct Known Subclasses:
DataSourceTransactionManager, HibernateTransactionManager, JdoTransactionManager, JtaTransactionManager

public abstract class AbstractPlatformTransactionManager
implements PlatformTransactionManager

Abstract base class that allows for easy implementation of concrete platform transaction managers like JtaTransactionManager and HibernateTransactionManager.

Provides the following workflow handling:

Transaction synchronization is a generic mechanism for registering callbacks that get invoked at transaction completion time. This is mainly used internally by the data access support classes for JDBC, Hibernate, and JDO: They register resources that are opened within the transaction for closing at transaction completion time, allowing e.g. for reuse of the same Hibernate Session within the transaction. The same mechanism can also be used for custom synchronization efforts.

Author:
Juergen Hoeller
Version: $Id: AbstractPlatformTransactionManager.java,v 1.21 2004/02/11 11:00:02 jhoeller Exp $
Since: 28.03.2003
See Also: setTransactionSynchronization(int), TransactionSynchronizationManager, JtaTransactionManager, HibernateTransactionManager

Field Summary
 final static intSYNCHRONIZATION_ALWAYS
          Always activate transaction synchronization, even for "empty" transactions that result from PROPAGATION_SUPPORTS with no existing backend transaction.
 final static intSYNCHRONIZATION_NEVER
          Never active transaction synchronization.
 final static intSYNCHRONIZATION_ON_ACTUAL_TRANSACTION
          Activate transaction synchronization only for actual transactions, i.e.

Method Summary
 final voidcommit(TransactionStatus status)
          This implementation of commit handles participating in existing transactions and programmatic rollback requests.
 final TransactionStatusgetTransaction(TransactionDefinition definition)
          This implementation of getTransaction handles propagation behavior.
 intgetTransactionSynchronization()
          Return if this transaction manager should activate the thread-bound transaction synchronization support.
 booleanisRollbackOnCommitFailure()
          Return if a rollback should be performed on failure of the commit call.
 final voidrollback(TransactionStatus status)
          This implementation of rollback handles participating in existing transactions.
 voidsetRollbackOnCommitFailure(boolean rollbackOnCommitFailure)
          Set if a rollback should be performed on failure of the commit call.
 voidsetTransactionSynchronization(int transactionSynchronization)
          Set when this transaction manager should activate the thread-bound transaction synchronization support.
 voidsetTransactionSynchronizationName(String constantName)
          Set the transaction synchronization by the name of the corresponding constant in this class, e.g.

Field Detail

SYNCHRONIZATION_ALWAYS

public final static int SYNCHRONIZATION_ALWAYS
Always activate transaction synchronization, even for "empty" transactions that result from PROPAGATION_SUPPORTS with no existing backend transaction.

SYNCHRONIZATION_NEVER

public final static int SYNCHRONIZATION_NEVER
Never active transaction synchronization.

SYNCHRONIZATION_ON_ACTUAL_TRANSACTION

public final static int SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
Activate transaction synchronization only for actual transactions, i.e. not for empty ones that result from PROPAGATION_SUPPORTS with no existing backend transaction.
Method Detail

commit

public final void commit(TransactionStatus status)
throws org.springframework.transaction.TransactionException
This implementation of commit handles participating in existing transactions and programmatic rollback requests. Delegates to isRollbackOnly, doCommit and rollback.
See Also:
org.springframework.transaction.TransactionStatus.isRollbackOnly(), isRollbackOnly(java.lang.Object), doCommit(org.springframework.transaction.support.DefaultTransactionStatus), rollback(org.springframework.transaction.TransactionStatus)

getTransaction

public final TransactionStatus getTransaction(TransactionDefinition definition)
throws org.springframework.transaction.TransactionException
This implementation of getTransaction handles propagation behavior. Delegates to doGetTransaction, isExistingTransaction, doBegin.
See Also:
doGetTransaction(), isExistingTransaction(java.lang.Object), doBegin(java.lang.Object,org.springframework.transaction.TransactionDefinition)

getTransactionSynchronization

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

isRollbackOnCommitFailure

public boolean isRollbackOnCommitFailure()
Return if a rollback should be performed on failure of the commit call.

rollback

public final void rollback(TransactionStatus status)
throws org.springframework.transaction.TransactionException
This implementation of rollback handles participating in existing transactions. Delegates to doRollback and doSetRollbackOnly.
See Also:
doRollback(org.springframework.transaction.support.DefaultTransactionStatus), doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus)

setRollbackOnCommitFailure

public void setRollbackOnCommitFailure(boolean rollbackOnCommitFailure)
Set if a rollback should be performed on failure of the commit call. Typically not necessary and thus to be avoided as it can override the commit exception with a subsequent rollback exception. Default is false.

setTransactionSynchronization

public void setTransactionSynchronization(int transactionSynchronization)
Set when this transaction manager should activate the thread-bound transaction synchronization support. Default is "always".

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

See Also:
SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION, SYNCHRONIZATION_NEVER, TransactionSynchronizationManager, TransactionSynchronization

setTransactionSynchronizationName

public void setTransactionSynchronizationName(String constantName)
Set the transaction synchronization by the name of the corresponding constant in this class, e.g. "SYNCHRONIZATION_ALWAYS".
Parameters:
constantName - name of the constant
See Also:
SYNCHRONIZATION_ALWAYS

Association Links

to Class org.springframework.core.Constants

Constants instance for AbstractPlatformTransactionManager