Class: ActiveRecord::ConnectionAdapters::SavepointTransaction

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

Overview

Active Record Savepoint Transaction

Instance Attribute Summary

Attributes inherited from Transaction

#connection, #isolation_level, #savepoint_name, #state, #written

Instance Method Summary collapse

Methods inherited from Transaction

#add_record, #before_commit_records, #closed?, #commit_records, #dirty!, #dirty?, #incomplete!, #joinable?, #materialized?, #open?, #records, #restartable?, #restore!, #rollback_records

Constructor Details

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

Returns a new instance of SavepointTransaction.



317
318
319
320
321
322
323
324
325
326
327
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 317

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



351
352
353
354
355
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 351

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

#full_rollback?Boolean

Returns:

  • (Boolean)


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

def full_rollback?; false; end

#materialize!Object



329
330
331
332
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 329

def materialize!
  connection.create_savepoint(savepoint_name)
  super
end

#restartObject



334
335
336
337
338
339
340
341
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 334

def restart
  return unless materialized?

  @instrumenter.finish
  @instrumenter.start

  connection.rollback_to_savepoint(savepoint_name)
end

#rollbackObject



343
344
345
346
347
348
349
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 343

def rollback
  unless @state.invalidated?
    connection.rollback_to_savepoint(savepoint_name) if materialized?
  end
  @state.rollback!
  @instrumenter.finish
end