Beispiel #1
0
        public void Start(IUnitOfWork uow)
        {
            int sessionCode = 0;

            switch (type)
            {
            case TypeOfUnitOfWork.Normal:     // add the uow to the observers of the current conversation, so that at closing time, the conversation is disposed with the last uow
                this.session = getAmbientSession(true);
                statefull    = true;
                stSession    = null;

                registerUnit(session, uow);
                if (!AppConfiguration.CacheQueryResults)
                {
                    session.CacheMode = NHibernate.CacheMode.Ignore;
                }
                else
                {
                    session.CacheMode = NHibernate.CacheMode.Normal;
                }
                sessionCode = session.GetHashCode();
                break;

            case TypeOfUnitOfWork.Isolated:     // single conversation per uow
                this.session = createSession();
                statefull    = true;
                stSession    = null;

                if (!AppConfiguration.CacheQueryResults)
                {
                    session.CacheMode = NHibernate.CacheMode.Ignore;
                }
                else
                {
                    session.CacheMode = NHibernate.CacheMode.Normal;
                }
                sessionCode = session.GetHashCode();
                break;

            case TypeOfUnitOfWork.Bulk:     // single conversation per uow
                this.stSession = createStatelessSession();
                statefull      = false;
                session        = null;

                sessionCode = stSession.GetHashCode();
                break;

            default:
                break;
            }

            if (showQueries)
            {
                Trace.WriteLine("SQL output at:" + DateTime.Now.ToString() + "--> " + "A conversation was opened. ID: " + sessionCode);
            }
        }
Beispiel #2
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();
     }
 }