本文整理汇总了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();
}
}
}
示例2: NHibernateException
public static void NHibernateException(Exception ex, ITransaction transaction)
{
if (!transaction.WasCommitted)
{
transaction.Rollback();
}
throw ex;
}
示例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;
}
示例4: Eval
public void Eval(ITransaction transaction, bool throwException = true)
{
if (IsValid())
{
transaction.Commit();
return;
}
transaction.Rollback();
if (throwException) ThrowValidationException();
}
示例5: save
public bool save(Customer customer)
{
trans = session.BeginTransaction();
try
{
session.Save(customer);
trans.Commit();
return true;
}
catch (Exception)
{
trans.Rollback();
return false;
}
}
示例6: save
public bool save(Account account)
{
trans = session.BeginTransaction();
try
{
session.Save(account);
trans.Commit();
return true;
}
catch (Exception)
{
trans.Rollback();
return false;
}
}
示例7: Rollback
private void Rollback(ITransaction transaction)
{
if (transaction != null && transaction.IsActive)
{
transaction.Rollback();
}
}
示例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();
}
}
}
示例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;
}
示例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();
}
}