Class: ActiveRecord::ConnectionAdapters::TransactionManager
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::TransactionManager
- Defined in:
- lib/active_record/connection_adapters/abstract/transaction.rb
Overview
:nodoc:
Instance Method Summary collapse
- #begin_transaction(options = {}) ⇒ Object
- #commit_transaction ⇒ Object
- #current_transaction ⇒ Object
-
#initialize(connection) ⇒ TransactionManager
constructor
A new instance of TransactionManager.
- #open_transactions ⇒ Object
- #rollback_transaction ⇒ Object
- #within_new_transaction(options = {}) ⇒ Object
Constructor Details
#initialize(connection) ⇒ TransactionManager
Returns a new instance of TransactionManager.
158 159 160 161 |
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 158 def initialize(connection) @stack = [] @connection = connection end |
Instance Method Details
#begin_transaction(options = {}) ⇒ Object
163 164 165 166 167 168 169 170 171 172 |
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 163 def begin_transaction( = {}) transaction = if @stack.empty? RealTransaction.new(@connection, ) else SavepointTransaction.new(@connection, "active_record_#{@stack.size}", ) end @stack.push(transaction) transaction end |
#commit_transaction ⇒ Object
174 175 176 |
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 174 def commit_transaction @stack.pop.commit end |
#current_transaction ⇒ Object
207 208 209 |
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 207 def current_transaction @stack.last || NULL_TRANSACTION end |
#open_transactions ⇒ Object
203 204 205 |
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 203 def open_transactions @stack.size end |
#rollback_transaction ⇒ Object
178 179 180 |
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 178 def rollback_transaction @stack.pop.rollback end |
#within_new_transaction(options = {}) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/active_record/connection_adapters/abstract/transaction.rb', line 182 def within_new_transaction( = {}) transaction = begin_transaction yield rescue Exception => error rollback_transaction if transaction raise ensure unless error if Thread.current.status == 'aborting' rollback_transaction if transaction else begin commit_transaction rescue Exception transaction.rollback unless transaction.state.completed? raise end end end end |