class ActiveRecord::ConnectionAdapters::Transaction

:nodoc:

def add_record(record, ensure_finalize = true)

def add_record(record, ensure_finalize = true)
  @records ||= []
  if ensure_finalize
    @records << record
  else
    @lazy_enrollment_records ||= ObjectSpace::WeakMap.new
    @lazy_enrollment_records[record] = record
  end
end

def before_commit_records

def before_commit_records
  records.uniq.each(&:before_committed!) if records && @run_commit_callbacks
end

def closed?; false; end

def closed?; false; end

def commit_records

def commit_records
  return unless records
  ite = records.uniq(&:__id__)
  already_run_callbacks = {}
  while record = ite.shift
    if @run_commit_callbacks
      trigger_callbacks = record.trigger_transactional_callbacks?
      should_run_callbacks = !already_run_callbacks[record] && trigger_callbacks
      already_run_callbacks[record] ||= trigger_callbacks
      record.committed!(should_run_callbacks: should_run_callbacks)
    else
      # if not running callbacks, only adds the record to the parent transaction
      connection.add_transaction_record(record)
    end
  end
ensure
  ite&.each { |i| i.committed!(should_run_callbacks: false) }
end

def full_rollback?; true; end

def full_rollback?; true; end

def initialize(connection, isolation: nil, joinable: true, run_commit_callbacks: false)

def initialize(connection, isolation: nil, joinable: true, run_commit_callbacks: false)
  @connection = connection
  @state = TransactionState.new
  @records = nil
  @isolation_level = isolation
  @materialized = false
  @joinable = joinable
  @run_commit_callbacks = run_commit_callbacks
  @lazy_enrollment_records = nil
end

def joinable?; @joinable; end

def joinable?; @joinable; end

def materialize!

def materialize!
  @materialized = true
end

def materialized?

def materialized?
  @materialized
end

def open?; !closed?; end

def open?; !closed?; end

def records

def records
  if @lazy_enrollment_records
    @records.concat @lazy_enrollment_records.values
    @lazy_enrollment_records = nil
  end
  @records
end

def rollback_records

def rollback_records
  return unless records
  ite = records.uniq(&:__id__)
  already_run_callbacks = {}
  while record = ite.shift
    trigger_callbacks = record.trigger_transactional_callbacks?
    should_run_callbacks = !already_run_callbacks[record] && trigger_callbacks
    already_run_callbacks[record] ||= trigger_callbacks
    record.rolledback!(force_restore_state: full_rollback?, should_run_callbacks: should_run_callbacks)
  end
ensure
  ite&.each do |i|
    i.rolledback!(force_restore_state: full_rollback?, should_run_callbacks: false)
  end
end