Esempio n. 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (CurrentTransaction != null)
                    {
                        CurrentTransaction.Dispose();
                        CurrentTransaction = null;
                    }

                    if (Connection != null)
                    {
                        if (Connection.State != ConnectionState.Closed)
                        {
                            Connection.Close();
                        }

                        Connection.Dispose();
                        Connection = null;
                    }
                }

                disposedValue = true;
            }
        }
 private void DoClose()
 {
     if (m_connectionState != ConnectionState.Closed)
     {
         m_cachedProcedures = null;
         if (CurrentTransaction != null)
         {
             CurrentTransaction.Dispose();
             CurrentTransaction = null;
         }
         if (m_session != null)
         {
             if (m_connectionSettings.Pooling)
             {
                 m_session.ReturnToPool();
             }
             else
             {
                 m_session.DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
             }
             m_session = null;
         }
         SetState(ConnectionState.Closed);
     }
 }
Esempio n. 3
0
        public async Task CommitTransactionAsync(IDbContextTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }
            if (transaction != CurrentTransaction)
            {
                throw new InvalidOperationException($"Transaction {transaction.TransactionId} is not current");
            }

            try
            {
                await SaveChangesAsync();

                transaction.Commit();
            }
            catch
            {
                RollbackTransaction();
                throw;
            }
            finally
            {
                if (CurrentTransaction != null)
                {
                    CurrentTransaction.Dispose();
                    CurrentTransaction = null;
                }
            }
        }
Esempio n. 4
0
        /// <inheritdoc />
        public void Dispose()
        {
            CurrentTransaction?.Dispose();

            DbConnection?.Close();
            DbConnection?.Dispose();
        }
Esempio n. 5
0
 public virtual void Dispose()
 {
     if (CurrentTransaction != null)
     {
         CurrentTransaction.Dispose();
         CurrentTransaction = null;
     }
 }
Esempio n. 6
0
 public virtual void Dispose()
 {
     CurrentTransaction?.Dispose();
     if (_connectionOwned && _connection != null)
     {
         _connection.Dispose();
         _connection  = null;
         _openedCount = 0;
     }
 }
Esempio n. 7
0
 public void Commit()
 {
     CurrentTransaction?.Commit();
     CurrentTransaction?.Dispose();
     if (CurrentConnection?.State == ConnectionState.Open)
     {
         CurrentConnection.Close();
     }
     CurrentConnection?.Dispose();
 }
Esempio n. 8
0
 /// <summary>
 /// 事务回滚
 /// </summary>
 public void Rollback()
 {
     if (CurrentTransaction == null)
     {
         return;
     }
     CurrentTransaction.Rollback();
     CurrentTransaction.Dispose();
     CurrentTransaction = null;
 }
Esempio n. 9
0
 public void Rollback()
 {
     CurrentTransaction?.Rollback();
     CurrentTransaction?.Dispose();
     if (CurrentConnection?.State == ConnectionState.Open)
     {
         CurrentConnection.Close();
     }
     CurrentConnection?.Dispose();
 }
Esempio n. 10
0
        public virtual void Dispose()
        {
            DbContexts.Clear();

            if (CurrentTransaction != null)
            {
                CurrentTransaction.Dispose();
                CurrentTransaction = null;
            }
        }
Esempio n. 11
0
        public virtual void Commit()
        {
            if (CurrentTransaction == null)
            {
                return;
            }
            CurrentTransaction.Complete();

            CurrentTransaction.Dispose();
            CurrentTransaction = null;
        }
Esempio n. 12
0
        /// <summary>
        ///     Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            CurrentTransaction?.Dispose();

            if (_connectionOwned && _connection.HasValue)
            {
                _connection.Value.Dispose();
                _connection.Reset(CreateDbConnection);
                _openedCount = 0;
            }
        }
 public void Dispose()
 {
     if (CurrentTransaction != null)
     {
         CurrentTransaction.Dispose();
     }
     if (_connection.IsValueCreated && _connection.Value.State != ConnectionState.Closed)
     {
         _connection.Value.Close();
     }
 }
Esempio n. 14
0
        public virtual void Dispose(IIocResolver iocResolver)
        {
            foreach (var dbContext in DbContexts)
            {
                iocResolver.Release(dbContext);
            }

            if (CurrentTransaction != null)
            {
                CurrentTransaction.Dispose();
                CurrentTransaction = null;
            }
        }
Esempio n. 15
0
        public void Rollback()
        {
            if (CurrentTransaction == null)
            {
                throw new InvalidOperationException();
            }

            lock (_transactionSyncRoot)
            {
                CurrentTransaction.Rollback();
                CurrentTransaction.Dispose();
                CurrentTransaction = null;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// 保存数据并且提交事务
        /// </summary>
        protected override void CompleteUow()
        {
            SaveChanges();

            if (CurrentTransaction == null)
            {
                return;
            }

            CurrentTransaction.Complete();

            CurrentTransaction.Dispose();
            CurrentTransaction = null;
        }
Esempio n. 17
0
 /// <summary>
 /// Fecha a sessão.
 /// </summary>
 public void Close()
 {
     if (_state == GDASessionState.Open)
     {
         if (CurrentTransaction != null)
         {
             CurrentTransaction.Dispose();
         }
         _currentConnection.Close();
         _currentConnection.Dispose();
         CurrentTransaction = null;
         _currentConnection = null;
         _state             = GDASessionState.Closed;
     }
 }
Esempio n. 18
0
        public void Dispose()
        {
            foreach (var dbContext in DbContexts)
            {
                _dependencyResolver.Release(dbContext);
            }

            DbContexts.Clear();

            if (CurrentTransaction != null)
            {
                CurrentTransaction.Dispose();
                CurrentTransaction = null;
            }
        }
Esempio n. 19
0
 public void RollbackTransaction()
 {
     try
     {
         CurrentTransaction?.Rollback();
     }
     finally
     {
         if (CurrentTransaction != null)
         {
             CurrentTransaction.Dispose();
             CurrentTransaction = null;
         }
     }
 }
 private void DoClose()
 {
     if (m_connectionState != ConnectionState.Closed)
     {
         if (CurrentTransaction != null)
         {
             CurrentTransaction.Dispose();
             CurrentTransaction = null;
         }
         if (m_session != null)
         {
             if (!m_session.ReturnToPool())
             {
                 m_session.Dispose();
             }
             m_session = null;
         }
         SetState(ConnectionState.Closed);
     }
 }
Esempio n. 21
0
        /// <summary>
        /// uow完成后自动释放
        /// </summary>
        protected override void DisposeUow()
        {
            //DbContext.Dispose();

            if (null == Options)
            {
                return;
            }

            if (Options.IsTransactional == true)
            {
                foreach (var dbContext in DbContexts)
                {
                    IocResolver.Release(dbContext);
                }

                DbContexts.Clear();

                if (CurrentTransaction != null)
                {
                    CurrentTransaction.Dispose();
                    CurrentTransaction = null;
                }
            }
            else
            {
                foreach (var activeDbContext in ActiveDbContexts.Values.ToImmutableList())
                {
                    Release(activeDbContext);
                }
            }

            if (CurrentTransaction != null)
            {
                CurrentTransaction.Dispose();
                CurrentTransaction = null;
            }

            ActiveDbContexts.Clear();
        }
Esempio n. 22
0
 public override void Complete()
 {
     lock (_lock)
     {
         _db.SaveChanges();
         if (CurrentTransaction != null)
         {
             try
             {
                 CurrentTransaction.Commit();
             }
             catch (System.Exception)
             {
                 CurrentTransaction.Rollback();
             }
             finally
             {
                 CurrentTransaction.Dispose();
             }
         }
     }
 }
Esempio n. 23
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;
        }
Esempio n. 25
0
 public void Dispose()
 {
     CurrentTransaction?.Dispose();
     CurrentTransaction = null;
     _semaphore?.Dispose();
 }
        public void Dispose()
        {
            CurrentTransaction?.Dispose();

            _realConnection.Dispose();
        }