Class: ActiveRecord::ConnectionAdapters::SavepointTransaction
- Inherits:
-
Transaction
- Object
- Transaction
- ActiveRecord::ConnectionAdapters::SavepointTransaction
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
#commit ⇒ Object
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
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
|
#restart ⇒ Object
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
|
#rollback ⇒ Object
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
|