/// <summary> /// Ensures that all processing actually performed by the given work will /// occur outside of a transaction. /// </summary> /// <param name="work">The work to be performed. </param> /// <param name="session">The session from which this request is originating. </param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param> public static Task DoNonTransactedWorkAsync(IIsolatedWork work, ISessionImplementor session, CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <object>(cancellationToken)); } return(session.Factory.TransactionFactory.ExecuteWorkInIsolationAsync(session, work, false, cancellationToken)); }
/// <summary> /// Executes some work in isolation. /// </summary> /// <param name="session">The NHibernate session</param> /// <param name="work">The work to execute</param> /// <param name="transacted">Whether or not to wrap the work in a transaction</param> public new void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { var connection = (ReliableSqlDbConnection)session.Connection; ReliableAdoTransaction.ExecuteWithRetry(connection, () => base.ExecuteWorkInIsolation(session, work, transacted) ); }
/// <inheritdoc /> public override void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { using (var tx = new TransactionScope(TransactionScopeOption.Suppress)) { base.ExecuteWorkInIsolation(session, work, transacted); tx.Complete(); } }
/// <summary> /// Executes some work in isolation. /// </summary> /// <param name="session">The NHibernate session</param> /// <param name="work">The work to execute</param> /// <param name="transacted">Whether or not to wrap the work in a transaction</param> public new void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { var connection = (ReliableSqlDbConnection)session.Connection; ReliableAdoTransaction.ExecuteWithRetry(connection, () => base.ExecuteWorkInIsolation(session, work, transacted) ); }
public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { using (var tx = new TransactionScope(TransactionScopeOption.Suppress)) { // instead of duplicating the logic, we suppress the DTC transaction and create // our own transaction instead adoNetTransactionFactory.ExecuteWorkInIsolation(session, work, transacted); tx.Complete(); } }
public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { using(var tx = new TransactionScope(TransactionScopeOption.Suppress)) { // instead of duplicating the logic, we suppress the DTC transaction and create // our own transaction instead adoNetTransactionFactory.ExecuteWorkInIsolation(session, work, transacted); tx.Complete(); } }
public async Task ExecuteWorkInIsolationAsync(ISessionImplementor session, IIsolatedWork work, bool transacted, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (var tx = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { // instead of duplicating the logic, we suppress the DTC transaction and create // our own transaction instead await(adoNetTransactionFactory.ExecuteWorkInIsolationAsync(session, work, transacted, cancellationToken)).ConfigureAwait(false); tx.Complete(); } }
public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { throw new NotImplementedException(); }
public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { throw new NotImplementedException(); }
/// <inheritdoc /> public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (work == null) { throw new ArgumentNullException(nameof(work)); } DbConnection connection = null; DbTransaction trans = null; // bool wasAutoCommit = false; try { // We make an exception for SQLite and use the session's connection, // since SQLite only allows one connection to the database. if (session.Factory.Dialect is SQLiteDialect) { connection = session.Connection; } else { connection = session.Factory.ConnectionProvider.GetConnection(); } if (transacted) { trans = connection.BeginTransaction(); // TODO NH: a way to read the autocommit state is needed //if (TransactionManager.GetAutoCommit(connection)) //{ // wasAutoCommit = true; // TransactionManager.SetAutoCommit(connection, false); //} } work.DoWork(connection, trans); if (transacted) { trans.Commit(); //TransactionManager.Commit(connection); } } catch (Exception t) { using (new SessionIdLoggingContext(session.SessionId)) { try { if (trans != null && connection.State != ConnectionState.Closed) { trans.Rollback(); } } catch (Exception ignore) { isolaterLog.Debug("Unable to rollback transaction", ignore); } if (t is HibernateException) { throw; } else if (t is DbException) { throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t, "error performing isolated work"); } else { throw new HibernateException("error performing isolated work", t); } } } finally { //if (transacted && wasAutoCommit) //{ // try // { // // TODO NH: reset autocommit // // TransactionManager.SetAutoCommit(connection, true); // } // catch (Exception) // { // log.Debug("was unable to reset connection back to auto-commit"); // } //} try { trans?.Dispose(); } catch (Exception ignore) { isolaterLog.Warn("Unable to dispose transaction", ignore); } if (session.Factory.Dialect is SQLiteDialect == false) { session.Factory.ConnectionProvider.CloseConnection(connection); } } }
/// <inheritdoc /> public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (work == null) { throw new ArgumentNullException(nameof(work)); } DbConnection connection = null; DbTransaction trans = null; try { // We make an exception for SQLite and use the session's connection, // since SQLite only allows one connection to the database. connection = session.Factory.Dialect is SQLiteDialect ? session.Connection : session.ConnectionManager.GetNewConnection(); if (transacted) { trans = connection.BeginTransaction(); } work.DoWork(connection, trans); if (transacted) { trans.Commit(); } } catch (Exception t) { using (session.BeginContext()) { try { if (trans != null && connection.State != ConnectionState.Closed) { trans.Rollback(); } } catch (Exception ignore) { _isolatorLog.Debug(ignore, "Unable to rollback transaction"); } switch (t) { case HibernateException _: throw; case DbException _: throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t, "error performing isolated work"); default: throw new HibernateException("error performing isolated work", t); } } } finally { try { trans?.Dispose(); } catch (Exception ignore) { _isolatorLog.Warn(ignore, "Unable to dispose transaction"); } if (connection != null && session.Factory.Dialect is SQLiteDialect == false) { session.Factory.ConnectionProvider.CloseConnection(connection); } } }
/// <summary> /// Ensures that all processing actually performed by the given work will /// occur outside of a transaction. /// </summary> /// <param name="work">The work to be performed. </param> /// <param name="session">The session from which this request is originating. </param> public static void DoNonTransactedWork(IIsolatedWork work, ISessionImplementor session) { session.Factory.TransactionFactory.ExecuteWorkInIsolation(session, work, false); }
public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { IDbConnection connection = null; IDbTransaction trans = null; // bool wasAutoCommit = false; try { // We make an exception for SQLite and use the session's connection, // since SQLite only allows one connection to the database. //if (session.Factory.Dialect is SQLiteDialect) // connection = session.Connection; //else connection = session.Factory.ConnectionProvider.GetConnection(); if (transacted) { trans = connection.BeginTransaction(); // TODO NH: a way to read the autocommit state is needed //if (TransactionManager.GetAutoCommit(connection)) //{ // wasAutoCommit = true; // TransactionManager.SetAutoCommit(connection, false); //} } work.DoWork(connection, trans); if (transacted) { trans.Commit(); //TransactionManager.Commit(connection); } } catch { try { if (trans != null && connection.State != ConnectionState.Closed) { trans.Rollback(); } } catch (Exception ignore) { isolaterLog.Debug("unable to release connection on exception [" + ignore + "]"); } } finally { //if (transacted && wasAutoCommit) //{ // try // { // // TODO NH: reset autocommit // // TransactionManager.SetAutoCommit(connection, true); // } // catch (Exception) // { // log.Debug("was unable to reset connection back to auto-commit"); // } //} //if (session.Factory.Dialect is SQLiteDialect == false) session.Factory.ConnectionProvider.CloseConnection(connection); } }
public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, bool transacted) { IDbConnection connection = null; IDbTransaction trans = null; // bool wasAutoCommit = false; try { // We make an exception for SQLite and use the session's connection, // since SQLite only allows one connection to the database. if (session.Factory.Dialect is SQLiteDialect) connection = session.Connection; else connection = session.Factory.ConnectionProvider.GetConnection(); if (transacted) { trans = connection.BeginTransaction(); // TODO NH: a way to read the autocommit state is needed //if (TransactionManager.GetAutoCommit(connection)) //{ // wasAutoCommit = true; // TransactionManager.SetAutoCommit(connection, false); //} } work.DoWork(connection, trans); if (transacted) { trans.Commit(); //TransactionManager.Commit(connection); } } catch (Exception t) { using (new SessionIdLoggingContext(session.SessionId)) { try { if (trans != null && connection.State != ConnectionState.Closed) { trans.Rollback(); } } catch (Exception ignore) { isolaterLog.Debug("unable to release connection on exception [" + ignore + "]"); } if (t is HibernateException) { throw; } else if (t is DbException) { throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t, "error performing isolated work"); } else { throw new HibernateException("error performing isolated work", t); } } } finally { //if (transacted && wasAutoCommit) //{ // try // { // // TODO NH: reset autocommit // // TransactionManager.SetAutoCommit(connection, true); // } // catch (Exception) // { // log.Debug("was unable to reset connection back to auto-commit"); // } //} if (session.Factory.Dialect is SQLiteDialect == false) session.Factory.ConnectionProvider.CloseConnection(connection); } }
/// <inheritdoc /> public override async Task ExecuteWorkInIsolationAsync(ISessionImplementor session, IIsolatedWork work, bool transacted, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (var tx = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) { await(base.ExecuteWorkInIsolationAsync(session, work, transacted, cancellationToken)).ConfigureAwait(false); tx.Complete(); } }
/// <summary> /// Ensures that all processing actually performed by the given work will /// occur outside of a transaction. /// </summary> /// <param name="work">The work to be performed. </param> /// <param name="session">The session from which this request is originating. </param> public static void DoNonTransactedWork(IIsolatedWork work, ISessionImplementor session) { session.Factory.TransactionFactory.ExecuteWorkInIsolation(session, work, false); }
/// <inheritdoc /> public virtual Task ExecuteWorkInIsolationAsync(ISessionImplementor session, IIsolatedWork work, bool transacted, CancellationToken cancellationToken) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (work == null) { throw new ArgumentNullException(nameof(work)); } if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <object>(cancellationToken)); } return(InternalExecuteWorkInIsolationAsync()); async Task InternalExecuteWorkInIsolationAsync() { DbConnection connection = null; DbTransaction trans = null; try { // We make an exception for SQLite and use the session's connection, // since SQLite only allows one connection to the database. connection = session.Factory.Dialect is SQLiteDialect ? session.Connection : await(session.Factory.ConnectionProvider.GetConnectionAsync(cancellationToken)).ConfigureAwait(false); if (transacted) { trans = connection.BeginTransaction(); } await(work.DoWorkAsync(connection, trans, cancellationToken)).ConfigureAwait(false); if (transacted) { trans.Commit(); } } catch (Exception t) { using (session.BeginContext()) { try { if (trans != null && connection.State != ConnectionState.Closed) { trans.Rollback(); } } catch (Exception ignore) { _isolatorLog.Debug(ignore, "Unable to rollback transaction"); } switch (t) { case HibernateException _: throw; case DbException _: throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t, "error performing isolated work"); default: throw new HibernateException("error performing isolated work", t); } } } finally { try { trans?.Dispose(); } catch (Exception ignore) { _isolatorLog.Warn(ignore, "Unable to dispose transaction"); } if (connection != null && session.Factory.Dialect is SQLiteDialect == false) { session.Factory.ConnectionProvider.CloseConnection(connection); } } } }
internal IsolatedWorkAfterTransaction(IIsolatedWork work, ISessionImplementor session) { _work = work; _session = session; }
public Task ExecuteWorkInIsolationAsync(ISessionImplementor session, IIsolatedWork work, bool transacted, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public async Task ExecuteWorkInIsolationAsync(ISessionImplementor session, IIsolatedWork work, bool transacted, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); DbConnection connection = null; DbTransaction trans = null; // bool wasAutoCommit = false; try { // We make an exception for SQLite and use the session's connection, // since SQLite only allows one connection to the database. if (session.Factory.Dialect is SQLiteDialect) { connection = session.Connection; } else { connection = await(session.Factory.ConnectionProvider.GetConnectionAsync(cancellationToken)).ConfigureAwait(false); } if (transacted) { trans = connection.BeginTransaction(); // TODO NH: a way to read the autocommit state is needed //if (TransactionManager.GetAutoCommit(connection)) //{ // wasAutoCommit = true; // TransactionManager.SetAutoCommit(connection, false); //} } await(work.DoWorkAsync(connection, trans, cancellationToken)).ConfigureAwait(false); if (transacted) { trans.Commit(); //TransactionManager.Commit(connection); } } catch (Exception t) { using (new SessionIdLoggingContext(session.SessionId)) { try { if (trans != null && connection.State != ConnectionState.Closed) { trans.Rollback(); } } catch (Exception ignore) { isolaterLog.Debug("unable to release connection on exception [" + ignore + "]"); } if (t is HibernateException) { throw; } else if (t is DbException) { throw ADOExceptionHelper.Convert(session.Factory.SQLExceptionConverter, t, "error performing isolated work"); } else { throw new HibernateException("error performing isolated work", t); } } } finally { //if (transacted && wasAutoCommit) //{ // try // { // // TODO NH: reset autocommit // // TransactionManager.SetAutoCommit(connection, true); // } // catch (Exception) // { // log.Debug("was unable to reset connection back to auto-commit"); // } //} if (session.Factory.Dialect is SQLiteDialect == false) { session.Factory.ConnectionProvider.CloseConnection(connection); } } }