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.
97
98
99
100
101
102
103
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 97
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.
94
95
96
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 94
def connection
@connection
end
|
#joinable=(value) ⇒ Object
Sets the attribute joinable
95
96
97
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 95
def joinable=(value)
@joinable = value
end
|
#records ⇒ Object
Returns the value of attribute records.
94
95
96
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 94
def records
@records
end
|
#savepoint_name ⇒ Object
Returns the value of attribute savepoint_name.
94
95
96
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 94
def savepoint_name
@savepoint_name
end
|
#state ⇒ Object
Returns the value of attribute state.
94
95
96
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 94
def state
@state
end
|
Instance Method Details
#add_record(record) ⇒ Object
105
106
107
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 105
def add_record(record)
records << record
end
|
#before_commit_records ⇒ Object
120
121
122
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 120
def before_commit_records
records.uniq.each(&:before_committed!) if @run_commit_callbacks
end
|
#closed? ⇒ Boolean
140
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 140
def closed?; false; end
|
#commit_records ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 124
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
138
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 138
def full_rollback?; true; end
|
#joinable? ⇒ Boolean
139
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 139
def joinable?; @joinable; end
|
#open? ⇒ Boolean
141
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 141
def open?; !closed?; end
|
#rollback_records ⇒ Object
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 109
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
|