Ejemplo n.º 1
0
        protected virtual object CloseUnitOfWork(TransactionAttributeSettings transactionAttributeSettings,
                                                 object transactionState, Exception err)
        {
            string factoryKey = transactionAttributeSettings.FactoryKey;

            if (err == null)
            {
                try {
                    NHibernateSession.CurrentFor(factoryKey).Flush();
                    transactionState = transactionManager.CommitTransaction(factoryKey, transactionState);
                }
                catch (Exception) {
                    transactionState = transactionManager.RollbackTransaction(factoryKey, transactionState);
                    transactionState = transactionManager.PopTransaction(factoryKey, transactionState);
                    throw;
                }
            }
            else
            {
                transactionState = transactionManager.RollbackTransaction(factoryKey, transactionState);
            }
            transactionState = transactionManager.PopTransaction(factoryKey, transactionState);

            return(transactionState);
        }
Ejemplo n.º 2
0
        public Task <CommitTransactionsResponse> CommitTransactions(List <TransactionInfo> transactions, HashSet <long> queries)
        {
            List <Task> tasks = new List <Task>();

            var result = new CommitTransactionsResponse {
                CommitResult = new Dictionary <long, CommitResult>()
            };

            foreach (var ti in transactions)
            {
                try
                {
                    tm.CommitTransaction(ti);
                }
                catch (OrleansTransactionAbortedException e)
                {
                    var cr = new CommitResult()
                    {
                        Success           = false,
                        AbortingException = e,
                    };
                    result.CommitResult[ti.TransactionId] = cr;
                }
            }

            foreach (var q in queries)
            {
                OrleansTransactionAbortedException abortingException;
                var status = tm.GetTransactionStatus(q, out abortingException);
                if (status == TransactionStatus.InProgress)
                {
                    continue;
                }

                var cr = new CommitResult();
                if (status == TransactionStatus.Aborted)
                {
                    cr.Success           = false;
                    cr.AbortingException = abortingException;
                }
                else if (status == TransactionStatus.Committed)
                {
                    cr.Success = true;
                }
                else if (status == TransactionStatus.Unknown)
                {
                    // Note that the way we communicate an unknown transaction is a false Success
                    // and a null aborting exception.
                    // TODO: make this more explicit?
                    cr.Success = false;
                }

                result.CommitResult[q] = cr;
            }

            result.ReadOnlyTransactionId = tm.GetReadOnlyTransactionId();
            result.AbortLowerBound       = result.ReadOnlyTransactionId;

            return(Task.FromResult(result));
        }
Ejemplo n.º 3
0
        public void Add(int key, object value)
        {
            try
            {
                m_transactionManager.BeginTransaction();

                m_bufferDictionary = new Dictionary <int, object>(m_mainDictionary);

                m_bufferDictionary.Add(key, value);

                m_transactionManager.CommitTransaction(Commit);
            }
            catch (System.Exception)
            {
                m_transactionManager.RollbackTransaction(Rollback);

                throw;
            }
        }
        /// <summary>
        ///     Occurs after the action method is invoked.
        ///     Commits transaction if no error occurred.
        /// </summary>
        /// <param name="actionExecutedContext">The action context.</param>
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            base.OnActionExecuted(actionExecutedContext);
            ITransactionManager transactionManager = GetTransactionManager(actionExecutedContext.Request);

            if (actionExecutedContext.Exception != null || ShouldRollbackOnModelError(actionExecutedContext))
            {
                transactionManager.RollbackTransaction();
            }
            else
            {
                transactionManager.CommitTransaction();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            try
            {
                _transactionManager.BeginTransaction();
                await next();

                _transactionManager.CommitTransaction();
            }
            catch (Exception ex)
            {
                _transactionManager.RollbackTransaction();
                throw ex;
            }
        }
Ejemplo n.º 6
0
 public void CommitTransaction(SecurityToken mySecurity, Int64 myTransactionToken)
 {
     _transactionManager.CommitTransaction(mySecurity, myTransactionToken);
 }