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, #savepoint_name, #state, #written, #written_indirectly

Instance Method Summary collapse

Methods inherited from Transaction

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

Constructor Details

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

Returns a new instance of SavepointTransaction.



285
286
287
288
289
290
291
292
293
294
295
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 285

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



313
314
315
316
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 313

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

#full_rollback?Boolean

Returns:

  • (Boolean)


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

def full_rollback?; false; end

#materialize!Object



297
298
299
300
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 297

def materialize!
  connection.create_savepoint(savepoint_name)
  super
end

#restartObject



302
303
304
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 302

def restart
  connection.rollback_to_savepoint(savepoint_name) if materialized?
end

#rollbackObject



306
307
308
309
310
311
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 306

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