com.interface21.transaction.support
Class TransactionSynchronizationManager

java.lang.Object
  |
  +--com.interface21.transaction.support.TransactionSynchronizationManager

public abstract class TransactionSynchronizationManager
extends java.lang.Object

Manages a list of transactions synchronizations per thread. Must be activated and deactivated by a transaction manager via init and clear. Automatically supported by AbstractPlatformTransactionManager, and thus all standard Spring transaction managers like JtaTransactionManager.

Resource management code should only register synchronizations when this manager is active, and perform resource cleanup immediately else. If transaction synchronization isn't active, there is either no current transaction, or the transaction manager doesn't support synchronizations.

E.g. used for Hibernate Session close calls when using JTA, for proper transactional handling of the JVM-level cache.

Since:
02.06.2003
Author:
Juergen Hoeller
See Also:
isActive(), register(com.interface21.transaction.support.TransactionSynchronization), TransactionSynchronization, AbstractPlatformTransactionManager, JtaTransactionManager, SessionFactoryUtils.closeSessionIfNecessary(net.sf.hibernate.Session, net.sf.hibernate.SessionFactory)

Constructor Summary
TransactionSynchronizationManager()
           
 
Method Summary
static void clear()
          Deactivate thread synchronizations for the current thread.
static void init()
          Activate thread synchronizations for the current thread.
static boolean isActive()
          Return if thread synchronizations are active for the current thread.
static void register(TransactionSynchronization synchronization)
          Register a new JTA synchronization for the current thread.
static void triggerAfterCompletion(int status)
          Trigger afterCompletion calls for the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionSynchronizationManager

public TransactionSynchronizationManager()
Method Detail

init

public static void init()
Activate thread synchronizations for the current thread. Called by transaction manager on transaction begin.

isActive

public static boolean isActive()
Return if thread synchronizations are active for the current thread. Can be called before register to avoid unnecessary instance creation.
See Also:
register(com.interface21.transaction.support.TransactionSynchronization)

register

public static void register(TransactionSynchronization synchronization)
Register a new JTA synchronization for the current thread. Called by resource management code. Calls get ignored if transaction synchronization isn't active.

triggerAfterCompletion

public static void triggerAfterCompletion(int status)
Trigger afterCompletion calls for the current thread. Called by transaction manager after transaction commit/rollback. Calls get ignored if transaction synchronization isn't active.
Parameters:
status - completion status according to TransactionSynchronization constants
See Also:
TransactionSynchronization

clear

public static void clear()
Deactivate thread synchronizations for the current thread. Called by transaction manager on transaction cleanup.


Rod Johnson and Spring contributors 2001-2003.