Class: ActiveRecord::ConnectionAdapters::Transaction
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::Transaction
show all
- Defined in:
- lib/active_record/connection_adapters/abstract/transaction.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(connection, options, run_commit_callbacks: false) ⇒ Transaction
Returns a new instance of Transaction.
47
48
49
50
51
52
53
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 47
def initialize(connection, options, run_commit_callbacks: false)
@connection = connection
@state = TransactionState.new
@records = []
@joinable = options.fetch(:joinable, true)
@run_commit_callbacks = run_commit_callbacks
end
|
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
44
45
46
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 44
def connection
@connection
end
|
#joinable=(value) ⇒ Object
Sets the attribute joinable
45
46
47
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 45
def joinable=(value)
@joinable = value
end
|
#records ⇒ Object
Returns the value of attribute records.
44
45
46
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 44
def records
@records
end
|
#savepoint_name ⇒ Object
Returns the value of attribute savepoint_name.
44
45
46
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 44
def savepoint_name
@savepoint_name
end
|
#state ⇒ Object
Returns the value of attribute state.
44
45
46
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 44
def state
@state
end
|
Instance Method Details
#add_record(record) ⇒ Object
55
56
57
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 55
def add_record(record)
records << record
end
|
#before_commit_records ⇒ Object
78
79
80
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 78
def before_commit_records
records.uniq.each(&:before_committed!) if @run_commit_callbacks
end
|
#closed? ⇒ Boolean
98
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 98
def closed?; false; end
|
#commit ⇒ Object
74
75
76
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 74
def commit
@state.set_state(:committed)
end
|
#commit_records ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 82
def commit_records
ite = records.uniq
while record = ite.shift
if @run_commit_callbacks
record.committed!
else
record.add_to_transaction
end
end
ensure
ite.each { |i| i.committed!(should_run_callbacks: false) }
end
|
#full_rollback? ⇒ Boolean
96
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 96
def full_rollback?; true; end
|
#joinable? ⇒ Boolean
97
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 97
def joinable?; @joinable; end
|
#open? ⇒ Boolean
99
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 99
def open?; !closed?; end
|
#rollback ⇒ Object
59
60
61
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 59
def rollback
@state.set_state(:rolledback)
end
|
#rollback_records ⇒ Object
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 63
def rollback_records
ite = records.uniq
while record = ite.shift
record.rolledback!(force_restore_state: full_rollback?)
end
ensure
ite.each do |i|
i.rolledback!(force_restore_state: full_rollback?, should_run_callbacks: false)
end
end
|