Inheritance: vlko.core.Repository.ITransaction
Ejemplo n.º 1
0
        internal static void UnregisterTransaction(Transaction transaction)
        {
            var stack = CurrentStack;
            if (stack.TopTransaction == transaction)
            {
                bool transactionStillActive = stack.Session.Transaction.IsActive;

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

                // unlock transaction concurrency
                Monitor.Exit(transaction.LockObject);

                // 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.TopTransaction = null;

                // if transaction is also top session then free session
                if (stack.TopUnitOfWork == null)
                {
                    ClearStackInfo(stack);
                }
            }
        }
Ejemplo 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 = SessionFactoryInstance.OpenSession();
                stack.Session.FlushMode = FlushMode.Commit;
            }
            // and if no transaction yet, then start new one
            if (stack.TopTransaction == null)
            {
                transaction.LockObject = stack.Session.Connection;
                // lock transaction concurrency
                Monitor.Enter(transaction.LockObject);

                stack.TopTransaction = transaction;
                stack.Session.BeginTransaction(IsolationLevel.Unspecified);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Rollbacks the transaction.
 /// </summary>
 /// <param name="transaction">The transaction.</param>
 internal static void RollbackTransaction(Transaction transaction)
 {
     var stack = CurrentStack;
     stack.Session.Transaction.Rollback();
 }
Ejemplo 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.Session.Transaction.WasRolledBack)
         {
             throw new SessionException("Nested transaction called Rollback and thus we are not able to commit!");
         }
         stack.Session.Transaction.Commit();
     }
     else
     {
         stack.Session.Flush();
     }
 }