class ActiveRecord::ConnectionAdapters::TransactionManager

Experimental RBS support (using type sampling data from the type_fusion project).

# sig/active_record/connection_adapters/abstract/transaction.rbs

class ActiveRecord::ConnectionAdapters::TransactionManager
  def begin_transaction: (isolation: nil, joinable: bool, _lazy: bool) -> (ActiveRecord::ConnectionAdapters::SavepointTransaction | ActiveRecord::ConnectionAdapters::RealTransaction)
  def commit_transaction: () -> nil
  def current_transaction: () -> (ActiveRecord::ConnectionAdapters::RealTransaction | ActiveRecord::ConnectionAdapters::SavepointTransaction | ActiveRecord::ConnectionAdapters::NullTransaction)
  def enable_lazy_transactions!: () -> true
  def lazy_transactions_enabled?: () -> true
  def materialize_transactions: () -> nil
  def rollback_transaction: (?ActiveRecord::ConnectionAdapters::RealTransaction transaction) -> nil
  def within_new_transaction: (isolation: nil, joinable: true) -> nil
end

:nodoc:

def after_failure_actions(transaction, error)

Deallocate invalidated prepared statements outside of the transaction
def after_failure_actions(transaction, error)
  return unless transaction.is_a?(RealTransaction)
  return unless error.is_a?(ActiveRecord::PreparedStatementCacheExpired)
  @connection.clear_cache!
end

def begin_transaction(isolation: nil, joinable: true, _lazy: true)

Experimental RBS support (using type sampling data from the type_fusion project).

def begin_transaction: (isolation: nil, joinable: bool, _lazy: bool) -> (ActiveRecord::ConnectionAdapters::SavepointTransaction | ActiveRecord::ConnectionAdapters::RealTransaction)

This signature was generated using 7 samples from 1 application.

def begin_transaction(isolation: nil, joinable: true, _lazy: true)
  @connection.lock.synchronize do
    run_commit_callbacks = !current_transaction.joinable?
    transaction =
      if @stack.empty?
        RealTransaction.new(
          @connection,
          isolation: isolation,
          joinable: joinable,
          run_commit_callbacks: run_commit_callbacks
        )
      else
        SavepointTransaction.new(
          @connection,
          "active_record_#{@stack.size}",
          @stack.last,
          isolation: isolation,
          joinable: joinable,
          run_commit_callbacks: run_commit_callbacks
        )
      end
    if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && _lazy
      @has_unmaterialized_transactions = true
    else
      transaction.materialize!
    end
    @stack.push(transaction)
    transaction
  end
end

def commit_transaction

Experimental RBS support (using type sampling data from the type_fusion project).

def commit_transaction: () -> nil

This signature was generated using 3 samples from 1 application.

def commit_transaction
  @connection.lock.synchronize do
    transaction = @stack.last
    begin
      transaction.before_commit_records
    ensure
      @stack.pop
    end
    transaction.commit
    transaction.commit_records
  end
end

def current_transaction

Experimental RBS support (using type sampling data from the type_fusion project).

def current_transaction: () -> (ActiveRecord::ConnectionAdapters::RealTransaction | ActiveRecord::ConnectionAdapters::SavepointTransaction | ActiveRecord::ConnectionAdapters::NullTransaction)

This signature was generated using 68 samples from 2 applications.

def current_transaction
  @stack.last || NULL_TRANSACTION
end

def disable_lazy_transactions!

def disable_lazy_transactions!
  materialize_transactions
  @lazy_transactions_enabled = false
end

def enable_lazy_transactions!

Experimental RBS support (using type sampling data from the type_fusion project).

def enable_lazy_transactions!: () -> true

This signature was generated using 12 samples from 1 application.

def enable_lazy_transactions!
  @lazy_transactions_enabled = true
end

def initialize(connection)

:nodoc:
def initialize(connection)
  @stack = []
  @connection = connection
  @has_unmaterialized_transactions = false
  @materializing_transactions = false
  @lazy_transactions_enabled = true
end

def lazy_transactions_enabled?

Experimental RBS support (using type sampling data from the type_fusion project).

def lazy_transactions_enabled?: () -> true

This signature was generated using 10 samples from 1 application.

def lazy_transactions_enabled?
  @lazy_transactions_enabled
end

def materialize_transactions

Experimental RBS support (using type sampling data from the type_fusion project).

def materialize_transactions: () -> nil

This signature was generated using 57 samples from 1 application.

def materialize_transactions
  return if @materializing_transactions
  return unless @has_unmaterialized_transactions
  @connection.lock.synchronize do
    begin
      @materializing_transactions = true
      @stack.each { |t| t.materialize! unless t.materialized? }
    ensure
      @materializing_transactions = false
    end
    @has_unmaterialized_transactions = false
  end
end

def open_transactions

def open_transactions
  @stack.size
end

def rollback_transaction(transaction = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def rollback_transaction: (?ActiveRecord::ConnectionAdapters::RealTransaction transaction) -> nil

This signature was generated using 5 samples from 1 application.

def rollback_transaction(transaction = nil)
  @connection.lock.synchronize do
    transaction ||= @stack.pop
    transaction.rollback unless transaction.state.invalidated?
    transaction.rollback_records
  end
end

def within_new_transaction(isolation: nil, joinable: true)

Experimental RBS support (using type sampling data from the type_fusion project).

def within_new_transaction: (isolation: nil, joinable: true) -> nil

This signature was generated using 2 samples from 1 application.

def within_new_transaction(isolation: nil, joinable: true)
  @connection.lock.synchronize do
    transaction = begin_transaction(isolation: isolation, joinable: joinable)
    ret = yield
    completed = true
    ret
  rescue Exception => error
    if transaction
      transaction.state.invalidate! if error.is_a? ActiveRecord::TransactionRollbackError
      rollback_transaction
      after_failure_actions(transaction, error)
    end
    raise
  ensure
    if transaction
      if error
        # @connection still holds an open or invalid transaction, so we must not
        # put it back in the pool for reuse.
        @connection.throw_away! unless transaction.state.rolledback?
      elsif Thread.current.status == "aborting" || (!completed && transaction.written)
        # The transaction is still open but the block returned earlier.
        #
        # The block could return early because of a timeout or because the thread is aborting,
        # so we are rolling back to make sure the timeout didn't caused the transaction to be
        # committed incompletely.
        rollback_transaction
      else
        begin
          commit_transaction
        rescue Exception
          rollback_transaction(transaction) unless transaction.state.completed?
          raise
        end
      end
    end
  end
end