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, #user_transaction, #written

Instance Method Summary collapse

Methods inherited from Transaction

#add_record, #after_commit, #after_rollback, #before_commit, #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.



405
406
407
408
409
410
411
412
413
414
415
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 405

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



439
440
441
442
443
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 439

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

#full_rollback?Boolean

Returns:

  • (Boolean)


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

def full_rollback?; false; end

#materialize!Object



417
418
419
420
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 417

def materialize!
  connection.create_savepoint(savepoint_name)
  super
end

#restartObject



422
423
424
425
426
427
428
429
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 422

def restart
  return unless materialized?

  @instrumenter.finish(:restart)
  @instrumenter.start

  connection.rollback_to_savepoint(savepoint_name)
end

#rollbackObject



431
432
433
434
435
436
437
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 431

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