当前位置: 首页>>代码示例>>C#>>正文


C# ITransaction.Rollback方法代码示例

本文整理汇总了C#中ITransaction.Rollback方法的典型用法代码示例。如果您正苦于以下问题:C# ITransaction.Rollback方法的具体用法?C# ITransaction.Rollback怎么用?C# ITransaction.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITransaction的用法示例。


在下文中一共展示了ITransaction.Rollback方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Intercept

        public void Intercept(IInvocation invocation)
        {
            var sessionFactories = NHibernateSessionManager.SessionFactories;
            var method = invocation.Method;
            var isTransactionScoped = method.IsDecoratedBy(typeof(TransactionAttribute));

            if (isTransactionScoped) {
                foreach (var sessionFactory in sessionFactories)
                {
                    var session = sessionFactory.GetSession();

                    _transaction = sessionFactory.GetSession().Transaction.IsActive
                                ? _session.Transaction
                                : _session.BeginTransaction();
                }
                _transaction = _session.Transaction;

                try {
                    invocation.Proceed();

                    _transaction.Commit();
                } catch (Exception) {
                    _transaction.Rollback();

                    throw;
                } finally {
                    _transaction.Dispose();
                }
            }
        }
开发者ID:gofixiao,项目名称:Macsauto-Backup,代码行数:30,代码来源:TransactionInterceptor.cs

示例2: NHibernateException

        public static void NHibernateException(Exception ex, ITransaction transaction)
        {
            if (!transaction.WasCommitted)
            {
                transaction.Rollback();
            }

            throw ex;
        }
开发者ID:edubalf,项目名称:DevShop,代码行数:9,代码来源:TratarException.cs

示例3: Handle

        CommandResult Handle(ITransaction transaction, ICommand command)
        {
            var commandResult = new CommandResult();
            try
            {
                using (_localizer.BeginScope())
                {
                    commandResult = CommandResult.ForCommand(command);

                    var authorizationResult = _commandSecurityManager.Authorize(command);
                    if (!authorizationResult.IsAuthorized)
                    {
                        commandResult.SecurityMessages = authorizationResult.BuildFailedAuthorizationMessages();
                        transaction.Rollback();
                        return commandResult;
                    }

                    var validationResult = _commandValidationService.Validate(command);
                    commandResult.ValidationResults = validationResult.ValidationResults;
                    commandResult.CommandValidationMessages = validationResult.CommandErrorMessages;

                    if (commandResult.Success)
                    {
                        try
                        {
                            _commandHandlerManager.Handle(command);
                            transaction.Commit();
                        }
                        catch (TargetInvocationException ex)
                        {
                            commandResult.Exception = ex.InnerException;
                            transaction.Rollback();
                        }
                        catch (Exception exception)
                        {
                            commandResult.Exception = exception;
                            transaction.Rollback();
                        }
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                }
            }
            catch (TargetInvocationException ex)
            {
                commandResult.Exception = ex.InnerException;
            }
            catch (Exception ex)
            {
                commandResult.Exception = ex;
            }

            return commandResult;            
        }
开发者ID:LenFon,项目名称:Bifrost,代码行数:56,代码来源:CommandCoordinator.cs

示例4: Eval

 public void Eval(ITransaction transaction, bool throwException = true)
 {
     if (IsValid())
     {
         transaction.Commit();
         return;
     }
     transaction.Rollback();
     if (throwException) ThrowValidationException();
 }
开发者ID:mynamespace,项目名称:NHibernate.Extensions,代码行数:10,代码来源:SessionValidator.cs

示例5: save

 public bool save(Customer customer)
 {
     trans = session.BeginTransaction();
     try
     {
         session.Save(customer);
         trans.Commit();
         return true;
     }
     catch (Exception)
     {
         trans.Rollback();
         return false;
     }
 }
开发者ID:ryanyau,项目名称:mobile,代码行数:15,代码来源:CustomerDao.cs

示例6: save

 public bool save(Account account)
 {
     trans = session.BeginTransaction();
     try
     {
         session.Save(account);
         trans.Commit();
         return true;
     }
     catch (Exception)
     {
         trans.Rollback();
         return false;
     }
 }
开发者ID:ryanyau,项目名称:mobile,代码行数:15,代码来源:AccountDao.cs

示例7: Rollback

 private void Rollback(ITransaction transaction)
 {
     if (transaction != null && transaction.IsActive)
     {
         transaction.Rollback();
     }
 }
开发者ID:mmsommer,项目名称:Ogd.DataSource,代码行数:7,代码来源:NHibernateHelper.cs

示例8: RollbackTransaction

        private void RollbackTransaction(ITransaction transaction)
        {
            try
            {
                transaction.Rollback();
            }
            catch (Exception e)
            {
                if (logger.IsFatalEnabled)
                {
                    logger.Fatal("Fatal error during transaction rollback", e);
                }

                throw;
            }
        }
开发者ID:carcer,项目名称:Castle.Facilities.AutomaticTransactionManagement,代码行数:16,代码来源:TransactionInterceptor.cs

示例9: InitSession

 /// <summary>
 /// Initializes the session that will be used to enumerate
 /// </summary>
 private void InitSession()
 {
     _session = _sessionFactory.OpenSession();
     _session.FlushMode = FlushMode.Never;
     _tx = _session.BeginTransaction();
     try
     {
         //Handle the case of entity type (InitialLoad)
         if (_entityType != null)
         {
             _criteria = _session.CreateCriteria(_entityType);
             _criteria.SetCacheable(false);
             //If perform by id, add order to the criteria
             if (_performOrderById)
             {
                 IClassMetadata metadata = _sessionFactory.GetClassMetadata(_entityType);
                 string idPropName = metadata.IdentifierPropertyName;
                 if (idPropName != null)
                     _criteria.AddOrder(Order.Asc(idPropName));
             }
         }
         //Handle the case of Persistency.Query (GetEnumerator)
         else if (_persistencyQuery != null)
         {
             string select = _persistencyQuery.SqlQuery;
             _query = _session.CreateQuery(select);
             object[] preparedValues = _persistencyQuery.Parameters;
             if (preparedValues != null)
             {
                 for (int i = 0; i < preparedValues.Length; i++)
                 {
                     _query.SetParameter(i, preparedValues[i]);
                 }
             }
             _query.SetCacheable(false);
             _query.SetFlushMode(FlushMode.Never);
         }
         else throw new Exception("NHibernateDataEnumerator must receive an Entity Type or a Query");
     }
     catch(Exception ex)
     {
         if (_tx != null && _tx.IsActive)
             _tx.Rollback();
         if (_session.IsOpen)
             _session.Close();
         throw new Exception("Error while constructing an enumerator", ex);
     }
 }
开发者ID:GigaSpaces-ProfessionalServices,项目名称:xapnet-templates,代码行数:51,代码来源:NHibernateDataEnumerator.cs

示例10: SynchronizedCase

		private static void SynchronizedCase(IInvocation invocation, ITransaction transaction)
		{
			Contract.Requires(transaction.State == TransactionState.Active);
			_Logger.DebugFormat("synchronized case");

			using (new TransactionScope(transaction.Inner))
			{
				try
				{
					invocation.Proceed();

					if (transaction.State == TransactionState.Active)
						transaction.Complete();

					else
						_Logger.WarnFormat(
							"transaction was in state {0}, so it cannot be completed. the 'consumer' method, so to speak, might have rolled it back.",
							transaction.State);
				}
				catch (TransactionAbortedException)
				{
					// if we have aborted the transaction, we both warn and re-throw the exception
					_Logger.Warn("transaction aborted - synchronized case");
					throw;
				}
				catch (TransactionException ex)
				{
					if (_Logger.IsFatalEnabled)
						_Logger.Fatal("internal error in transaction system - synchronized case", ex);

					throw;
				}
				catch (Exception)
				{
					if (_Logger.IsErrorEnabled)
						_Logger.ErrorFormat("caught exception, rolling back transaction - synchronized case - tx#{0}",
						                    transaction.LocalIdentifier);

					transaction.Rollback();
					throw;
				}
				finally
				{
					if (_Logger.IsDebugEnabled)
						_Logger.DebugFormat("dispoing transaction - synchronized case - tx#{0}", transaction.LocalIdentifier);

					transaction.Dispose();
				}
			}
		}
开发者ID:bittercoder,项目名称:Castle.Transactions,代码行数:50,代码来源:TransactionInterceptor.cs

示例11: CommitTransaction

 /// <summary>
 /// Comitar Transação
 /// </summary>
 /// <returns></returns>
 public bool CommitTransaction()
 {
     bool result = HasOpenTransaction;
     if (result)
     {
         try
         {
             transaction.Commit();
             transaction = null;
         }
         catch (HibernateException)
         {
             transaction.Rollback();
             transaction = null;
             throw;
         }
     }
     return result;
 }
开发者ID:engaugusto,项目名称:ProvaRodrigoWebMod4,代码行数:23,代码来源:NHibernateSession.cs

示例12: ConcludeTransactionBasedOn

        private static void ConcludeTransactionBasedOn(TransactionState transactionState, ITransaction tx)
        {
            switch (transactionState)
            {
                case TransactionState.Committed:
                    tx.Commit();
                    break;

                case TransactionState.RolledBack:
                    tx.Rollback();
                    break;

                case TransactionState.Open:
                    // Do nothing
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:davidmosborne,项目名称:Blog,代码行数:20,代码来源:Within.cs


注:本文中的ITransaction.Rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。