internal TransactionScope OpenTransaction(TransactionOpenMode mode, IsolationLevel isolationLevel, bool isAutomatic) { var transaction = Transaction; switch (mode) { case TransactionOpenMode.Auto: if (transaction != null) { if (isolationLevel != IsolationLevel.Unspecified && isolationLevel != transaction.IsolationLevel) { EnsureIsolationLevelCompatibility(transaction.IsolationLevel, isolationLevel); } return(TransactionScope.VoidScopeInstance); } if (isolationLevel == IsolationLevel.Unspecified) { isolationLevel = Configuration.DefaultIsolationLevel; } return(CreateOutermostTransaction(isolationLevel, isAutomatic)); case TransactionOpenMode.New: if (isolationLevel == IsolationLevel.Unspecified) { isolationLevel = Configuration.DefaultIsolationLevel; } return(transaction != null ? CreateNestedTransaction(isolationLevel, isAutomatic) : CreateOutermostTransaction(isolationLevel, isAutomatic)); default: throw new ArgumentOutOfRangeException("mode"); } }
/// <summary> /// Initializes a new instance of the <see cref="ExecutionContext{T}"/> class. /// </summary> /// <param name="domain">The domain.</param> /// <param name="isolationLevel">The isolation level.</param> /// <param name="transactionOpenMode">The transaction open mode.</param> /// <param name="function">The task.</param> public ExecutionContext( Domain domain, IsolationLevel isolationLevel, TransactionOpenMode transactionOpenMode, Func <Session, T> function) { Domain = domain; IsolationLevel = isolationLevel; TransactionOpenMode = transactionOpenMode; Function = function; }
/// <summary> /// Initializes a new instance of the <see cref="ExecutionContext{T}"/> class. /// </summary> /// <param name="domain">The domain.</param> /// <param name="isolationLevel">The isolation level.</param> /// <param name="transactionOpenMode">The transaction open mode.</param> /// <param name="function">The task.</param> public ExecutionContext( Domain domain, IsolationLevel isolationLevel, TransactionOpenMode transactionOpenMode, Func <Session, T> function) : this(domain, null, isolationLevel, transactionOpenMode, function) { }
private async ValueTask <TransactionScope> InnerOpenTransaction( TransactionOpenMode mode, IsolationLevel isolationLevel, bool isAutomatic, bool isAsync, CancellationToken token = default) { var transaction = Transaction; switch (mode) { case TransactionOpenMode.Auto: if (transaction != null) { if (isolationLevel != IsolationLevel.Unspecified && isolationLevel != transaction.IsolationLevel) { EnsureIsolationLevelCompatibility(transaction.IsolationLevel, isolationLevel); } return(TransactionScope.VoidScopeInstance); } if (isolationLevel == IsolationLevel.Unspecified) { isolationLevel = Configuration.DefaultIsolationLevel; } return (isAsync ? await CreateOutermostTransactionAsync(isolationLevel, isAutomatic, token).ConfigureAwait(false) : CreateOutermostTransaction(isolationLevel, isAutomatic)); case TransactionOpenMode.New: if (isolationLevel == IsolationLevel.Unspecified) { isolationLevel = Configuration.DefaultIsolationLevel; } return (isAsync ? transaction != null ? await CreateNestedTransactionAsync(isolationLevel, isAutomatic, token).ConfigureAwait(false) : await CreateOutermostTransactionAsync(isolationLevel, isAutomatic, token).ConfigureAwait(false) : transaction != null ? CreateNestedTransaction(isolationLevel, isAutomatic) : CreateOutermostTransaction(isolationLevel, isAutomatic)); default: throw new ArgumentOutOfRangeException(nameof(mode)); } }
/// <summary> /// Opens a new or already running transaction. /// </summary> /// <param name="mode">The mode.</param> /// <returns> /// A new <see cref="TransactionScope"/> object. Its disposal will lead to either commit /// or rollback of the transaction it controls dependently on <see cref="ICompletableScope.IsCompleted"/> flag. /// </returns> /// <exception cref="InvalidOperationException">There is no current <see cref="Session"/>.</exception> public TransactionScope OpenTransaction(TransactionOpenMode mode) => OpenTransaction(mode, IsolationLevel.Unspecified, false);
internal ValueTask <TransactionScope> OpenTransactionAsync( TransactionOpenMode mode, IsolationLevel isolationLevel, bool isAutomatic, CancellationToken token = default) => InnerOpenTransaction(mode, isolationLevel, isAutomatic, true, token);
internal TransactionScope OpenTransaction( TransactionOpenMode mode, IsolationLevel isolationLevel, bool isAutomatic) => InnerOpenTransaction(mode, isolationLevel, isAutomatic, false).GetAwaiter().GetResult();
/// <summary> /// Asynchronously opens a new or joins to the already running transaction. /// </summary> /// <remarks> Multiple active operations are not supported. Use <see langword="await"/> /// to ensure that all asynchronous operations have completed.</remarks> /// <param name="mode">The mode.</param> /// <param name="isolationLevel">The isolation level.</param> /// <param name="token">The cancellation token to terminate execution if needed.</param> /// <returns> /// A new <see cref="TransactionScope"/> object. Its disposal will lead to either commit /// or rollback of the transaction it controls dependently on <see cref="ICompletableScope.IsCompleted"/> flag. /// </returns> /// <exception cref="InvalidOperationException">There is no current <see cref="Session"/>.</exception> public ValueTask <TransactionScope> OpenTransactionAsync( TransactionOpenMode mode, IsolationLevel isolationLevel, CancellationToken token = default) => OpenTransactionAsync(mode, isolationLevel, false, token);
/// <summary> /// Opens a new or already running transaction. /// </summary> /// <param name="mode">The mode.</param> /// <param name="isolationLevel">The isolation level.</param> /// <returns> /// A new <see cref="TransactionScope"/> object. Its disposal will lead to either commit /// or rollback of the transaction it controls dependently on <see cref="ICompletableScope.IsCompleted"/> flag. /// </returns> /// <exception cref="InvalidOperationException">There is no current <see cref="Session"/>.</exception> public TransactionScope OpenTransaction(TransactionOpenMode mode, IsolationLevel isolationLevel) => OpenTransaction(mode, isolationLevel, false);
/// <summary> /// Opens a new or already running transaction. /// </summary> /// <param name="mode">The mode.</param> /// <param name="isolationLevel">The isolation level.</param> /// <returns> /// A new <see cref="TransactionScope"/> object. Its disposal will lead to either commit /// or rollback of the transaction it controls dependently on <see cref="ICompletableScope.IsCompleted"/> flag. /// </returns> /// <exception cref="InvalidOperationException">There is no current <see cref="Session"/>.</exception> public TransactionScope OpenTransaction(TransactionOpenMode mode, IsolationLevel isolationLevel) { return(OpenTransaction(mode, isolationLevel, false)); }
public IExecuteConfiguration WithTransactionOpenMode(TransactionOpenMode transactionOpenMode) { TransactionOpenMode = transactionOpenMode; return(this); }
public static TransactionScope Open(TransactionOpenMode mode, IsolationLevel isolationLevel) { var session = Session.Demand(); return(session.OpenTransaction(mode, isolationLevel, false)); }
public static TransactionScope Open(Session session, TransactionOpenMode mode, IsolationLevel isolationLevel) { ArgumentValidator.EnsureArgumentNotNull(session, "session"); return(session.OpenTransaction(mode, isolationLevel, false)); }
/// <summary> /// Starts <see cref="IExecuteConfiguration"/> flow /// and provides <see cref="TransactionOpenMode"/> to use. /// </summary> /// <param name="domain">The domain.</param> /// <param name="transactionOpenMode">Transaction open mode to use.</param> /// <returns>Created <see cref="IExecuteConfiguration"/>.</returns> public static IExecuteConfiguration WithTransactionOpenMode(this Domain domain, TransactionOpenMode transactionOpenMode) { return(new ExecuteConfiguration(domain).WithTransactionOpenMode(transactionOpenMode)); }