Exemplo n.º 1
0
 internal SuspendedTransaction(TransactionHandleRegistry outerInstance, ActiveTransaction activeMarker, TransactionHandle transactionHandle)
 {
     this._outerInstance              = outerInstance;
     this.ActiveMarker                = activeMarker;
     this.TransactionHandle           = transactionHandle;
     this.LastActiveTimestampConflict = outerInstance.clock.millis();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Rollbacks the transaction.
 /// </summary>
 private static void RollbackTransaction()
 {
     ActiveTransaction.Rollback();
     ActiveTransaction.Dispose();
     ActiveTransaction  = null;
     TransactionCounter = 0;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Rollback active transaction
        /// </summary>
        private static void RolebackTransaction()
        {
            try {
                ActiveTransaction.Rollback();

                if (log.IsWarnEnabled)
                {
                    log.Warn("활성화된 Transaction을 Rollback 했습니다.");
                }
            }
            catch (Exception ex) {
                if (log.IsErrorEnabled)
                {
                    log.Error("Transaction Rollback에 실패했습니다.");
                    log.Error(ex);
                }
            }
            finally {
                if (ActiveTransaction != null)
                {
                    ActiveTransaction.Dispose();
                    ActiveTransaction = null;
                }
                TransactionCount = 0;
            }
        }
Exemplo n.º 4
0
 public void BeginTransaction()
 {
     _call++;
     if (ActiveTransaction == null)
     {
         var connection = GetConnection();
         ActiveTransaction = new ActiveTransaction(connection);
     }
 }
Exemplo n.º 5
0
 public void Rollback()
 {
     if (ActiveTransaction == null)
     {
         throw new InvalidOperationException("No transaction started.");
     }
     ActiveTransaction.Rollback();
     ActiveTransaction = null;
     _call             = 0;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Commits the transaction.
 /// </summary>
 private static void CommitTransaction()
 {
     TransactionCounter--;
     if (TransactionCounter == 0 && ActiveTransaction != null)
     {
         ActiveTransaction.Commit();
         ActiveTransaction.Dispose();
         ActiveTransaction = null;
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Commits the current transaction.
 /// </summary>
 public virtual void Commit()
 {
     EnsureTransactionIsActive();
     try {
         ActiveTransaction.Commit();
     }
     finally {
         ActiveTransaction.Dispose();
         ClearActiveTransaction();
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Rollbacks the current transaction.
 /// </summary>
 public virtual void Rollback()
 {
     EnsureTransactionIsActive();
     try {
         ActiveTransaction.Rollback();
     }
     finally {
         ActiveTransaction.Dispose();
         ClearActiveTransaction();
     }
 }
Exemplo n.º 9
0
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             ActiveConnection.Dispose();
             ActiveTransaction?.Dispose();
         }
     }
     _disposed = true;
 }
Exemplo n.º 10
0
        public void Commit()
        {
            if (ActiveTransaction == null)
            {
                throw new InvalidOperationException("No transaction started.");
            }

            if (_call == 1)
            {
                ActiveTransaction.Commit();
                ActiveTransaction = null;
            }
            _call--;
        }
Exemplo n.º 11
0
        /// <summary>
        /// ADO.NET의 기본 Transaction을 시작한다. (TransactionScope와는 달리 DTC를 이용하지 않는다.)
        /// </summary>
        /// <param name="isolationLevel">Transaction 격리수준 (기본적으로 ReadCommitted)</param>
        /// <returns>Return a new instance of DbTransaction</returns>
        /// <example>
        /// <code>
        /// AdoRepository.BeginTransaction(IsolationLevel.ReadUncommitted);
        /// try
        /// {
        ///     DbCommand insertCommand = AdoRepository.GetSqlStringCommand(InsertString);
        ///     DbCommand deleteCommand = AdoRepository.GetSqlStringCommand(DeleteString);
        ///     DbCommand countCommand = AdoRepository.GetSqlStringCommand(CountString);
        ///
        ///     var count = Convert.ToInt32(AdoRepository.ExecuteScalar(countCommand));
        ///
        ///     AdoRepository.ExecuteNonQuery(insertCommand);
        ///     AdoRepository.ExecuteNonQuery(deleteCommand);
        ///
        ///     AdoRepository.Commit();
        ///
        ///     Assert.AreEqual(4, count);
        /// }
        /// catch (Exception ex)
        /// {
        ///     if (IsErrorEnabled)
        ///         log.ErrorException(ex);
        ///
        ///     AdoRepository.Rollback();
        ///
        ///     throw;
        /// }
        /// </code>
        /// </example>
        public virtual DbTransaction BeginTransaction(System.Data.IsolationLevel isolationLevel)
        {
            var connection = AdoTool.CreateTransactionScopeConnection(Db);

            ActiveTransaction = connection.BeginTransaction(isolationLevel);

            if (IsDebugEnabled)
            {
                log.Debug("Database=[{0}]에 새로운 Transaction을 시작했습니다.  Transaction=[{1}]",
                          connection.Database, ActiveTransaction.GetType().FullName);
            }

            return(ActiveTransaction);
        }
Exemplo n.º 12
0
 /// <inheritdoc/>
 public void Dispose()
 {
     if (isDisposed)
     {
         return;
     }
     isDisposed = true;
     if (ActiveTransaction != null)
     {
         ActiveTransaction.Dispose();
         ClearActiveTransaction();
     }
     UnderlyingConnection.Dispose();
 }
Exemplo n.º 13
0
        /// <summary>
        /// Dispose active transaction
        /// </summary>
        private static void DisposeTransaction()
        {
            if (TransactionCount <= 0)
            {
                if (IsDebugEnabled)
                {
                    log.Debug("활성 Transaction을 Dispose 합니다..");
                }

                if (ActiveTransaction != null)
                {
                    ActiveTransaction.Dispose();
                }
                ActiveTransaction = null;
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Commit transaction
        /// </summary>
        private static void CommitTransaction()
        {
            TransactionCount--;

            if (TransactionCount == 0 && ActiveTransaction != null)
            {
                ActiveTransaction.Commit();
                ActiveTransaction.Dispose();
                ActiveTransaction = null;

                if (log.IsInfoEnabled)
                {
                    log.Info("활성화된 Transaction을 Commit하고 Dispose했습니다.");
                }
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// 提交事务
 /// </summary>
 public void Commit()
 {
     if (wasOpenTransaction)
     {
         try
         {
             ActiveTransaction.Commit();
         }
         catch (Exception)
         {
             ActiveTransaction.Rollback();
             throw;
         }
         finally
         {
             wasOpenTransaction = false;
         }
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Closes the connection to the database. This is the preferred method of closing any open connection.
 /// </summary>
 public override void Close()
 {
     if (_state == ConnectionState.Closed)
     {
         return;
     }
     if (ActiveTransaction != null)
     {
         ActiveTransaction.Rollback();
     }
     ActiveTransaction = null;
     _state            = ConnectionState.Closed;
     if (InnerConnection != null)
     {
         InnerConnection.StateChange -= WrappedConnection_StateChange;
         InnerConnectionFactory.Instance.CloseConnection(_ConnectionString, InnerConnection);
     }
     InnerConnection = null;
     OnStateChange(new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed));
 }
Exemplo n.º 17
0
        /// <summary>
        /// 현재 활성화된 Transaction이 있다면, Commit을 수행한다.
        /// </summary>
        /// <exception cref="InvalidOperationException">Current Thread Context에 활성화된 Transaction이 없을 때</exception>
        public virtual void Commit()
        {
            if (IsActiveTransaction == false)
            {
                if (IsDebugEnabled)
                {
                    log.Debug("활성화된 Transaction이 없으므로 반환합니다.");
                }

                return;
            }

            if (IsActiveTransaction)
            {
                try {
                    ActiveTransaction.Commit();

                    if (log.IsInfoEnabled)
                    {
                        log.Info("Transaction을 Commit 했습니다!!!");
                    }
                }
                catch (Exception ex) {
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorException("Transaction Commit 작업이 실패했습니다.", ex);
                    }

                    throw;
                }
                finally {
                    if (IsActiveTransaction)
                    {
                        ActiveTransaction.Dispose();
                        ActiveTransaction = null;
                    }
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 현재 활성화된 Transaction이 있다면, Rollback을 수행한다.
        /// </summary>
        public virtual void Rollback()
        {
            // Guard.Assert(ActiveTransaction != null, "Active transaction is null.");

            if (IsActiveTransaction == false)
            {
                if (IsDebugEnabled)
                {
                    log.Debug("ActiveTransaction이 없습니다. Rollback을 수행하지 않습니다.");
                }

                return;
            }

            try {
                ActiveTransaction.Rollback();

                if (log.IsInfoEnabled)
                {
                    log.Info("Transaction을 Rollback 했습니다.");
                }
            }
            catch (Exception ex) {
                if (log.IsErrorEnabled)
                {
                    log.ErrorException("Transaction Rollback 작업이 실패했습니다.", ex);
                }
                throw;
            }
            finally {
                if (IsActiveTransaction)
                {
                    ActiveTransaction.Dispose();
                    ActiveTransaction = null;
                }
            }
        }
Exemplo n.º 19
0
 public void Complete()
 {
     PublishDomainEvents(DomainEvents);
     DomainEvents.Clear();
     ActiveTransaction?.Commit();
 }
Exemplo n.º 20
0
 public IDbTransaction GetTransaction() => ActiveTransaction?.GetTransaction();