Ejemplo n.º 1
0
        /// <summary>
        /// Creates a connection to the database informed.
        /// </summary>
        /// <param name="dbName">Enumeration of type <see cref="DatabaseName"/>.</param>
        private void InitDbConnection(DatabaseName dbName)
        {
            if (IsEnlisted)
            {
                return;
            }

            if (CurrentConnection != null && CurrentConnection.State != ConnectionState.Closed && CurrentConnection.State != ConnectionState.Broken)
            {
                //if there is a connection opened to another db, throw an exception
                if (CurrentDbName != dbName)
                {
                    throw new DatabaseException($"The repository cannot request a connection to database '{dbName}' because it possesses an open connection to database {CurrentDbName}.");
                }

                //auto-rollback on dispose
                if (CurrentTransaction?.Connection != null)
                {
                    CurrentTransaction.Rollback();
                }

                if (CurrentConnection.State != ConnectionState.Closed || CurrentConnection.State != ConnectionState.Broken)
                {
                    CurrentConnection.Close();

                    CurrentConnection = null;
                }
            }

            CurrentConnection = Context.CreateConnection(dbName);
            CurrentDbName     = dbName;
        }
Ejemplo n.º 2
0
 public void Transaction(Action action)
 {
     lock (this.SyncLock)
     {
         this.AssertValid();
         EnsureTransaction();
         try
         {
             CurrentTransaction.Enlist();
             action();
             CurrentTransaction.Leave();
         }
         catch (Exception)
         {
             CurrentTransaction.Rollback();
             throw;
         }
         finally
         {
             if (!CurrentTransaction.Running)
             {
                 CurrentTransaction = null;
             }
         }
     }
 }
Ejemplo n.º 3
0
 public void RollBackTransaction()
 {
     using (CurrentTransaction)
     {
         CurrentTransaction.Rollback();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 回滚事务
 /// </summary>
 public void Rollback()
 {
     if (IsEnabledTransaction)
     {
         CurrentTransaction.Rollback();
     }
     HasCommitted = true;
 }
Ejemplo n.º 5
0
 public void Rollback()
 {
     if (CurrentTransaction != null)
     {
         CurrentTransaction.Rollback();
         CurrentTransaction = null;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     Discards all changes made to the database in the current transaction.
        /// </summary>
        public virtual void RollbackTransaction()
        {
            if (CurrentTransaction == null)
            {
                throw new InvalidOperationException(RelationalStrings.NoActiveTransaction);
            }

            CurrentTransaction.Rollback();
        }
Ejemplo n.º 7
0
 public void Rollback()
 {
     CurrentTransaction?.Rollback();
     CurrentTransaction?.Dispose();
     if (CurrentConnection?.State == ConnectionState.Open)
     {
         CurrentConnection.Close();
     }
     CurrentConnection?.Dispose();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Rolls back a transaction.
 /// </summary>
 /// <returns></returns>
 public virtual bool rollBack()
 {
     if (CurrentTransaction == null)
     {
         throw new PDOException("No active transaction");
     }
     CurrentTransaction.Rollback();
     CurrentTransaction = null;
     return(true);
 }
Ejemplo n.º 9
0
        public void RollbackTransaction( )
        {
            if (CurrentTransaction == null)
            {
                throw new InvalidOperationException("Can not commit a transaction that has not been started.");
            }

            CurrentTransaction.Rollback();
            CurrentTransaction = null;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 事务回滚
 /// </summary>
 public void Rollback()
 {
     if (CurrentTransaction == null)
     {
         return;
     }
     CurrentTransaction.Rollback();
     CurrentTransaction.Dispose();
     CurrentTransaction = null;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Rolls back a transaction.
        /// </summary>
        /// <returns></returns>
        public virtual bool rollBack()
        {
            if (CurrentTransaction == null)
            {
                HandleError("No active transaction");
                return(false);
            }

            CurrentTransaction.Rollback();
            CurrentTransaction = null;
            return(true);
        }
Ejemplo n.º 12
0
        public void Rollback()
        {
            if (CurrentTransaction == null)
            {
                throw new InvalidOperationException();
            }

            lock (_transactionSyncRoot)
            {
                CurrentTransaction.Rollback();
                CurrentTransaction.Dispose();
                CurrentTransaction = null;
            }
        }
Ejemplo n.º 13
0
 public void RollbackTransaction()
 {
     try
     {
         CurrentTransaction?.Rollback();
     }
     finally
     {
         if (CurrentTransaction != null)
         {
             CurrentTransaction.Dispose();
             CurrentTransaction = null;
         }
     }
 }
Ejemplo n.º 14
0
        public void RollbackTransaction()
        {
            if (!HasOpenTransation())
            {
                throw new Exception("Não existe transação aberta");
            }

            try
            {
                CurrentTransaction.Rollback();
                CurrentTransaction = null;
            }
            finally
            {
                CloseSession();
            }
        }
Ejemplo n.º 15
0
 public override void Complete()
 {
     lock (_lock)
     {
         _db.SaveChanges();
         if (CurrentTransaction != null)
         {
             try
             {
                 CurrentTransaction.Commit();
             }
             catch (System.Exception)
             {
                 CurrentTransaction.Rollback();
             }
             finally
             {
                 CurrentTransaction.Dispose();
             }
         }
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 释放资源
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (!_isDisposed)
     {
         if (Connection != null)
         {
             using (Connection)
             {
                 if (Connection.State != ConnectionState.Closed)
                 {
                     if (CurrentTransaction != null)
                     {
                         CurrentTransaction.Rollback();
                         CurrentTransaction.Dispose();
                     }
                 }
                 Connection.Close();
                 Connection.Dispose();
             }
         }
         this._isDisposed = true;
     }
 }
        // Protected implementation of Dispose pattern.
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                if (_connection is object)
                {
                    if (CurrentTransaction is object)
                    {
                        if (!_committed)
                        {
                            CurrentTransaction.Rollback();
                        }
                        CurrentTransaction.Dispose();
                    }
                    _connection.Dispose();
                }
            }
            disposed = true;
        }
Ejemplo n.º 18
0
 public override void RollbackTransaction() => CurrentTransaction.Rollback();
 public void RollbackTransaction() => CurrentTransaction.Rollback();
Ejemplo n.º 20
0
 public void RollbackTransaction()
 {
     CurrentTransaction?.Rollback();
 }