Beispiel #1
0
        public async Task SingleCommit(DbCommand command, CancellationToken cancellation)
        {
            NpgsqlTransaction tx = null;

            try
            {
                tx = _connection.BeginTransaction();
                command.Connection = _connection;

                await command.ExecuteNonQueryAsync(cancellation).ConfigureAwait(false);

                await tx.CommitAsync(cancellation).ConfigureAwait(false);
            }
            catch (Exception)
            {
                if (tx != null)
                {
                    await tx.RollbackAsync(cancellation).ConfigureAwait(false);
                }

                // Let the caller deal with retries
                await reopenConnectionIfNecessary(cancellation).ConfigureAwait(false);

                throw;
            }
            finally
            {
                tx?.SafeDispose();
            }
        }