Exemplo n.º 1
0
        internal static void UnregisterTransaction(Transaction transaction)
        {
            var stack = CurrentStack;
            if (stack.TopTransaction == transaction)
            {
                bool transactionStillActive = stack.TransactionState == StackInfo.TransactionStateEnum.Active;

                // if we have still open transaction then call rollback
                if (transactionStillActive)
                {
                    RollbackTransaction(transaction);
                }

                // throw exception if transaction was still active and no exception raised, then throw my own exception
                if (transactionStillActive && Marshal.GetExceptionCode() == 0)
                {
                    throw new SessionException("Transaction is open! Try commit or rollback before ");
                }

                stack.Transaction.Dispose();
                stack.TransactionState = StackInfo.TransactionStateEnum.NoActiveTransaction;
                stack.TopTransaction = null;

                // if transaction is also top session then free session
                if (stack.TopUnitOfWork == null)
                {
                    ClearStackInfo(stack);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Registers the transaction.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 internal static void RegisterTransaction(Transaction transaction)
 {
     var stack = CurrentStack;
     // if no session yet, start new
     if (stack.Session == null)
     {
         stack.Session = (DocumentSession)transaction.DocumentStoreInstance.OpenSession();
     }
     // and if no transaction yet, then start new one
     if (stack.TopTransaction == null)
     {
         stack.TopTransaction = transaction;
         stack.Transaction = RavenTransactionAccessor.StartTransaction();
         stack.TransactionState = StackInfo.TransactionStateEnum.Active;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Rollbacks the transaction.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 internal static void RollbackTransaction(Transaction transaction)
 {
     var stack = CurrentStack;
     stack.TransactionState = StackInfo.TransactionStateEnum.Rollback;
     stack.Session.Rollback(RavenTransactionAccessor.GetTransactionInformation().Id);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Commits the transaction.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 internal static void CommitTransaction(Transaction transaction)
 {
     var stack = CurrentStack;
     if (stack.TopTransaction == transaction)
     {
         if (stack.TransactionState == StackInfo.TransactionStateEnum.Rollback)
         {
             throw new SessionException("Nested transaction called Rollback and thus we are not able to commit!");
         }
         stack.Session.SaveChanges();
         stack.TransactionState = StackInfo.TransactionStateEnum.Commit;
         stack.Session.Commit(RavenTransactionAccessor.GetTransactionInformation().Id);
     }
     else
     {
         stack.Session.SaveChanges();
     }
 }