/// <summary>
        /// Suspend the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <returns>
        /// An object that holds suspended resources (will be kept unexamined for passing it into
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoResume"/>.)
        /// </returns>
        protected override object DoSuspend(object transaction)
        {
            MessageQueueTransactionObject txObject = (MessageQueueTransactionObject)transaction;

            txObject.ResourceHolder = null;
            return(TransactionSynchronizationManager.UnbindResource(CURRENT_TRANSACTION_SLOTNAME));
        }
Esempio n. 2
0
        /// <summary>Do suspend.</summary>
        /// <param name="transaction">The transaction.</param>
        /// <returns>The object.</returns>
        protected override object DoSuspend(object transaction)
        {
            var transactionObject = (RabbitTransactionObject)transaction;

            transactionObject.ResourceHolder = null;
            return(TransactionSynchronizationManager.UnbindResource(this.ConnectionFactory));
        }
Esempio n. 3
0
 private void DoClose(bool isLogDebugEnabled)
 {
     if (!IsParticipating)
     {
         if (SingleSession)
         {
             // single session mode
             if (isLogDebugEnabled)
             {
                 log.Debug("Closing single Hibernate Session in SessionScope");
             }
             LazySessionHolder holder = (LazySessionHolder)TransactionSynchronizationManager.UnbindResource(SessionFactory);
             holder.Close();
         }
         else
         {
             // deferred close mode
             if (isLogDebugEnabled)
             {
                 log.Debug("Closing all Hibernate Sessions");
             }
             SessionFactoryUtils.ProcessDeferredClose(SessionFactory);
         }
     }
     else
     {
         if (isLogDebugEnabled)
         {
             log.Debug("Only participated Hibernate Session - doing nothing");
         }
     }
 }
Esempio n. 4
0
 public void BeforeCompletion()
 {
     TransactionSynchronizationManager.UnbindResource(resourceKey);
     holderActive = false;
     //this.resourceHolder.closeAll();
     //TODO SPRNET-1244
 }
Esempio n. 5
0
        private void CleanUpAfterInvoke(RabbitResourceHolder resourceHolder, R.IModel channelToUse, bool boundHere)
        {
            if (resourceHolder != null && boundHere)
            {
                // so the channel exposed (because exposeListenerChannel is false) will be closed
                resourceHolder.SynchronizedWithTransaction = false;
            }

            ConnectionFactoryUtils.ReleaseResources(resourceHolder); // NOSONAR - null check in method
            if (boundHere)
            {
                // unbind if we bound
                TransactionSynchronizationManager.UnbindResource(ConnectionFactory);
                if (!ExposeListenerChannel && IsChannelLocallyTransacted)
                {
                    /*
                     *  commit the temporary channel we exposed; the consumer's channel
                     *  will be committed later. Note that when exposing a different channel
                     *  when there's no transaction manager, the exposed channel is committed
                     *  on each message, and not based on txSize.
                     */
                    RabbitUtils.CommitIfNecessary(channelToUse, _logger);
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Suspend this synchronization.
 /// </summary>
 /// <remarks>
 /// <p>
 /// Unbind Hibernate resources (SessionHolder) from
 /// <see cref="Spring.Transaction.Support.TransactionSynchronizationManager"/>
 /// if managing any.
 /// </p>
 /// </remarks>
 public override void Suspend()
 {
     if (this.holderActive)
     {
         TransactionSynchronizationManager.UnbindResource(this.sessionFactory);
     }
 }
 /// <summary>The suspend.</summary>
 public virtual void Suspend()
 {
     if (this.holderActive)
     {
         TransactionSynchronizationManager.UnbindResource(this.resourceKey);
     }
 }
 /// <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();
 }
 /// <summary>
 /// Suspend this synchronization.
 /// </summary>
 /// <remarks>
 /// <p>
 /// Supposed to unbind resources from
 /// <see cref="Spring.Transaction.Support.TransactionSynchronizationManager"/>
 /// if managing any.
 /// </p>
 /// </remarks>
 public void Suspend()
 {
     if (_holderActive)
     {
         TransactionSynchronizationManager.UnbindResource(_resourceKey);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Suspend the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <returns>
        /// An object that holds suspended resources (will be kept unexamined for passing it into
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoResume"/>.)
        /// </returns>
        /// <remarks>
        /// Transaction synchronization will already have been suspended.
        /// </remarks>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// in case of system errors.
        /// </exception>
        protected override object DoSuspend(object transaction)
        {
            EmsTransactionObject txObject = (EmsTransactionObject)transaction;

            txObject.ResourceHolder = null;
            return(TransactionSynchronizationManager.UnbindResource(ConnectionFactory));
        }
        public void TestTemplateUsesPublisherConnectionUnlessInTx()
        {
            connectionFactory.Destroy();
            template.UsePublisherConnection = true;
            template.ConvertAndSend("dummy", "foo");
            Assert.Null(connectionFactory._connection.Target);
            Assert.NotNull(((CachingConnectionFactory)connectionFactory.PublisherConnectionFactory)._connection.Target);
            connectionFactory.Destroy();
            Assert.Null(connectionFactory._connection.Target);
            Assert.Null(((CachingConnectionFactory)connectionFactory.PublisherConnectionFactory)._connection.Target);
            var channel = connectionFactory.CreateConnection().CreateChannel(true);

            Assert.NotNull(connectionFactory._connection.Target);
            var holder = new RabbitResourceHolder(channel, true);

            TransactionSynchronizationManager.BindResource(connectionFactory, holder);
            try
            {
                template.IsChannelTransacted = true;
                template.ConvertAndSend("dummy", "foo");
                Assert.NotNull(connectionFactory._connection.Target);
                Assert.Null(((CachingConnectionFactory)connectionFactory.PublisherConnectionFactory)._connection.Target);
            }
            finally
            {
                TransactionSynchronizationManager.UnbindResource(connectionFactory);
                channel.Close();
            }
        }
Esempio n. 12
0
 public override void Suspend()
 {
     if (holderActive)
     {
         TransactionSynchronizationManager.UnbindResource(resourceKey);
     }
 }
        /// <summary>
        /// Cleanup resources after transaction completion.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <remarks>
        /// <para>
        /// Called after <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoCommit"/>
        /// and
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoRollback"/>
        /// execution on any outcome.
        /// </para>
        /// </remarks>
        protected override void DoCleanupAfterCompletion(object transaction)
        {
            MessageQueueTransactionObject txObject = (MessageQueueTransactionObject)transaction;

            TransactionSynchronizationManager.UnbindResource(CURRENT_TRANSACTION_SLOTNAME);
            txObject.ResourceHolder.Clear();
        }
Esempio n. 14
0
        /// <summary>
        /// Cleanup resources after transaction completion.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <remarks>
        /// <para>
        /// Called after <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoCommit"/>
        /// and
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoRollback"/>
        /// execution on any outcome.
        /// </para>
        /// </remarks>
        protected override void DoCleanupAfterCompletion(object transaction)
        {
            EmsTransactionObject txObject = (EmsTransactionObject)transaction;

            TransactionSynchronizationManager.UnbindResource(ConnectionFactory);
            txObject.ResourceHolder.CloseAll();
            txObject.ResourceHolder.Clear();
        }
Esempio n. 15
0
        /// <summary>
        /// Suspend this synchronization.
        /// </summary>
        /// <remarks>
        ///     <p>
        /// Supposed to unbind resources from
        /// <see cref="Spring.Transaction.Support.TransactionSynchronizationManager"/>
        /// if managing any.
        /// </p>
        /// </remarks>
        public override void Suspend()
        {
            if (holderActive)
            {
                TransactionSynchronizationManager.UnbindResource(dbProvider);

                //TODO do we need to reset the connection inside the conHolder to null?
            }
        }
        /// <summary>
        /// Suspend the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <returns>
        /// An object that holds suspended resources (will be kept unexamined for passing it into
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoResume"/>.)
        /// </returns>
        /// <remarks>
        /// Transaction synchronization will already have been suspended.
        /// </remarks>
        /// <exception cref="Spring.Transaction.IllegalTransactionStateException">
        /// If suspending is not supported by the transaction manager implementation.
        /// </exception>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// in case of system errors.
        /// </exception>
        protected override object DoSuspend(object transaction)
        {
            DbProviderTransactionObject txMgrStateObject = (DbProviderTransactionObject)transaction;

            txMgrStateObject.ConnectionHolder = null;
            ConnectionHolder conHolder = (ConnectionHolder)TransactionSynchronizationManager.UnbindResource(DbProvider);

            return(conHolder);
        }
Esempio n. 17
0
        /// <summary>The do cleanup after completion.</summary>
        /// <param name="transaction">The transaction.</param>
        protected override void DoCleanupAfterCompletion(object transaction)
        {
            var list      = (Stack <object>)TransactionSynchronizationManager.GetResource(this);
            var resources = list;

            resources.Clear();
            TransactionSynchronizationManager.UnbindResource(this);
            ((ResourcelessTransaction)transaction).Clear();
        }
Esempio n. 18
0
 public override void BeforeCompletion()
 {
     TransactionSynchronizationManager.UnbindResource(resourceKey);
     holderActive = false;
     if (!transacted)
     {
         resourceHolder.CloseAll();
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Invoked before transaction commit/rollback (after
 /// <see cref="Spring.Transaction.Support.ITransactionSynchronization.BeforeCommit"/>,
 /// even if
 /// <see cref="Spring.Transaction.Support.ITransactionSynchronization.BeforeCommit"/>
 /// threw an exception).
 /// </summary>
 /// <remarks>
 ///     <p>
 /// Can e.g. perform resource cleanup.
 /// </p>
 ///     <p>
 /// Note that exceptions will get propagated to the commit caller
 /// and cause a rollback of the transaction.
 /// </p>
 /// </remarks>
 public override void BeforeCompletion()
 {
     if (connectionHolder.IsOpen)
     {
         TransactionSynchronizationManager.UnbindResource(dbProvider);
         holderActive = false;
         ConnectionUtils.DisposeConnection(connectionHolder.Connection, dbProvider);
     }
 }
Esempio n. 20
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);
     }
 }
 /// <summary>
 /// Invoked before transaction commit/rollback (after
 /// <see cref="Spring.Transaction.Support.ITransactionSynchronization.BeforeCommit"/>,
 /// even if
 /// <see cref="Spring.Transaction.Support.ITransactionSynchronization.BeforeCommit"/>
 /// threw an exception).
 /// </summary>
 /// <remarks>
 /// <p>
 /// Can e.g. perform resource cleanup.
 /// </p>
 /// <p>
 /// Note that exceptions will get propagated to the commit caller
 /// and cause a rollback of the transaction.
 /// </p>
 /// </remarks>
 public void BeforeCompletion()
 {
     if (ShouldUnbindAtCompletion())
     {
         TransactionSynchronizationManager.UnbindResource(_resourceKey);
         _holderActive = false;
         if (ShouldReleaseBeforeCompletion())
         {
             ReleaseResource(_resourceHolder, _resourceKey);
         }
     }
 }
 /// <summary>The before completion.</summary>
 public virtual void BeforeCompletion()
 {
     if (this.ShouldUnbindAtCompletion())
     {
         TransactionSynchronizationManager.UnbindResource(this.resourceKey);
         this.holderActive = false;
         if (this.ShouldReleaseBeforeCompletion())
         {
             this.ReleaseResource(this.resourceHolder, this.resourceKey);
         }
     }
 }
        /// <summary>
        /// Cleanup resources after transaction completion.
        /// </summary>
        /// <param name="transaction">Transaction object returned by
        /// <see cref="M:Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.</param>
        /// <remarks>
        /// <note>
        /// This implemenation unbinds the SessionFactory and
        /// DbProvider from thread local storage and closes the
        /// ISession.
        /// </note>
        ///     <p>
        /// Called after <see cref="M:Spring.Transaction.Support.AbstractPlatformTransactionManager.DoCommit(Spring.Transaction.Support.DefaultTransactionStatus)"/>
        /// and
        /// <see cref="M:Spring.Transaction.Support.AbstractPlatformTransactionManager.DoRollback(Spring.Transaction.Support.DefaultTransactionStatus)"/>
        /// execution on any outcome.
        /// </p>
        ///     <p>
        /// Should not throw any exceptions but just issue warnings on errors.
        /// </p>
        /// </remarks>
        protected override void DoCleanupAfterCompletion(object transaction)
        {
            HibernateTransactionObject txObject = (HibernateTransactionObject)transaction;

            // Remove the session holder from the thread.
            if (txObject.NewSessionHolder)
            {
                TransactionSynchronizationManager.UnbindResource(SessionFactory);
            }
            // Remove the ADO.NET connection holder from the thread, if exposed.
            if (DbProvider != null)
            {
                TransactionSynchronizationManager.UnbindResource(DbProvider);
            }

            /*
             * try
             * {
             *  //TODO investigate isolation level settings...
             *  //IDbConnection con = txObject.SessionHolder.Session.Connection;
             *  //AdoUtils.ResetConnectionAfterTransaction(con, txObject.PreviousIsolationLevel);
             * }
             * catch (HibernateException ex)
             * {
             *  log.Info("Could not access ADO.NET IDbConnection of Hibernate Session", ex);
             * }
             */
            ISession session = txObject.SessionHolder.Session;

            if (txObject.NewSessionHolder)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Closing Hibernate Session [" + session + "] after transaction");
                }

                SessionFactoryUtils.CloseSessionOrRegisterDeferredClose(session, SessionFactory);
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Not closing pre-bound Hibernate Session [" + session + "] after transaction");
                }
                if (txObject.SessionHolder.AssignedPreviousFlushMode)
                {
                    session.FlushMode = txObject.SessionHolder.PreviousFlushMode;
                }
            }

            txObject.SessionHolder.Clear();
        }
        /// <summary>
        /// Resume the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">
        /// Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.
        /// </param>
        /// <param name="suspendedResources">
        /// The object that holds suspended resources as returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoSuspend"/>.
        /// </param>
        /// <remarks>
        /// Transaction synchronization will be resumed afterwards.
        /// </remarks>
        /// <exception cref="Spring.Transaction.IllegalTransactionStateException">
        /// If suspending is not supported by the transaction manager implementation.
        /// </exception>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of system errors.
        /// </exception>
        protected override void DoResume(Object transaction, Object suspendedResources)
        {
            logger.Debug("Do Resume");
            SuspendedResourcesHolder resourcesHolder = (SuspendedResourcesHolder)suspendedResources;
            Db4oTransactionObject    txObject        = (Db4oTransactionObject)transaction;

            txObject.ObjectContainerHolder = resourcesHolder.ObjectContainerHolder;
            if (TransactionSynchronizationManager.HasResource(_DataSource))
            {
                TransactionSynchronizationManager.UnbindResource(_DataSource);
            }
            TransactionSynchronizationManager.BindResource(_DataSource,
                                                           resourcesHolder.ObjectContainerHolder);
        }
Esempio n. 25
0
 /// <summary>
 /// Suspend this synchronization.
 /// </summary>
 /// <remarks>
 /// <p>
 /// Supposed to unbind resources from
 /// <see cref="Spring.Transaction.Support.TransactionSynchronizationManager"/>
 /// if managing any.
 /// </p>
 /// </remarks>
 public override void Suspend()
 {
     base.Suspend();
     logger.Debug("Suspend");
     if (this.HolderActive)
     {
         TransactionSynchronizationManager.UnbindResource(_DataSource);
         if (_Holder.ObjectContainer != null)
         {
             //DisposeConnection(_Holder.ObjectContainer, _DataSource);
             //_Holder.ObjectContainer = null;
         }
     }
 }
Esempio n. 26
0
 /// <summary>
 /// Invoked before transaction commit (before
 /// <see cref="Spring.Transaction.Support.ITransactionSynchronization.BeforeCompletion"/>)
 /// Can e.g. flush transactional O/R Mapping sessions to the database
 /// </summary>
 /// <remarks>
 /// <para>
 /// This callback does not mean that the transaction will actually be
 /// commited.  A rollback decision can still occur after this method
 /// has been called.  This callback is rather meant to perform work
 /// that's only relevant if a commit still has a chance
 /// to happen, such as flushing SQL statements to the database.
 /// </para>
 /// <para>
 /// Note that exceptions will get propagated to the commit caller and cause a
 /// rollback of the transaction.</para>
 /// <para>
 /// (note: do not throw TransactionException subclasses here!)
 /// </para>
 /// </remarks>
 public override void BeforeCompletion()
 {
     if (this.newSession)
     {
         // Default behavior: unbind and close the thread-bound Hibernate Session.
         TransactionSynchronizationManager.UnbindResource(this.sessionFactory);
         this.holderActive = false;
     }
     else if (this.sessionHolder.AssignedPreviousFlushMode == true)
     {
         // In case of pre-bound Session, restore previous flush mode.
         this.sessionHolder.Session.FlushMode = (this.sessionHolder.PreviousFlushMode);
     }
 }
        /// <summary>
        /// Suspend the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">
        /// Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.
        /// </param>
        /// <returns>
        /// An object that holds suspended resources (will be kept unexamined for passing it into
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoResume"/>.)
        /// </returns>
        /// <remarks>
        /// Transaction synchronization will already have been suspended.
        /// </remarks>
        /// <exception cref="Spring.Transaction.IllegalTransactionStateException">
        /// If suspending is not supported by the transaction manager implementation.
        /// </exception>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// in case of system errors.
        /// </exception>
        protected override object DoSuspend(object transaction)
        {
            HibernateTransactionObject txObject = (HibernateTransactionObject)transaction;

            txObject.SetSessionHolder(null, false);
            SessionHolder sessionHolder =
                (SessionHolder)TransactionSynchronizationManager.UnbindResource(SessionFactory);
            ConnectionHolder connectionHolder = null;

            if (DbProvider != null)
            {
                connectionHolder = (ConnectionHolder)TransactionSynchronizationManager.UnbindResource(DbProvider);
            }
            return(new SuspendedResourcesHolder(sessionHolder, connectionHolder));
        }
 private void UnbindResourceIfPossible(object key)
 {
     // This is required because SPRNET TX support hasn't caught up with the Java equivalent.
     try
     {
         TransactionSynchronizationManager.UnbindResource(key);
     }
     catch (InvalidOperationException ex)
     {
         if (!ex.Message.StartsWith("No value for key ["))
         {
             throw;
         }
     }
 }
        public void TearDown()
        {
            var keys = new object[TransactionSynchronizationManager.ResourceDictionary.Keys.Count];

            TransactionSynchronizationManager.ResourceDictionary.Keys.CopyTo(keys, 0);
            foreach (var key in keys)
            {
                TransactionSynchronizationManager.UnbindResource(key);
            }

            TransactionSynchronizationManager.ClearSynchronization();

            _mongo.ClearReceivedCalls();
            _mongo = null;
            MongoTestHelper.ClearCache();
        }
        /// <summary>
        /// Resume the resources of the current transaction.
        /// </summary>
        /// <param name="transaction">
        /// Transaction object returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoGetTransaction"/>.
        /// </param>
        /// <param name="suspendedResources">
        /// The object that holds suspended resources as returned by
        /// <see cref="Spring.Transaction.Support.AbstractPlatformTransactionManager.DoSuspend"/>.
        /// </param>
        /// <remarks>
        /// Transaction synchronization will be resumed afterwards.
        /// </remarks>
        /// <exception cref="Spring.Transaction.IllegalTransactionStateException">
        /// If suspending is not supported by the transaction manager implementation.
        /// </exception>
        /// <exception cref="Spring.Transaction.TransactionException">
        /// In the case of system errors.
        /// </exception>
        protected override void DoResume(object transaction, object suspendedResources)
        {
            SuspendedResourcesHolder resourcesHolder = (SuspendedResourcesHolder)suspendedResources;

            if (TransactionSynchronizationManager.HasResource(SessionFactory))
            {
                // From non-transactional code running in active transaction synchronization
                // -> can be safely removed, will be closed on transaction completion.
                TransactionSynchronizationManager.UnbindResource(SessionFactory);
            }
            TransactionSynchronizationManager.BindResource(SessionFactory, resourcesHolder.SessionHolder);
            if (DbProvider != null)
            {
                TransactionSynchronizationManager.BindResource(DbProvider, resourcesHolder.ConnectionHolder);
            }
        }