/// <summary>
        /// Chiude ed esegue il dispose di Transizioni e Sessioni
        /// </summary>
        /// <remarks>Esegue il rollback delle eventuali transazioni aperte</remarks>
        public void CloseTransactionAndSessions()
        {
            if (ContextTransactions != null && ContextTransactions.Count > 0)
            {
                foreach (ITransaction trans in ContextTransactions.Values)
                {
                    if (trans.IsActive)
                    {
                        trans.Rollback();
                    }
                    ((IDisposable)trans).Dispose();
                }
                ContextTransactions.Clear();
            }

            if (ContextSessions != null && ContextSessions.Count > 0)
            {
                foreach (ISession session in ContextSessions.Values)
                {
                    if (session.IsOpen)
                    {
                        session.Close();
                    }
                    //((IDisposable)session).Dispose();
                }
                ContextSessions.Clear();
            }
        }
Ejemplo n.º 2
0
        public ITransaction BeginTransactionOn(string sessionFactoryConfigPath)
        {
            ITransaction transaction = (ITransaction)ContextTransactions[sessionFactoryConfigPath];

            if (transaction == null)
            {
                transaction = GetSessionFrom(sessionFactoryConfigPath).BeginTransaction();
                ContextTransactions.Add(sessionFactoryConfigPath, transaction);
            }

            return(transaction);
        }
        public ITransaction BeginTransactionOn(string contextName)
        {
            ITransaction transaction = (ITransaction)ContextTransactions[contextName];

            if (transaction == null)
            {
                transaction = GetSessionFrom(contextName).BeginTransaction();
                ContextTransactions.Add(contextName, transaction);
            }

            return(transaction);
        }
Ejemplo n.º 4
0
        public void RollbackTransactionOn(string sessionFactoryConfigPath)
        {
            ITransaction transaction = (ITransaction)ContextTransactions[sessionFactoryConfigPath];

            try {
                if (HasOpenTransactionOn(sessionFactoryConfigPath))
                {
                    transaction.Rollback();
                }

                ContextTransactions.Remove(sessionFactoryConfigPath);
            }
            finally {
                CloseSessionOn(sessionFactoryConfigPath);
            }
        }
Ejemplo n.º 5
0
        public void CommitTransactionOn(string sessionFactoryConfigPath)
        {
            ITransaction transaction = (ITransaction)ContextTransactions[sessionFactoryConfigPath];

            try {
                if (HasOpenTransactionOn(sessionFactoryConfigPath))
                {
                    transaction.Commit();
                    ContextTransactions.Remove(sessionFactoryConfigPath);
                }
            }
            catch (HibernateException) {
                RollbackTransactionOn(sessionFactoryConfigPath);
                throw;
            }
        }
        public void RollbackTransactionOn(string contextName)
        {
            ITransaction transaction = (ITransaction)ContextTransactions[contextName];

            try
            {
                if (HasOpenTransactionOn(contextName))
                {
                    transaction.Rollback();
                }

                ContextTransactions.Remove(contextName);
            }
            finally
            {
                CloseSessionOn(contextName);
            }
        }
        public void CommitTransactionOn(string contextName)
        {
            ITransaction transaction = (ITransaction)ContextTransactions[contextName];

            try
            {
                if (HasOpenTransactionOn(contextName))
                {
                    transaction.Commit();
                    ContextTransactions.Remove(contextName);
                }
            }
            catch (HibernateException)
            {
                RollbackTransactionOn(contextName);
                throw;
            }
        }
        public void RollbackTransactionOn(string sessionFactoryName)
        {
            ITransaction transaction = (ITransaction)ContextTransactions[sessionFactoryName];

            try
            {
                if (HasOpenTransactionOn(sessionFactoryName))
                {
                    var session = (ISession)ContextSessions[sessionFactoryName];
                    session.Flush();
                    transaction.Rollback();
                }

                ContextTransactions.Remove(sessionFactoryName);
            }
            finally
            {
                //CloseSessionOn(sessionFactoryName);
            }
        }