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); } } }
/// <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)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; } }
/// <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); }
/// <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(); } }