Exemplo n.º 1
0
        public async Task <bool> Commit()
        {
            try
            {
                if (transaction != null)
                {
                    await transaction.CommitAsync();
                }

                return(true);
            }
            catch
            {
                if (transaction != null && transaction.IsActive)
                {
                    await transaction.RollbackAsync();
                }

                return(false);
            }
            finally
            {
                transaction.Dispose();
                transaction = null;
            }
        }
Exemplo n.º 2
0
        private void Dispose(bool disposing)
        {
            if (isDisposed)
            {
                return;
            }

            lock (thisLock)
            {
                if (isDisposed == false)
                {
                    try
                    {
                        _tx.Dispose();
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        isDisposed = true;

                        if (disposing)
                        {
                            GC.SuppressFinalize(this);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 void IDisposable.Dispose()
 {
     if (isOriginator)
     {
         Rollback();
         transaction.Dispose();
     }
 }
Exemplo n.º 4
0
 public void Dispose(bool disposing)
 {
     if (_disposed)
     {
         return;
     }
     if (disposing)
     {
         if (_transaction != null)
         {
             _transaction.Dispose();
             _transaction = null;
         }
     }
     _disposed = true;
 }
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     transaction.Dispose();
 }
 void IDisposable.Dispose() => nhTran.Dispose();
Exemplo n.º 7
0
        IMethodReturn IInterceptionBehavior.Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            IMethodReturn retour = null;

            TransactionalAttribute transactional = null;

            object[] atts = input.MethodBase.GetCustomAttributes(typeof(TransactionalAttribute), false);
            if (atts.Count() > 0)
            {
                transactional = (TransactionalAttribute)atts[0];
            }

            if (Utility.MyNHibernateHelper.SessionManager.Configuration == null)
            {
                SessionManager.Configuration = TransactionInterceptorConfiguration.Configuration;
                TransactionInterceptorConfiguration.SessionManager = new SessionManager();
            }

            if (NHibernate.Context.CurrentSessionContext.HasBind(SessionManager.SessionFactory) == false)
            {
                NHibernate.Context.CurrentSessionContext.Bind(SessionManager.SessionFactory.OpenSession());
            }

            NHibernate.ISession     session     = null;
            NHibernate.ITransaction transaction = null;
            if (transactional != null)
            {
                session = TransactionInterceptorConfiguration.SessionManager.CurrentSession;
                if (transactional.OpenTransaction)
                {
                    transaction = session.BeginTransaction();
                }
            }

            try
            {
                retour = getNext()(input, getNext);
                if (transaction != null && transactional.RollBack == true)
                {
                    transaction.Rollback();
                    //if (typeof(retour.Exception) == typeof(NHibernate.Exceptions.GenericADOException)) retour.Exception = null;
                }
                else if (retour.Exception == null && transaction != null)
                {
                    transaction.Commit();
                }
                else if (retour.Exception != null)
                {
                    throw retour.Exception;
                }
            }
            catch (Exception ex)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                else
                {
                    throw ex;
                }
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Dispose();
                }
                if (session != null)
                {
                    session.Close();
                    session.Dispose();
                    NHibernate.Context.CurrentSessionContext.Unbind(SessionManager.SessionFactory);
                }
            }

            return(retour);
        }