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
 public void Init()
 {
     _mockTxnMgr = new MockTxnPlatformMgrAbstract();
     _mockTxnMgr.TransactionSynchronization = TransactionSynchronizationState.Always;
     if (TransactionSynchronizationManager.SynchronizationActive)
     {
         TransactionSynchronizationManager.ClearSynchronization();
     }
 }
 public void Destroy()
 {
     _mockTxnMgr.Verify();
     _mockTxnMgr = null;
     if (TransactionSynchronizationManager.SynchronizationActive)
     {
         TransactionSynchronizationManager.ClearSynchronization();
     }
 }
        public void SynchronizationsLifeCycle()
        {
            TransactionSynchronizationManager.InitSynchronization();
            IList syncs = TransactionSynchronizationManager.Synchronizations;

            Assert.AreEqual(0, syncs.Count);
            TransactionSynchronizationManager.RegisterSynchronization(MockRepository.GenerateMock <ITransactionSynchronization>());
            syncs = TransactionSynchronizationManager.Synchronizations;
            Assert.AreEqual(1, syncs.Count);
            TransactionSynchronizationManager.ClearSynchronization();
        }
        public void SynchronizationsLifeCycle()
        {
            TransactionSynchronizationManager.InitSynchronization();
            IList syncs = TransactionSynchronizationManager.Synchronizations;

            Assert.AreEqual(0, syncs.Count);
            TransactionSynchronizationManager.RegisterSynchronization(new MockTxnSync());
            syncs = TransactionSynchronizationManager.Synchronizations;
            Assert.AreEqual(1, syncs.Count);
            TransactionSynchronizationManager.ClearSynchronization();
        }
 public void RegisterSyncsInvalid()
 {
     Assert.Throws <InvalidOperationException>(() => TransactionSynchronizationManager.RegisterSynchronization(MockRepository.GenerateMock <ITransactionSynchronization>()));
 }
 public void SynchronizationsClearInvalid()
 {
     Assert.Throws <InvalidOperationException>(() => TransactionSynchronizationManager.ClearSynchronization());
 }
 public void InitSynchronizationsInvalid()
 {
     TransactionSynchronizationManager.InitSynchronization();
     Assert.Throws <InvalidOperationException>(() => TransactionSynchronizationManager.InitSynchronization());
 }
 public void RegisterSyncsInvalid()
 {
     TransactionSynchronizationManager.RegisterSynchronization(new MockTxnSync());
 }
 public void SynchronizationsClearInvalid()
 {
     TransactionSynchronizationManager.ClearSynchronization();
 }
 public void InitSynchronizationsInvalid()
 {
     TransactionSynchronizationManager.InitSynchronization();
     TransactionSynchronizationManager.InitSynchronization();
 }
Exemple #11
0
 public void RegisterSyncsInvalid()
 {
     Assert.Throws <InvalidOperationException>(() => TransactionSynchronizationManager.RegisterSynchronization(A.Fake <ITransactionSynchronization>()));
 }
 public void RegisterSyncsInvalid()
 {
     TransactionSynchronizationManager.RegisterSynchronization(MockRepository.GenerateMock <ITransactionSynchronization>());
 }