/// <summary>
 /// Invoked after transaction commit/rollback.
 /// </summary>
 /// <param name="status">
 /// Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/>
 /// </param>
 /// <remarks>
 /// Can e.g. perform resource cleanup, in this case after transaction completion.
 /// <p>
 /// Note that exceptions will get propagated to the commit or rollback
 /// caller, although they will not influence the outcome of the transaction.
 /// </p>
 /// </remarks>
 public void AfterCompletion(TransactionSynchronizationStatus status)
 {
     if (ShouldUnbindAtCompletion())
     {
         bool releaseNecessary;
         if (_holderActive)
         {
             // The thread-bound resource holder might not be available anymore,
             // since afterCompletion might get called from a different thread.
             _holderActive = false;
             TransactionSynchronizationManager.UnbindResource(_resourceKey);
             _resourceHolder.Unbound();
             releaseNecessary = true;
         }
         else
         {
             releaseNecessary = ShouldReleaseAfterCompletion(_resourceHolder);
         }
         if (releaseNecessary)
         {
             ReleaseResource(_resourceHolder, _resourceKey);
         }
     }
     else
     {
         // Probably a pre-bound resource...
         CleanupResource(_resourceHolder, _resourceKey, (status == TransactionSynchronizationStatus.Committed));
     }
     _resourceHolder.Reset();
 }
Пример #2
0
 public override void AfterCompletion(TransactionSynchronizationStatus status)
 {
     if (transacted)
     {
         resourceHolder.CloseAll();
     }
 }
Пример #3
0
        /// <summary>
        /// Invoked after transaction commit/rollback.
        /// </summary>
        /// <param name="status">
        /// Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/>
        /// </param>
        /// <remarks>
        /// Can e.g. perform resource cleanup, in this case after transaction completion.
        /// <p>
        /// Note that exceptions will get propagated to the commit or rollback
        /// caller, although they will not influence the outcome of the transaction.
        /// </p>
        /// </remarks>
        public override void AfterCompletion(TransactionSynchronizationStatus status)
        {
            if (!newSession)
            {
                ISession session = sessionHolder.Session;

                // Provide correct transaction status for releasing the Session's cache locks,
                // if possible. Else, closing will release all cache locks assuming a rollback.
                ISessionImplementor sessionImplementor = session as ISessionImplementor;
                if (sessionImplementor != null)
                {
                    sessionImplementor.AfterTransactionCompletion(status == TransactionSynchronizationStatus.Committed, sessionHolder.Transaction);
                }

                if (newSession)
                {
                    SessionFactoryUtils.CloseSessionOrRegisterDeferredClose(session, sessionFactory);
                }
            }
            if (!newSession && status != TransactionSynchronizationStatus.Committed)
            {
                // Clear all pending inserts/updates/deletes in the Session.
                // Necessary for pre-bound Sessions, to avoid inconsistent state.
                sessionHolder.Session.Clear();
            }

            if (this.sessionHolder.DoesNotHoldNonDefaultSession)
            {
                sessionHolder.SynchronizedWithTransaction = false;
            }
        }
        /// <summary>The after completion.</summary>
        /// <param name="status">The status.</param>
        public virtual void AfterCompletion(TransactionSynchronizationStatus status)
        {
            if (this.ShouldUnbindAtCompletion())
            {
                var releaseNecessary = false;
                if (this.holderActive)
                {
                    // The thread-bound resource holder might not be available anymore,
                    // since afterCompletion might get called from a different thread.
                    this.holderActive = false;

                    // TransactionSynchronizationManager.UnbindResourceIfPossible(this.resourceKey);
                    this.UnbindResourceIfPossible(this.resourceKey);
                    this.resourceHolder.Unbound();
                    releaseNecessary = true;
                }
                else
                {
                    releaseNecessary = this.ShouldReleaseAfterCompletion(this.resourceHolder);
                }

                if (releaseNecessary)
                {
                    this.ReleaseResource(this.resourceHolder, this.resourceKey);
                }
            }
            else
            {
                // Probably a pre-bound resource...
                this.CleanupResource(this.resourceHolder, this.resourceKey, status == TransactionSynchronizationStatus.Committed);
            }

            this.resourceHolder.Reset();
        }
Пример #5
0
 /// <summary>
 /// Invoked after transaction commit/rollback.
 /// </summary>
 /// <param name="status">Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/></param>
 /// <remarks>
 /// Can e.g. perform resource cleanup, in this case after transaction completion.
 /// <p>
 /// Note that exceptions will get propagated to the commit or rollback
 /// caller, although they will not influence the outcome of the transaction.
 /// </p>
 /// </remarks>
 public override void AfterCompletion(TransactionSynchronizationStatus status)
 {
     if (TransactionSynchronizationManager.HasResource(dbProvider))
     {
         TransactionSynchronizationManager.UnbindResource(dbProvider);
         holderActive = false;
         ConnectionUtils.DisposeConnection(connectionHolder.Connection, dbProvider);
     }
 }
Пример #6
0
        /// <summary>Actions to be done after completion.</summary>
        /// <param name="status">The status.</param>
        public override void AfterCompletion(TransactionSynchronizationStatus status)
        {
            if (status != (int)TransactionSynchronizationStatus.Committed)
            {
                this.resourceHolder.RollbackAll();
            }

            if (this.resourceHolder.ReleaseAfterCompletion)
            {
                this.resourceHolder.SynchronizedWithTransaction = false;
            }

            base.AfterCompletion(status);
        }
Пример #7
0
 /// <summary>
 /// Invoked after transaction commit/rollback.
 /// </summary>
 /// <param name="status">
 /// Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/>
 /// </param>
 /// <remarks>
 /// Can e.g. perform resource cleanup, in this case after transaction completion.
 /// <p>
 /// Note that exceptions will get propagated to the commit or rollback
 /// caller, although they will not influence the outcome of the transaction.
 /// </p>
 /// </remarks>
 public override void AfterCompletion(TransactionSynchronizationStatus status)
 {
     base.AfterCompletion(status);
     logger.Debug("After Completion");
     // if not closed BeforeCompletion, do it now
     // (and if it hasn't been done by someone else)
     if (TransactionSynchronizationManager.HasResource(_DataSource))
     {
         TransactionSynchronizationManager.UnbindResource(_DataSource);
         _HolderActive = false;
         if (_Holder.ObjectContainer != null)
         {
             DisposeConnection(_Holder.ObjectContainer, _DataSource);
         }
     }
 }
 public void AfterCompletion(TransactionSynchronizationStatus syncStatus)
 {
     Assert.IsFalse(afterCompletionCalled);
     afterCompletionCalled = true;
     Assert.IsTrue(syncStatus == status);
     Assert.IsTrue(TransactionSynchronizationManager.HasResource(provider));
 }
 public TestTransactionSynchronization(IDbProvider provider,
     TransactionSynchronizationStatus synchronizationStatus)
 {
     this.provider = provider;
     status = synchronizationStatus;
 }
 private void InvokeAfterCompletion(IList synchronizations, TransactionSynchronizationStatus status)
 {
     foreach (ITransactionSynchronization synchronization in synchronizations)
     {
         try
         {
             synchronization.AfterCompletion(status);
         }
         catch (Exception e)
         {
             log.Error("TransactionSynchronization.AfterCompletion threw exception", e);
         }
     }
 }
 /// <summary>
 /// Trigger afterCompletion callback, handling exceptions properly.
 /// </summary>
 /// <param name="status">object representing the transaction</param>
 /// <param name="completionStatus">
 /// Completion status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/>
 /// </param>
 private void TriggerAfterCompletion(DefaultTransactionStatus status, TransactionSynchronizationStatus completionStatus)
 {
     if (status.NewSynchronization)
     {
         IList synchronizations = TransactionSynchronizationManager.Synchronizations;
         if (!status.HasTransaction() || status.IsNewTransaction)
         {
             if (status.Debug)
             {
                 log.Debug("Triggering afterCompletion synchronization");
             }
             InvokeAfterCompletion(synchronizations, completionStatus);
         }
         else
         {
             //TODO investigate parallel of JTA/System.Txs
             log.Info("Transaction controlled outside of spring tx manager.");
             RegisterAfterCompletionWithExistingTransaction(status.Transaction, synchronizations);
         }
     }
 }
        /**
         * Actually invoke the <code>afterCompletion</code> methods of the
         * given Spring TransactionSynchronization objects.
         * @param synchronizations List of TransactionSynchronization objects
         * @param completionStatus the completion status according to the
         * constants in the TransactionSynchronization interface
         * @see TransactionSynchronization#afterCompletion(int)
         * @see TransactionSynchronization#STATUS_COMMITTED
         * @see TransactionSynchronization#STATUS_ROLLED_BACK
         * @see TransactionSynchronization#STATUS_UNKNOWN
         */

        /// <summary>The invoke after completion.</summary>
        /// <param name="synchronizations">The synchronizations.</param>
        /// <param name="completionStatus">The completion status.</param>
        public static void InvokeAfterCompletion(IList<ITransactionSynchronization> synchronizations, TransactionSynchronizationStatus completionStatus)
        {
            if (synchronizations != null)
            {
                foreach (var synchronization in synchronizations)
                {
                    try
                    {
                        synchronization.AfterCompletion(completionStatus);
                    }
                    catch (Exception tsex)
                    {
                        Logger.Error("TransactionSynchronization.afterCompletion threw exception", tsex);
                    }
                }
            }
        }
        /**
         * Actually invoke the <code>afterCompletion</code> methods of the
         * given Spring TransactionSynchronization objects.
         * @param synchronizations List of TransactionSynchronization objects
         * @param completionStatus the completion status according to the
         * constants in the TransactionSynchronization interface
         * @see TransactionSynchronization#afterCompletion(int)
         * @see TransactionSynchronization#STATUS_COMMITTED
         * @see TransactionSynchronization#STATUS_ROLLED_BACK
         * @see TransactionSynchronization#STATUS_UNKNOWN
         */

        /// <summary>The invoke after completion.</summary>
        /// <param name="synchronizations">The synchronizations.</param>
        /// <param name="completionStatus">The completion status.</param>
        public static void InvokeAfterCompletion(IList <ITransactionSynchronization> synchronizations, TransactionSynchronizationStatus completionStatus)
        {
            if (synchronizations != null)
            {
                foreach (var synchronization in synchronizations)
                {
                    try
                    {
                        synchronization.AfterCompletion(completionStatus);
                    }
                    catch (Exception tsex)
                    {
                        Logger.Error("TransactionSynchronization.afterCompletion threw exception", tsex);
                    }
                }
            }
        }
		/// <summary>
		/// Invoked after transaction commit/rollback.
		/// </summary>
		/// <param name="status">
		/// Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/>
		/// </param>
		/// <remarks>
		/// Can e.g. perform resource cleanup, in this case after transaction completion.
		/// <p>
		/// Note that exceptions will get propagated to the commit or rollback
		/// caller, although they will not influence the outcome of the transaction.
		/// </p>
		/// </remarks>
		public virtual void AfterCompletion( TransactionSynchronizationStatus status ) {}
 /// <summary>
 /// Invoked after transaction commit/rollback.
 /// </summary>
 /// <param name="status">Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/></param>
 /// <remarks>
 /// Can e.g. perform resource cleanup, in this case after transaction completion.
 /// <p>
 /// Note that exceptions will get propagated to the commit or rollback
 /// caller, although they will not influence the outcome of the transaction.
 /// </p>
 /// </remarks>
 public override void AfterCompletion(TransactionSynchronizationStatus status)
 {
     if (TransactionSynchronizationManager.HasResource(dbProvider))
     {
         TransactionSynchronizationManager.UnbindResource(dbProvider);
         holderActive = false;
         ConnectionUtils.DisposeConnection(connectionHolder.Connection, dbProvider);   
     }
 }
 /// <summary>
 /// Invoked after transaction commit/rollback.
 /// </summary>
 /// <param name="status">
 /// Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/>
 /// </param>
 /// <remarks>
 /// Can e.g. perform resource cleanup, in this case after transaction completion.
 /// <p>
 /// Note that exceptions will get propagated to the commit or rollback
 /// caller, although they will not influence the outcome of the transaction.
 /// </p>
 /// </remarks>
 public virtual void AfterCompletion(TransactionSynchronizationStatus status)
 {
 }
Пример #17
0
 public void AfterCompletion(TransactionSynchronizationStatus status)
 {
     //TODO SPRNET-1244
 }
Пример #18
0
 public override void AfterCompletion(TransactionSynchronizationStatus status)
 {
     if (transacted)
     {
         resourceHolder.CloseAll();
     }
 }
	    /// <summary>
	    /// Invoked after transaction commit/rollback.
	    /// </summary>
	    /// <param name="status">
	    /// Status according to <see cref="Spring.Transaction.Support.TransactionSynchronizationStatus"/>
	    /// </param>
	    /// <remarks>
	    /// Can e.g. perform resource cleanup, in this case after transaction completion.
	    /// <p>
	    /// Note that exceptions will get propagated to the commit or rollback
	    /// caller, although they will not influence the outcome of the transaction.
	    /// </p>
	    /// </remarks>
	    public override void AfterCompletion(TransactionSynchronizationStatus status)
	    {
	        if (!newSession)
	        {
                ISession session = sessionHolder.Session;
                
                // Provide correct transaction status for releasing the Session's cache locks,
                // if possible. Else, closing will release all cache locks assuming a rollback.
                ISessionImplementor sessionImplementor = session as ISessionImplementor;
	            if (sessionImplementor != null)
	            {
                    sessionImplementor.AfterTransactionCompletion(status == TransactionSynchronizationStatus.Committed, sessionHolder.Transaction);
	            }

                if (newSession)
                {
                    SessionFactoryUtils.CloseSessionOrRegisterDeferredClose(session, sessionFactory);
                }	            	            
	        }
            if (!newSession && status != TransactionSynchronizationStatus.Committed)
            {
                // Clear all pending inserts/updates/deletes in the Session.
                // Necessary for pre-bound Sessions, to avoid inconsistent state.
                sessionHolder.Session.Clear();
            }
      		
	        if (this.sessionHolder.DoesNotHoldNonDefaultSession) {
			  sessionHolder.SynchronizedWithTransaction = false;
		    }

        }
        /**
         * Trigger <code>afterCompletion</code> callbacks on all currently registered synchronizations.
         * @see TransactionSynchronizationManager#getSynchronizations()
         * @param completionStatus the completion status according to the
         * constants in the TransactionSynchronization interface
         * @see TransactionSynchronization#afterCompletion(int)
         * @see TransactionSynchronization#STATUS_COMMITTED
         * @see TransactionSynchronization#STATUS_ROLLED_BACK
         * @see TransactionSynchronization#STATUS_UNKNOWN
         */

        /// <summary>The trigger after completion.</summary>
        /// <param name="completionStatus">The completion status.</param>
        public static void TriggerAfterCompletion(TransactionSynchronizationStatus completionStatus)
        {
            var synchronizations = TransactionSynchronizationManager.Synchronizations.ToGenericList <ITransactionSynchronization>();

            InvokeAfterCompletion(synchronizations, completionStatus);
        }
 public void AfterCompletion(TransactionSynchronizationStatus status)
 {
     sync.AfterCompletion(true);
 }
        /**
         * Trigger <code>afterCompletion</code> callbacks.
         * @param status object representing the transaction
         * @param completionStatus completion status according to TransactionSynchronization constants
         */
        private void TriggerAfterCompletion(DefaultTransactionStatus status, TransactionSynchronizationStatus completionStatus)
        {
            if (status.NewSynchronization)
            {
                var synchronizations = TransactionSynchronizationManager.Synchronizations.ToGenericList<ITransactionSynchronization>();
                if (synchronizations != null)
                {
                    if (!status.HasTransaction() || status.NewSynchronization)
                    {
                        if (status.Debug)
                        {
                            Logger.Trace("Triggering afterCompletion synchronization");
                        }

                        // No transaction or new transaction for the current scope ->
                        // invoke the afterCompletion callbacks immediately
                        this.InvokeAfterCompletion(synchronizations, completionStatus);
                    }
                    else if (!(synchronizations.Count < 1))
                    {
                        // Existing transaction that we participate in, controlled outside
                        // of the scope of this Spring transaction manager -> try to register
                        // an afterCompletion callback with the existing (JTA) transaction.
                        this.RegisterAfterCompletionWithExistingTransaction(status.Transaction, synchronizations);
                    }
                }
            }
        }
        /**
         * Trigger <code>afterCompletion</code> callbacks on all currently registered synchronizations.
         * @see TransactionSynchronizationManager#getSynchronizations()
         * @param completionStatus the completion status according to the
         * constants in the TransactionSynchronization interface
         * @see TransactionSynchronization#afterCompletion(int)
         * @see TransactionSynchronization#STATUS_COMMITTED
         * @see TransactionSynchronization#STATUS_ROLLED_BACK
         * @see TransactionSynchronization#STATUS_UNKNOWN
         */

        /// <summary>The trigger after completion.</summary>
        /// <param name="completionStatus">The completion status.</param>
        public static void TriggerAfterCompletion(TransactionSynchronizationStatus completionStatus)
        {
            var synchronizations = TransactionSynchronizationManager.Synchronizations.ToGenericList<ITransactionSynchronization>();
            InvokeAfterCompletion(synchronizations, completionStatus);
        }
        /**
	 * Actually invoke the <code>afterCompletion</code> methods of the
	 * given Spring TransactionSynchronization objects.
	 * <p>To be called by this abstract manager itself, or by special implementations
	 * of the <code>registerAfterCompletionWithExistingTransaction</code> callback.
	 * @param synchronizations List of TransactionSynchronization objects
	 * @param completionStatus the completion status according to the
	 * constants in the TransactionSynchronization interface
	 * @see #registerAfterCompletionWithExistingTransaction(Object, java.util.List)
	 * @see TransactionSynchronization#STATUS_COMMITTED
	 * @see TransactionSynchronization#STATUS_ROLLED_BACK
	 * @see TransactionSynchronization#STATUS_UNKNOWN
	 */

        /// <summary>The invoke after completion.</summary>
        /// <param name="synchronizations">The synchronizations.</param>
        /// <param name="completionStatus">The completion status.</param>
        protected void InvokeAfterCompletion(IList<ITransactionSynchronization> synchronizations, TransactionSynchronizationStatus completionStatus) { TransactionSynchronizationUtils.InvokeAfterCompletion(synchronizations, completionStatus); }
 public void AfterCompletion(TransactionSynchronizationStatus status)
 {
     sync.AfterCompletion(true);
 }
Пример #26
0
 public void AfterCompletion(TransactionSynchronizationStatus status)
 {
     //TODO SPRNET-1244
 }