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, #isolation_level, #records, #savepoint_name, #state

Instance Method Summary collapse

Methods inherited from Transaction

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

Constructor Details

#initialize(connection, savepoint_name, parent_transaction, **options) ⇒ SavepointTransaction

Returns a new instance of SavepointTransaction.



148
149
150
151
152
153
154
155
156
157
158
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 148

def initialize(connection, savepoint_name, parent_transaction, **options)
  super(connection, **options)

  parent_transaction.state.add_child(@state)

  if isolation_level
    raise ActiveRecord::TransactionIsolationError, "cannot set transaction isolation in a nested transaction"
  end

  @savepoint_name = savepoint_name
end

Instance Method Details

#commitObject



170
171
172
173
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 170

def commit
  connection.release_savepoint(savepoint_name) if materialized?
  @state.commit!
end

#full_rollback?Boolean

Returns:

  • (Boolean)


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

def full_rollback?; false; end

#materialize!Object



160
161
162
163
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 160

def materialize!
  connection.create_savepoint(savepoint_name)
  super
end

#rollbackObject



165
166
167
168
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 165

def rollback
  connection.rollback_to_savepoint(savepoint_name) if materialized?
  @state.rollback!
end