Ejemplo n.º 1
0
        public async Task RollbackTransactionAsync(DbTransaction transaction)
        {
            DbConnection connection = transaction.Connection;
            await transaction.RollbackAsync();

            await connection.CloseAsync();

            await transaction.DisposeAsync();

            await connection.DisposeAsync();
        }
Ejemplo n.º 2
0
        public async Task CommitTransactionAsync(DbTransaction transaction)
        {
            DbConnection connection = transaction.Connection;
            await transaction.CommitAsync();

            await connection.CloseAsync();

            await transaction.DisposeAsync();

            await connection.DisposeAsync();
        }
Ejemplo n.º 3
0
        private async Task Initialise()
        {
            if (_transaction != null)
            {
                await _transaction.DisposeAsync();

                _transaction = null;
                ResetRepositories();
            }

            _transaction = await GetDbTransaction();
        }
Ejemplo n.º 4
0
        public async Task <int> ExecuteTransactionAsync(Dictionary <string, object> sqlAndParameters, bool disposeConnection = true)
        {
            DbTransaction dbTransaction = null;

            try
            {
                await this.OpenDBConnectionAsync();

                dbTransaction = await base._dbConnection.BeginTransactionAsync();

                int affectedCollumnsNum = 0;

                foreach (KeyValuePair <string, object> sqlAndParameter in sqlAndParameters)
                {
                    affectedCollumnsNum += await base._dbConnection.ExecuteAsync(sqlAndParameter.Key, sqlAndParameter.Value, dbTransaction);
                }

                await dbTransaction.CommitAsync();

                return(affectedCollumnsNum);
            }
            catch (DbException e)
            {
                await dbTransaction?.RollbackAsync();

                disposeConnection = true;
                throw e;
            }
            catch (Exception e)
            {
                await dbTransaction?.RollbackAsync();

                disposeConnection = true;
                // TODO: Create a Transaction exception.
                throw e;
            }
            finally
            {
                _ = dbTransaction.DisposeAsync();

                if (disposeConnection)
                {
                    _ = base._dbConnection.DisposeAsync();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Clears all the resources associated to the transaction.
        /// </summary>
        private async Task ReleaseTransactionAsync()
        {
            foreach (var state in _collectionStates.Values)
            {
                // IndentityMap is cleared in ReleaseSession()
                state._concurrent?.Clear();
                state._saved?.Clear();
                state._updated?.Clear();
                state._tracked?.Clear();
                state._deleted?.Clear();
                state._maps?.Clear();
            }

            _commands?.Clear();
            _commands = null;

            if (_transaction != null)
            {
                await _transaction.DisposeAsync();

                _transaction = null;
            }
        }
Ejemplo n.º 6
0
 public ValueTask DisposeAsync()
 {
     return(_transaction.DisposeAsync());
 }