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.



324
325
326
327
328
329
330
331
332
333
334
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 324

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



358
359
360
361
362
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 358

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

#full_rollback?Boolean

Returns:

  • (Boolean)


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

def full_rollback?; false; end

#materialize!Object



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

def materialize!
  connection.create_savepoint(savepoint_name)
  super
end

#restartObject



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

def restart
  return unless materialized?

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

  connection.rollback_to_savepoint(savepoint_name)
end

#rollbackObject



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

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