C# Class Spring.Transaction.Support.TransactionSynchronizationManager

Internal class that manages resources and transaction synchronizations per thread.
Supports one resource per key without overwriting, i.e. a resource needs to be removed before a new one can be set for the same key. Supports a list of transaction synchronizations if synchronization is active.

Resource management code should check for thread-bound resources via GetResource(). It is normally not supposed to bind resources to threads, as this is the responsiblity of transaction managers. A further option is to lazily bind on first use if transaction synchronization is active, for performing transactions that span an arbitrary number of resources.

Transaction synchronization must be activated and deactivated by a transaction manager via InitSynchronization and ClearSynchronization. This is automatically supported by Spring.Transaction.Support.AbstractPlatformTransactionManager.

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.

Note that this class uses following naming convention for the named 'data slots' for storage of thread local data, 'Spring.Transaction:Name' where Name is either
Datei anzeigen Open project: spring-projects/spring-net Class Usage Examples

Public Methods

Method Description
BindResource ( Object key, Object value ) : void

Bind the given resource for teh given key to the current thread

Clear ( ) : void

Clears the entire transaction synchronization state for the current thread, registered synchronizations as well as the various transaction characteristics.

ClearSynchronization ( ) : void

Deactivate transaction synchronization for the current thread.

Called by transaction manager on transaction cleanup.

GetResource ( Object key ) : object

Retrieve a resource for the given key that is bound to the current thread.

HasResource ( Object key ) : bool

Check if there is a resource for the given key bound to the current thread.

InitSynchronization ( ) : void

Activate transaction synchronization for the current thread.

Called by transaction manager at the beginning of a transaction.

RegisterSynchronization ( ITransactionSynchronization synchronization ) : void

Register a new transaction synchronization for the current thread.

Typically called by resource management code.

UnbindResource ( Object key ) : object

Unbind a resource for the given key from the current thread

Private Methods

Method Description
Describe ( object obj ) : string

Method Details

BindResource() public static method

Bind the given resource for teh given key to the current thread
public static BindResource ( Object key, Object value ) : void
key Object key to bind the value to
value Object value to bind
return void

Clear() public static method

Clears the entire transaction synchronization state for the current thread, registered synchronizations as well as the various transaction characteristics.
public static Clear ( ) : void
return void

ClearSynchronization() public static method

Deactivate transaction synchronization for the current thread.
Called by transaction manager on transaction cleanup.
/// If synchronization is not active. ///
public static ClearSynchronization ( ) : void
return void

GetResource() public static method

Retrieve a resource for the given key that is bound to the current thread.
public static GetResource ( Object key ) : object
key Object key to check
return object

HasResource() public static method

Check if there is a resource for the given key bound to the current thread.
public static HasResource ( Object key ) : bool
key Object key to check
return bool

InitSynchronization() public static method

Activate transaction synchronization for the current thread.
Called by transaction manager at the beginning of a transaction.
/// If synchronization is already active. ///
public static InitSynchronization ( ) : void
return void

RegisterSynchronization() public static method

Register a new transaction synchronization for the current thread.
Typically called by resource management code.
/// If synchronization is not active. ///
public static RegisterSynchronization ( ITransactionSynchronization synchronization ) : void
synchronization ITransactionSynchronization
return void

UnbindResource() public static method

Unbind a resource for the given key from the current thread
if there is no value bound to the thread
public static UnbindResource ( Object key ) : object
key Object key to check
return object