public void CreateSaveAndHoldValidSavepoint()
 {
     ISavepointManager saveMgr = MockRepository.GenerateMock<ISavepointManager>();
     DefaultTransactionStatus status = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());
     status.CreateAndHoldSavepoint("savepoint");
     Assert.IsTrue(status.HasSavepoint);
     Assert.AreEqual("savepoint", status.Savepoint);
 }
		public void CreateSaveAndHoldValidSavepoint()
		{
			MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
			saveMgr.SetSavepointToReturn( "savepoint" );
			DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
			status.CreateAndHoldSavepoint( "savepoint" );
			Assert.IsTrue( status.HasSavepoint );
			Assert.AreEqual( "savepoint", status.Savepoint );
		}
        public void RollbackHeldSavepointSuccess()
        {
            ISavepointManager saveMgr = MockRepository.GenerateMock<ISavepointManager>();
            string savepoint = "savepoint";
            DefaultTransactionStatus status = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());
            status.CreateAndHoldSavepoint(savepoint);
            Assert.IsTrue(status.HasSavepoint);
            Assert.AreEqual(savepoint, status.Savepoint);

            status.RollbackToHeldSavepoint();
            saveMgr.AssertWasCalled(x => x.RollbackToSavepoint(savepoint));
        }
        public void ReleaseHeldSavepointSuccess()
        {
            ISavepointManager        saveMgr   = MockRepository.GenerateMock <ISavepointManager>();
            string                   savepoint = "savepoint";
            DefaultTransactionStatus status    = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());

            status.CreateAndHoldSavepoint(savepoint);
            Assert.IsTrue(status.HasSavepoint);
            Assert.AreEqual(savepoint, status.Savepoint);

            status.ReleaseHeldSavepoint();
            saveMgr.AssertWasCalled(x => x.CreateSavepoint(savepoint));
            saveMgr.AssertWasCalled(x => x.ReleaseSavepoint(savepoint));
        }
Exemple #5
0
        public void ReleaseHeldSavepointSuccess()
        {
            ISavepointManager        saveMgr   = A.Fake <ISavepointManager>();
            string                   savepoint = "savepoint";
            DefaultTransactionStatus status    = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());

            status.CreateAndHoldSavepoint(savepoint);
            Assert.IsTrue(status.HasSavepoint);
            Assert.AreEqual(savepoint, status.Savepoint);

            status.ReleaseHeldSavepoint();
            A.CallTo(() => saveMgr.CreateSavepoint(savepoint)).MustHaveHappened();
            A.CallTo(() => saveMgr.ReleaseSavepoint(savepoint)).MustHaveHappened();
        }
		public void RollbackHeldSavepointSuccess()
		{
			MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
			string savepoint = "savepoint";
			saveMgr.SetExpectedSavepoint( savepoint );
			saveMgr.SetSavepointToReturn( savepoint );
			DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
			status.CreateAndHoldSavepoint( savepoint );
			Assert.IsTrue( status.HasSavepoint );
			Assert.AreEqual( savepoint, status.Savepoint );

			status.RollbackToHeldSavepoint();
			saveMgr.Verify();
		}
Exemple #7
0
        public void DefaultConstructorTests()
        {
            ISmartTransactionObject txn = A.Fake <ISmartTransactionObject>();

            DefaultTransactionStatus stat = new DefaultTransactionStatus(txn, true, false, false, true, new object());

            Assert.IsNotNull(stat.Transaction);
            Assert.IsTrue(!stat.ReadOnly);
            Assert.IsTrue(!stat.NewSynchronization);
            Assert.IsNotNull(stat.SuspendedResources);
            Assert.IsTrue(stat.IsNewTransaction);
            Assert.IsTrue(!stat.RollbackOnly);
            stat.SetRollbackOnly();
            Assert.IsTrue(stat.RollbackOnly);
        }
        public void DefaultPropagationBehavior()
        {
            MockTxnDefinition def = new MockTxnDefinition();

            def.PropagationBehavior = TransactionPropagation.Required;
            def.ReadOnly            = true;
            setGeneralGetTransactionExpectations();

            DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);

            Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
            Assert.IsTrue(!status.IsNewTransaction);
            Assert.IsTrue(status.NewSynchronization);
            Assert.IsTrue(status.ReadOnly);
            Assert.IsNull(status.SuspendedResources);
        }
        public void TransactionSuspendedSuccessfully()
        {
            MockTxnDefinition def = new MockTxnDefinition();

            def.PropagationBehavior = TransactionPropagation.NotSupported;
            def.ReadOnly            = false;
            setGeneralGetTransactionExpectations();

            DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);

            Assert.IsNull(status.Transaction);
            Assert.IsTrue(!status.IsNewTransaction);
            Assert.IsTrue(status.NewSynchronization);
            Assert.IsTrue(!status.ReadOnly);
            Assert.IsNotNull(status.SuspendedResources);
        }
        public void DefaultConstructorTests()
        {
            ISmartTransactionObject txn = MockRepository.GenerateMock<ISmartTransactionObject>();

            DefaultTransactionStatus stat = new DefaultTransactionStatus(txn, true, false, false, true, new object());
            Assert.IsNotNull(stat.Transaction);
            Assert.IsTrue(!stat.ReadOnly);
            Assert.IsTrue(!stat.NewSynchronization);
            Assert.IsNotNull(stat.SuspendedResources);
            Assert.IsTrue(stat.IsNewTransaction);
            Assert.IsTrue(! stat.RollbackOnly);
            stat.SetRollbackOnly();
            Assert.IsTrue(stat.RollbackOnly);

            txn.AssertWasCalled(x => x.RollbackOnly, constraints => constraints.Repeat.Once());
        }
Exemple #11
0
        public void RollbackHeldSavepointSuccess()
        {
            MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
            string savepoint = "savepoint";

            saveMgr.SetExpectedSavepoint(savepoint);
            saveMgr.SetSavepointToReturn(savepoint);
            DefaultTransactionStatus status = new DefaultTransactionStatus(saveMgr, true, false, false, true, new object());

            status.CreateAndHoldSavepoint(savepoint);
            Assert.IsTrue(status.HasSavepoint);
            Assert.AreEqual(savepoint, status.Savepoint);

            status.RollbackToHeldSavepoint();
            saveMgr.Verify();
        }
        public void DefaultConstructorTests()
        {
            ISmartTransactionObject txn = MockRepository.GenerateMock <ISmartTransactionObject>();

            DefaultTransactionStatus stat = new DefaultTransactionStatus(txn, true, false, false, true, new object());

            Assert.IsNotNull(stat.Transaction);
            Assert.IsTrue(!stat.ReadOnly);
            Assert.IsTrue(!stat.NewSynchronization);
            Assert.IsNotNull(stat.SuspendedResources);
            Assert.IsTrue(stat.IsNewTransaction);
            Assert.IsTrue(!stat.RollbackOnly);
            stat.SetRollbackOnly();
            Assert.IsTrue(stat.RollbackOnly);

            txn.AssertWasCalled(x => x.RollbackOnly, constraints => constraints.Repeat.Once());
        }
		public void DefaultConstructorTests() 
		{
			MyMockTxnObject txn = new MyMockTxnObject();
			txn.SetExpectedIsRollBackOnlyValue( false );
			txn.SetExpectedRollbackOnlyCalls( 1 );

			DefaultTransactionStatus stat = new DefaultTransactionStatus( txn, true, false, false, true, new object() );
			Assert.IsNotNull( stat.Transaction );
			Assert.IsTrue( !stat.ReadOnly );
			Assert.IsTrue( !stat.NewSynchronization );
			Assert.IsNotNull( stat.SuspendedResources );
			Assert.IsTrue( stat.IsNewTransaction );
			Assert.IsTrue( ! stat.RollbackOnly );
			stat.SetRollbackOnly();
			Assert.IsTrue( stat.RollbackOnly );
			txn.Verify();
		}
Exemple #14
0
        public void DefaultBehaviorDefaultPropagationNoExistingTransaction()
        {
            MockTxnDefinition def = new MockTxnDefinition();

            def.PropagationBehavior = TransactionPropagation.Never;
            def.ReadOnly            = true;

            DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);

            Assert.IsNull(status.Transaction);
            Assert.IsTrue(!status.IsNewTransaction);
            Assert.IsTrue(status.NewSynchronization);
            Assert.IsTrue(status.ReadOnly);
            Assert.IsNull(status.SuspendedResources);
            Assert.AreEqual(0, _mockTxnMgr.DoBeginCallCount);

            AssertVanillaGetTransactionExpectations();
        }
Exemple #15
0
        public void TransactionCreatedSuccessfully()
        {
            MockTxnDefinition def = new MockTxnDefinition();

            def.PropagationBehavior = TransactionPropagation.RequiresNew;
            def.ReadOnly            = false;

            SetGeneralGetTransactionExpectations();

            DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);

            Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
            Assert.IsTrue(status.IsNewTransaction);
            Assert.IsTrue(status.NewSynchronization);
            Assert.IsTrue(!status.ReadOnly);
            Assert.IsNotNull(status.SuspendedResources);
            AssertVanillaGetTransactionExpectations();
        }
Exemple #16
0
        public void DefaultConstructorTests()
        {
            MyMockTxnObject txn = new MyMockTxnObject();

            txn.SetExpectedIsRollBackOnlyValue(false);
            txn.SetExpectedRollbackOnlyCalls(1);

            DefaultTransactionStatus stat = new DefaultTransactionStatus(txn, true, false, false, true, new object());

            Assert.IsNotNull(stat.Transaction);
            Assert.IsTrue(!stat.ReadOnly);
            Assert.IsTrue(!stat.NewSynchronization);
            Assert.IsNotNull(stat.SuspendedResources);
            Assert.IsTrue(stat.IsNewTransaction);
            Assert.IsTrue(!stat.RollbackOnly);
            stat.SetRollbackOnly();
            Assert.IsTrue(stat.RollbackOnly);
            txn.Verify();
        }
        public void NestedTransactionSuccessfully()
        {
            MockTxnDefinition def = new MockTxnDefinition();

            def.PropagationBehavior = TransactionPropagation.Nested;
            def.ReadOnly            = false;

            setGeneralGetTransactionExpectations();
            _mockTxnMgr.SetExpectedCalls("DoBegin", 1);
            _mockTxnMgr.Savepoints = false;
            _mockTxnMgr.NestedTransactionsAllowed = true;

            DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);

            Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
            Assert.IsTrue(status.IsNewTransaction);
            Assert.AreEqual(true, status.NewSynchronization);
            Assert.IsTrue(!status.ReadOnly);
            Assert.IsNull(status.SuspendedResources);
        }
        public void NestedTransactionWithSavepoint()
        {
            MockTxnDefinition def = new MockTxnDefinition();

            def.PropagationBehavior = TransactionPropagation.Nested;
            def.ReadOnly            = false;
            setVanillaGetTransactionExpectations();
            _mockTxnMgr.SetTransaction(new MyMockTxnObjectSavepointMgr());
            _mockTxnMgr.SetExpectedCalls("DoBegin", 0);
            _mockTxnMgr.Savepoints = true;
            _mockTxnMgr.NestedTransactionsAllowed = true;

            DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);

            Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
            Assert.IsFalse(status.IsNewTransaction);
            Assert.IsFalse(status.NewSynchronization);
            Assert.IsTrue(!status.ReadOnly);
            Assert.IsNull(status.SuspendedResources);
        }
Exemple #19
0
        public void NestedTransactionWithSavepoint()
        {
            MockTxnDefinition def = new MockTxnDefinition();

            def.PropagationBehavior = TransactionPropagation.Nested;
            def.ReadOnly            = false;
            ISavepointManager saveMgr = MockRepository.GenerateMock <ISavepointManager>();

            _mockTxnMgr.SetTransaction(saveMgr);
            _mockTxnMgr.Savepoints = true;
            _mockTxnMgr.NestedTransactionsAllowed = true;

            DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);

            Assert.AreEqual(_mockTxnMgr.Transaction, status.Transaction);
            Assert.IsFalse(status.IsNewTransaction);
            Assert.IsFalse(status.NewSynchronization);
            Assert.IsTrue(!status.ReadOnly);
            Assert.IsNull(status.SuspendedResources);

            AssertVanillaGetTransactionExpectations();
            Assert.AreEqual(0, _mockTxnMgr.DoBeginCallCount);
        }
 /// <summary>The do commit.</summary>
 /// <param name="status">The status.</param>
 protected override void DoCommit(DefaultTransactionStatus status)
 {
     this.log.Debug("Committing resourceless transaction on [" + status.Transaction + "]");
 }
 /// <summary>The do rollback.</summary>
 /// <param name="status">The status.</param>
 protected override void DoRollback(DefaultTransactionStatus status)
 {
     this.log.Debug("Rolling back resourceless transaction on [" + status.Transaction + "]");
 }
 /// <summary>The do rollback.</summary>
 /// <param name="status">The status.</param>
 protected override void DoRollback(DefaultTransactionStatus status) { }
 /// <summary>
 /// Set the given transaction rollback-only. Only called on rollback
 /// if the current transaction takes part in an existing one.
 /// </summary>
 /// <param name="status">The status representation of the transaction.</param>
 /// <remarks>Default implementation throws an IllegalTransactionStateException,
 /// assuming that participating in existing transactions is generally not
 /// supported. Subclasses are of course encouraged to provide such support.
 /// </remarks>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In the case of system errors.
 /// </exception>
 protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
 {
     MessageQueueTransactionObject txObject = (MessageQueueTransactionObject) status.Transaction;
     txObject.ResourceHolder.RollbackOnly = true;
 }
 public void ReleaseHeldSavepointException()
 {
     ISmartTransactionObject transaction = MockRepository.GenerateMock<ISmartTransactionObject>();
     DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object());
     stat.ReleaseHeldSavepoint();
 }
Exemple #25
0
        public void CreateSavepointException()
        {
            DefaultTransactionStatus stat = new DefaultTransactionStatus(new MyMockTxnObject(), true, false, false, true, new object());

            stat.CreateSavepoint("mySavePoint");
        }
        /// <summary>
        /// Perform an actual rollback on the given transaction.
        /// </summary>
        /// <param name="status">The status representation of the transaction.</param>
        /// <remarks>
        /// An implementation does not need to check the new transaction flag.
        /// </remarks>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of system errors.
        /// </exception>
        protected override void DoRollback(DefaultTransactionStatus status)
        {
            HibernateTransactionObject txObject = (HibernateTransactionObject)status.Transaction;

            if (status.Debug)
            {
                log.Debug("Rolling back Hibernate transaction on Session [" +
                    txObject.SessionHolder.Session + "]");
            }
            try
            {
                IDbTransaction adoTx = GetIDbTransaction(txObject.SessionHolder.Transaction);

                if (adoTx != null && adoTx.Connection != null)
                {
                    txObject.SessionHolder.Transaction.Rollback();
                }
            }
            catch (HibernateTransactionException ex)
            {
                throw new TransactionSystemException("Could not roll back Hibernate transaction", ex);
            }
            catch (HibernateException ex)
            {
                // Shouldn't really happen, as a rollback doesn't cause a flush.
                throw ConvertHibernateAccessException(ex);
            }
            finally
            {
                if (!txObject.NewSessionHolder)
                {
                    // Clear all pending inserts/updates/deletes in the Session.
                    // Necessary for pre-bound Sessions, to avoid inconsistent state.
                    txObject.SessionHolder.Session.Clear();
                }
            }
        }
 private void ProcessCommit(DefaultTransactionStatus status)
 {
     try
     {
         bool beforeCompletionInvoked = false;
         try
         {
             TriggerBeforeCommit(status);
             TriggerBeforeCompletion(status);
             beforeCompletionInvoked = true;
             bool globalRollbackOnly = false;
             if (status.IsNewTransaction || FailEarlyOnGlobalRollbackOnly)
             {
                 globalRollbackOnly = status.GlobalRollbackOnly;
             }
             if (status.HasSavepoint)
             {
                 status.ReleaseHeldSavepoint();
             }
             else if (status.IsNewTransaction)
             {
                 DoCommit(status);
             }
             // Throw UnexpectedRollbackException if we have a global rollback-only
             // marker but still didn't get a corresponding exception from commit.
             if (globalRollbackOnly)
             {
                 throw new UnexpectedRollbackException(
                         "Transaction silently rolled back because it has been marked as rollback-only");
             }
         }
         catch (UnexpectedRollbackException)
         {
             TriggerAfterCompletion(status, TransactionSynchronizationStatus.Rolledback);
             throw;
         }
         catch (TransactionException ex)
         {
             if (RollbackOnCommitFailure)
             {
                 DoRollbackOnCommitException(status, ex);
             }
             else
             {
                 TriggerAfterCompletion(status, TransactionSynchronizationStatus.Unknown);
             }
             throw;
         }
         catch (Exception ex)
         {
             if (!beforeCompletionInvoked)
             {
                 TriggerBeforeCompletion(status);
             }
             DoRollbackOnCommitException(status, ex);
             throw;
         }
         // Trigger AfterCommit callbacks, with an exception thrown there
         // propagated to callers but the transaction still considered as commited.
         try
         {
             TriggerAfterCommit(status);
         }
         finally
         {
             TriggerAfterCompletion(status, TransactionSynchronizationStatus.Committed);
         }
     }
     finally
     {
         CleanupAfterCompletion(status);
     }
 }
 private void TriggerAfterCommit(DefaultTransactionStatus status)
 {
     if (status.NewSynchronization)
     {
         if (status.Debug)
         {
             log.Debug("Trigger AfterCommit Synchronization");
         }
         IList synchronizations = TransactionSynchronizationManager.Synchronizations;
         foreach (ITransactionSynchronization currentTxnSynchronization in synchronizations)
         {
             try
             {
                 currentTxnSynchronization.AfterCommit();
             }
             catch (Exception e)
             {
                 log.Error("TransactionSynchronization.AfterCommit thew exception", e);
             }
         }
     }
 }
 /// <summary>
 /// Perform an actual commit on the given transaction.
 /// </summary>
 /// <param name="status">The status representation of the transaction.</param>
 /// <remarks>
 /// <p>
 /// An implementation does not need to check the rollback-only flag.
 /// </p>
 /// </remarks>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In the case of system errors.
 /// </exception>
 protected override void DoCommit(DefaultTransactionStatus status)
 {
     HibernateTransactionObject txObject = (HibernateTransactionObject)status.Transaction;
     if (status.Debug)
     {
         log.Debug("Committing Hibernate transaction on Session [" +
             txObject.SessionHolder.Session + "]");
     }
     try
     {
         txObject.SessionHolder.Transaction.Commit();
     }
     // Note, unfortunate collision of namespaces/classname for NHibernate.TransactionException
     // and Spring.Data.NHibernate requires this wierd construct.
     catch (Exception ex)
     {
         Type nhibTxExceptiontype = TypeResolutionUtils.ResolveType("NHibernate.TransactionException, NHibernate");
         if (ex.GetType().Equals(nhibTxExceptiontype))
         {
             // assumably from commit call to the underlying ADO.NET connection
             throw new TransactionSystemException("Could not commit Hibernate transaction", ex);
         }
         HibernateException hibEx = ex as HibernateException;
         if (hibEx != null)
         {
             // assumably failed to flush changes to database
             throw ConvertHibernateAccessException(hibEx);
         }
         throw;
     }
 }
 private void ProcessRollback(DefaultTransactionStatus status)
 {
     try
     {
         try
         {
             TriggerBeforeCompletion(status);
             if (status.HasSavepoint)
             {
                 if (status.Debug)
                 {
                     log.Debug("Rolling back transaction to savepoint.");
                 }
                 status.RollbackToHeldSavepoint();
             }
             else if (status.IsNewTransaction)
             {
                 if (status.Debug)
                 {
                     log.Debug("Initiating transaction rollback");
                 }
                 DoRollback(status);
             }
             else if (status.HasTransaction())
             {
                 if (status.LocalRollbackOnly)
                 {
                     if (status.Debug)
                     {
                         log.Debug("Participating transaction failed - marking existing transaction as rollback-only");
                     }
                 }
                 DoSetRollbackOnly(status);
             }
             else
             {
                 log.Debug("Should roll back transaction but cannot - no transaction available.");
             }
         }
         catch (Exception)
         {
             TriggerAfterCompletion(status, TransactionSynchronizationStatus.Unknown);
             throw;
         }
         TriggerAfterCompletion(status, TransactionSynchronizationStatus.Rolledback);
     }
     finally
     {
         CleanupAfterCompletion(status);
     }
 }
        protected override void DoRollback(DefaultTransactionStatus status)
        {
            PromotableTxScopeTransactionObject txObject =
                (PromotableTxScopeTransactionObject)status.Transaction;

            try
            {
                
                txObject.TxScopeAdapter.Dispose();
            }
            catch (Exception e)
            {
                throw new Spring.Transaction.TransactionSystemException("Failure on Transaction Scope rollback.", e);
            }
        }
 /// <summary>The do commit.</summary>
 /// <param name="status">The status.</param>
 protected override void DoCommit(DefaultTransactionStatus status) { }
 /// <summary>The do set rollback only.</summary>
 /// <param name="status">The status.</param>
 protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
 {
 }
 /// <summary>
 /// Set the given transaction rollback-only. Only called on rollback
 /// if the current transaction takes part in an existing one.
 /// </summary>
 /// <param name="status">The status representation of the transaction.</param>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In the case of system errors.
 /// </exception>
 protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
 {
     HibernateTransactionObject txObject = (HibernateTransactionObject)status.Transaction;
     if (status.Debug)
     {
         log.Debug("Setting Hibernate transaction on Session [" +
             txObject.SessionHolder.Session + "] rollback-only");
     }
     txObject.SetRollbackOnly();
 }
 public void CreateSavepointException()
 {
     ISmartTransactionObject transaction = MockRepository.GenerateMock<ISmartTransactionObject>();
     DefaultTransactionStatus stat = new DefaultTransactionStatus(transaction, true, false, false, true, new object());
     stat.CreateSavepoint("mySavePoint");
 }
 /// <summary>Do rollback.</summary>
 /// <param name="status">The status.</param>
 protected override void DoRollback(DefaultTransactionStatus status)
 {
     var transactionObject = (RabbitTransactionObject)status.Transaction;
     var resourceHolder = transactionObject.ResourceHolder;
     resourceHolder.RollbackAll();
 }
Exemple #37
0
        public void ReleaseHeldSavepointException()
        {
            DefaultTransactionStatus stat = new DefaultTransactionStatus(new MyMockTxnObject(), true, false, false, true, new object());

            stat.ReleaseHeldSavepoint();
        }
 /// <summary>Do set rollback only.</summary>
 /// <param name="status">The status.</param>
 protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
 {
     var transactionObject = (RabbitTransactionObject)status.Transaction;
     transactionObject.ResourceHolder.RollbackOnly = true;
 }
Exemple #39
0
        public void RollbackSavepointException()
        {
            DefaultTransactionStatus stat = new DefaultTransactionStatus(new MyMockTxnObject(), true, false, false, true, new object());

            stat.RollbackToSavepoint(null);
        }
 /// <summary>
 /// Perform an actual rollback on the given transaction, calls Transaction.Abort().
 /// </summary>
 /// <param name="status">The status representation of the transaction.</param>
 /// <remarks>
 /// An implementation does not need to check the new transaction flag.
 /// </remarks>
 protected override void DoRollback(DefaultTransactionStatus status)
 {
     MessageQueueTransactionObject txObject = (MessageQueueTransactionObject) status.Transaction;
     MessageQueueTransaction transaction = txObject.ResourceHolder.MessageQueueTransaction;
     try
     {
         if (LOG.IsDebugEnabled)
         {
             LOG.Debug("Committing MessageQueueTransaction");
         }
         transaction.Abort();
     }
     catch (MessageQueueException ex)
     {
         throw new TransactionSystemException("Could not roll back DefaultMessageQueue transaction", ex);
     }
 }
 /// <summary>
 /// Perform an actual commit on the given transaction.
 /// </summary>
 /// <param name="status">The status representation of the transaction.</param>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In the case of system errors.
 /// </exception>
 protected override void DoCommit(DefaultTransactionStatus status)
 {
     MessageTransactionObject txObject = (MessageTransactionObject)status.Transaction;
     ISession session = txObject.ResourceHolder.GetSession();
     try
     {
         if (status.Debug)
         {
             LOG.Debug("Committing NMS transaction on Session [" + session + "]");
         }
         session.Commit();
         //Note that NMS does not have, TransactionRolledBackException
         //See https://issues.apache.org/activemq/browse/AMQNET-93
     }
     catch (NMSException ex)
     {                
         throw new TransactionSystemException("Could not commit NMS transaction.", ex);
     }
 }
 /// <summary>
 /// Perform an actual commit on the given transaction.
 /// </summary>
 /// <param name="status">The status representation of the transaction.</param>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In the case of system errors.
 /// </exception>
 protected override void DoCommit(DefaultTransactionStatus status)
 {
     EmsTransactionObject txObject = (EmsTransactionObject)status.Transaction;
     ISession session = txObject.ResourceHolder.GetSession();
     try
     {
         if (status.Debug)
         {
             LOG.Debug("Committing EMS transaction on Session [" + session + "]");
         }
         session.Commit();
     }
     catch (TransactionRolledBackException ex)
     {
         throw new UnexpectedRollbackException("EMS transaction rolled back", ex);
     }
     catch (EMSException ex)
     {                
         throw new TransactionSystemException("Could not commit EMS transaction.", ex);
     }
 }
 protected override void DoCommit(DefaultTransactionStatus status)
 {
     PromotableTxScopeTransactionObject txObject =
         (PromotableTxScopeTransactionObject)status.Transaction;
     try
     {
         txObject.TxScopeAdapter.Complete();
         txObject.TxScopeAdapter.Dispose();
     }
     catch (TransactionAbortedException ex)
     {
         throw new UnexpectedRollbackException("Transaction unexpectedly rolled back (maybe due to a timeout)", ex);
     }
     catch (TransactionInDoubtException ex)
     {
         throw new HeuristicCompletionException(TransactionOutcomeState.Unknown, ex);
     }
     catch (Exception ex)
     {
         throw new TransactionSystemException("Failure on Transaction Scope Commit", ex);
     }
 }
 /// <summary>
 /// Perform an actual rollback on the given transaction.
 /// </summary>
 /// <param name="status">The status representation of the transaction.</param>
 /// <exception cref="Spring.Transaction.TransactionException">
 /// In the case of system errors.
 /// </exception>
 protected override void DoRollback(DefaultTransactionStatus status)
 {
     MessageTransactionObject txObject = (MessageTransactionObject)status.Transaction;
     ISession session = txObject.ResourceHolder.GetSession();
     try
     {
         if (status.Debug)
         {
             LOG.Debug("Rolling back NMS transaction on Session [" + session + "]");
         }
         session.Rollback();              
     }
     catch (NMSException ex)
     {
         throw new TransactionSystemException("Could not roll back NMS transaction.", ex);
     }
 }
 protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
 {
     if (status.Debug)
     {
         log.Debug("Setting transaction rollback-only");
     }
     try
     {
         System.Transactions.Transaction.Current.Rollback();
     } catch (Exception ex)
     {
         throw new TransactionSystemException("Failure on System.Transactions.Transaction.Current.Rollback", ex);
     }
 }
        /// <summary>
        /// Does the tx scope rollback.
        /// </summary>
        /// <param name="status">The status.</param>
        protected void DoTxScopeRollback(DefaultTransactionStatus status)
        {
            TxScopeTransactionManager.PromotableTxScopeTransactionObject txObject =
                ((HibernateTransactionObject)status.Transaction).PromotableTxScopeTransactionObject;

            try
            {

                txObject.TxScopeAdapter.Dispose();
            }
            catch (Exception e)
            {
                throw new Spring.Transaction.TransactionSystemException("Failure on Transaction Scope rollback.", e);
            }
        }