Exemplo n.º 1
0
 protected void ReplaceSessionAfterError()
 {
     if (session != null)
     {
         session.Dispose();
         session = sessionFactory.OpenSession();
         ReplaceEntitiesLoadedByFaultedSession();
     }
     if (statelessSession != null)
     {
         statelessSession.Dispose();
         statelessSession = sessionFactory.OpenStatelessSession();
     }
 }
Exemplo n.º 2
0
 public void Dispose()
 {
     if (_session != null)
     {
         _session.Dispose();
     }
 }
        public void NewTransactionBeforeUsingStatelessSession()
        {
            ISessionManager manager = container.Resolve <ISessionManager>();

            ITransactionManager tmanager = container.Resolve <ITransactionManager>();

            ITransaction transaction = tmanager.CreateTransaction(
                TransactionMode.Requires,
                IsolationMode.Serializable);

            transaction.Begin();

            IStatelessSession session = manager.OpenStatelessSession();

            Assert.IsNotNull(session);
            Assert.IsNotNull(session.Transaction);

            transaction.Commit();

            // TODO: Assert transaction was committed
            // Assert.IsTrue(session.Transaction.WasCommitted);
            // Assert.IsTrue(session.IsConnected);

            session.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
Exemplo n.º 4
0
 /// <summary>
 ///     资源释放
 /// </summary>
 public void Dispose()
 {
     _currentSession?.Dispose();
     _currentStatelessSession?.Dispose();
     _currentSession          = null;
     _currentStatelessSession = null;
 }
Exemplo n.º 5
0
 public void Commit()
 {
     using (ISession session = _sessionFactory.OpenSession())
     {
         if (Transaction.Current == null)
         {
             session.BeginTransaction();
         }
         DoCommit(session);
         if (Transaction.Current == null)
         {
             session.Transaction.Commit();
             session.Transaction.Dispose();
         }
     }
     _readSession.Dispose();
 }
Exemplo n.º 6
0
 public override void Dispose()
 {
     if (_session != null)
     {
         _session.Close();
         _session.Dispose();
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Does the close.
        /// </summary>
        /// <param name="closing">if set to <c>true</c> [closing].</param>
        /// <returns></returns>
        protected IDbConnection DoClose(bool closing)
        {
            if (disposed)
            {
                return(null);
            }

            if (canClose)
            {
                return(InternalClose(closing));
            }
            else
            {
                innerSession.Dispose();
            }

            return(null);
        }
Exemplo n.º 8
0
        public void Close()
        {
            Debug.WriteLine(MethodBase.GetCurrentMethod().DeclaringType + " => " + MethodBase.GetCurrentMethod().Name);

            if (_session.IsOpen)
            {
                //_session.Close();  //InvalidOperationException when using distributed transactions => Disconnect cannot be called while a transaction is in progress.
                _session.Dispose();
            }
        }
 public void Dispose()
 {
     if (_isStateless)
     {
         _wrapStateless.Dispose();
     }
     else
     {
         _wrap.Dispose();
     }
 }
Exemplo n.º 10
0
 public virtual void Dispose()
 {
     if (m_statelessSession != null)
     {
         m_statelessSession.Dispose();
     }
     if (m_sessionFactory != null)
     {
         m_sessionFactory.Dispose();
     }
 }
 public void Dispose()
 {
     if (_session != null)
     {
         _session.Dispose();
     }
     if (_statelessSession == null)
     {
         return;
     }
     _statelessSession.Dispose();
 }
 public void DisposingClosedStatelessSessionShouldNotCauseSessionException()
 {
     try
     {
         IStatelessSession ss = sessions.OpenStatelessSession();
         ss.Close();
         ss.Dispose();
     }
     catch (SessionException)
     {
         Assert.Fail();
     }
 }
Exemplo n.º 13
0
        public void Dispose()
        {
            if (BackgroundSession != null)
            {
                var task = new Task(() => {
                    BackgroundSession?.Dispose();
                    BackgroundSession = null;
                });
                task.Start(QueryScheduler);
                try {
                    if (!task.Wait(TimeSpan.FromSeconds(20)))
                    {
                        BackgroundSession?.Dispose();
                        BackgroundSession = null;
                    }
                } catch (Exception) {
//есть смысл кидать только в дебаге тк в реальной жизни мы ничего сделать не сможем
#if DEBUG
                    throw;
#endif
                }
            }
        }
Exemplo n.º 14
0
        public virtual void Dispose()
        {
            if (_session != null && _session.IsOpen)
            {
                _session.Close();
                _session.Dispose();
            }

            if (_statelessSession != null && _statelessSession.IsOpen)
            {
                _statelessSession.Close();
                _statelessSession.Dispose();
            }
        }
Exemplo n.º 15
0
        public void MixedFixtureTearDown()
        {
            var debugTest = Environment.GetEnvironmentVariable("DEBUG_TEST");

            if (debugTest.Match(TestContext.CurrentContext.Test.Name))
            {
                var repository = (Hierarchy)LogManager.GetRepository();
                repository.ResetConfiguration();
                XmlConfigurator.Configure();
            }
            disposable?.Dispose();
            localSession?.Dispose();
            localStateless?.Dispose();
            DbHelper.SaveFailData();
        }
Exemplo n.º 16
0
        private void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                session?.Dispose();
                statelessSession?.Dispose();
            }

            disposed = true;
        }
        public void NewTransactionAfterUsingStatelessSession()
        {
            ISessionManager manager = container.Resolve <ISessionManager>();

            IStatelessSession session1 = manager.OpenStatelessSession();

            ITransactionManager tmanager = container.Resolve <ITransactionManager>();

            ITransaction transaction = tmanager.CreateTransaction(
                TransactionMode.Requires,
                IsolationMode.Serializable);

            transaction.Begin();

            // Nested
            using (IStatelessSession session2 = manager.OpenStatelessSession())
            {
                Assert.IsNotNull(session2);

                Assert.IsNotNull(session1);
                Assert.IsNotNull(session1.Transaction,
                                 "After requesting compatible session, first session is enlisted in transaction too.");
                Assert.IsTrue(session1.Transaction.IsActive,
                              "After requesting compatible session, first session is enlisted in transaction too.");

                using (ISession session3 = manager.OpenSession())
                {
                    Assert.IsNotNull(session3);
                    Assert.IsNotNull(session3.Transaction);
                    Assert.IsTrue(session3.Transaction.IsActive);
                }

                StatelessSessionDelegate delagate1 = (StatelessSessionDelegate)session1;
                StatelessSessionDelegate delagate2 = (StatelessSessionDelegate)session2;
                Assert.AreSame(delagate1.InnerSession, delagate2.InnerSession);
            }

            transaction.Commit();

            // TODO: Assert transaction was committed
            // Assert.IsTrue(session1.Transaction.WasCommitted);
            Assert.IsTrue(session1.IsConnected);

            session1.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
Exemplo n.º 18
0
        public void TwoDatabasesStateless()
        {
            var manager = container.Resolve <ISessionManager>();

            IStatelessSession session1 = manager.OpenStatelessSession();
            IStatelessSession session2 = manager.OpenStatelessSession("db2");

            Assert.IsNotNull(session1);
            Assert.IsNotNull(session2);

            Assert.IsFalse(Object.ReferenceEquals(session1, session2));

            session2.Dispose();
            session1.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
Exemplo n.º 19
0
 private void endStatelessSession()
 {
     try
     {
         if (stSession != null && stSession.Transaction != null && stSession.Transaction.IsActive)
         {
             if (commitTransaction)
             {
                 try
                 {
                     if (stSession.Transaction.IsActive)
                     {
                         stSession.Transaction.Commit();
                     }
                 }
                 catch (Exception ex)
                 {
                     //stSession.Transaction.Rollback();
                     throw new Exception("There were some changes submitted to the system that could not be committed!", ex);
                 }
             }
             else
             {
                 stSession.Transaction.Rollback();
             }
         }
     }
     finally
     {
         if (stSession.IsOpen)
         {
             stSession.Close();
         }
         if (showQueries)
         {
             Trace.WriteLine("SQL output at:" + DateTime.Now.ToString() + "--> " + "A conversation was closed. ID: " + stSession.GetHashCode());
         }
         stSession.Dispose();
         stSession = null;
         GC.Collect();
     }
 }
Exemplo n.º 20
0
        public void SharedStatelessSession()
        {
            var manager = container.Resolve <ISessionManager>();

            IStatelessSession session1 = manager.OpenStatelessSession();
            IStatelessSession session2 = manager.OpenStatelessSession();
            IStatelessSession session3 = manager.OpenStatelessSession();

            Assert.IsNotNull(session1);
            Assert.IsNotNull(session2);
            Assert.IsNotNull(session3);

            Assert.IsTrue(StatelessSessionDelegate.AreEqual(session1, session2));
            Assert.IsTrue(StatelessSessionDelegate.AreEqual(session1, session3));

            session3.Dispose();
            session2.Dispose();
            session1.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
        public void SecondDatabaseStatelessSessionEnlistedOnlyOnceInActualTransaction()
        {
            ISessionManager manager = container.Resolve <ISessionManager>();

            ITransactionManager tmanager = container.Resolve <ITransactionManager>();

            ITransaction transaction = tmanager.CreateTransaction(
                TransactionMode.Requires,
                IsolationMode.Serializable);

            transaction.Begin();

            // open connection to first database and enlist session in running transaction
            IStatelessSession session1 = manager.OpenStatelessSession();

            // open connection to second database and enlist session in running transaction
            using (IStatelessSession session2 = manager.OpenStatelessSession("db2"))
            {
                Assert.IsNotNull(session2);
                Assert.IsNotNull(session2.Transaction);
            }
            // "real" NH session2 was not disposed because its in active transaction

            // request compatible session for db2 --> we must get existing NH session to db2 which should be already enlisted in active transaction
            using (IStatelessSession session3 = manager.OpenStatelessSession("db2"))
            {
                Assert.IsNotNull(session3);
                Assert.IsTrue(session3.Transaction.IsActive);
            }

            transaction.Commit();

            // TODO: Assert transaction was committed
            // Assert.IsTrue(session1.Transaction.WasCommitted);
            // Assert.IsTrue(session1.IsConnected);

            session1.Dispose();

            Assert.IsTrue(container.Resolve <ISessionStore>().IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
        /// <summary>
        /// Disposes of this instance of the Repository class.
        /// </summary>
        /// <param name="isDisposing">Flag that tells the .NET runtime if this class is disposing.</param>
        /// <remarks>This method kills the existing NHibernate session, transaction, and interceptor.</remarks>
        protected virtual void Dispose(bool isDisposing)
        {
            if (isDisposing)
            {
                if (_isSessionCreator)
                {
                    //this.Close();

                    //if (_transaction != null)
                    //{
                    //    _transaction.Dispose();
                    //    _transaction = null;
                    //}

                    if (_session != null)
                    {
                        _session.Dispose();
                        _session = null;
                    }
                }
            }
        }
Exemplo n.º 23
0
        public void FindCompatibleStatelessSession()
        {
            ISessionStore   store   = container.Resolve <ISessionStore>();
            ISessionFactory factory = container.Resolve <ISessionFactory>();

            IStatelessSession session = store.FindCompatibleStatelessSession(Constants.DefaultAlias);

            Assert.IsNull(session);

            session = factory.OpenStatelessSession();

            StatelessSessionDelegate sessionDelegate = new StatelessSessionDelegate(true, session, store);

            store.Store(Constants.DefaultAlias, sessionDelegate);

            Assert.IsNotNull(sessionDelegate.SessionStoreCookie);

            IStatelessSession session2 = store.FindCompatibleStatelessSession("something in the way she moves");

            Assert.IsNull(session2);

            session2 = store.FindCompatibleStatelessSession(Constants.DefaultAlias);

            Assert.IsNotNull(session2);
            Assert.AreSame(sessionDelegate, session2);

            session.Dispose();

            store.Remove(sessionDelegate);

            session = store.FindCompatibleStatelessSession(Constants.DefaultAlias);

            Assert.IsNull(session);

            Assert.IsTrue(store.IsCurrentActivityEmptyFor(Constants.DefaultAlias));
        }
Exemplo n.º 24
0
 public void TearDown()
 {
     _transaction.Dispose();
     _session.Dispose();
     _sessionFactory.Dispose();
 }
Exemplo n.º 25
0
 protected override void CoreDispose(bool disposeManagedResources)
 {
     _statelessSession.Dispose();
 }
Exemplo n.º 26
0
 public override void Dispose()
 {
     _session.Dispose();
     base.Dispose();
 }
Exemplo n.º 27
0
 public void Dispose()
 {
     statelessSession.Dispose();
 }
 public void Dispose()
 {
     _Session.Dispose();
 }
Exemplo n.º 29
0
 public void Dispose()
 {
     session.Dispose();
 }
Exemplo n.º 30
0
 public void Dispose()
 {
     _factory.DisposeUnitOfWork(this);
     _session.Dispose();
 }