Class: ActiveRecord::ConnectionAdapters::SavepointTransaction

Inherits:
Transaction show all
Defined in:
activerecord/lib/active_record/connection_adapters/abstract/transaction.rb

Instance Attribute Summary

Attributes inherited from Transaction

#connection, #joinable, #records, #savepoint_name, #state

Instance Method Summary collapse

Methods inherited from Transaction

#add_record, #closed?, #commit_records, #joinable?, #open?, #rollback_records

Constructor Details

#initialize(connection, savepoint_name, options) ⇒ SavepointTransaction

Returns a new instance of SavepointTransaction.


109
110
111
112
113
114
115
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 109

def initialize(connection, savepoint_name, options)
  super(connection, options)
  if options[:isolation]
    raise ActiveRecord::TransactionIsolationError, "cannot set transaction isolation in a nested transaction"
  end
  connection.create_savepoint(@savepoint_name = savepoint_name)
end

Instance Method Details

#commitObject


123
124
125
126
127
128
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 123

def commit
  connection.release_savepoint(savepoint_name)
  super
  parent = connection.transaction_manager.current_transaction
  records.each { |r| parent.add_record(r) }
end

#full_rollback?Boolean

Returns:

  • (Boolean)

130
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 130

def full_rollback?; false; end

#rollbackObject


117
118
119
120
121
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 117

def rollback
  connection.rollback_to_savepoint(savepoint_name)
  super
  rollback_records
end