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.


221
222
223
224
225
226
227
228
229
230
231
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 221

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


249
250
251
252
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 249

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

#full_rollback?Boolean

Returns:

  • (Boolean)

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

def full_rollback?; false; end

#materialize!Object


233
234
235
236
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 233

def materialize!
  connection.create_savepoint(savepoint_name)
  super
end

#restartObject


238
239
240
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 238

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

#rollbackObject


242
243
244
245
246
247
# File 'activerecord/lib/active_record/connection_adapters/abstract/transaction.rb', line 242

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