Module: Keymap::ConnectionAdapters::TransactionManagement
- Included in:
- AbstractAdapter
- Defined in:
- lib/keymap/connection_adapters/abstract/transaction_management.rb
Instance Method Summary collapse
-
#outside_transaction? ⇒ Boolean
Checks whether there is currently no transaction active.
-
#transaction(options = {}) ⇒ Object
Runs the given block in a database transaction, and returns the result of the block.
Instance Method Details
#outside_transaction? ⇒ Boolean
Checks whether there is currently no transaction active. This is done by querying the database driver, and does not use the transaction house-keeping information recorded by #increment_open_transactions and friends.
Returns true if there is no transaction active, false if there is a transaction active, and nil if this information is unknown.
Not all adapters supports transaction state introspection.
17 18 19 |
# File 'lib/keymap/connection_adapters/abstract/transaction_management.rb', line 17 def outside_transaction? nil end |
#transaction(options = {}) ⇒ Object
Runs the given block in a database transaction, and returns the result of the block.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/keymap/connection_adapters/abstract/transaction_management.rb', line 23 def transaction( = {}) transaction_open = false @_current_transaction_records ||= [] begin if block_given? begin_db_transaction transaction_open = true @_current_transaction_records.push([]) yield end rescue Exception => database_transaction_rollback if transaction_open && !outside_transaction? transaction_open = false rollback_db_transaction end raise unless database_transaction_rollback.is_a?(Rollback) end ensure if transaction_open begin commit_db_transaction rescue Exception => database_transaction_rollback rollback_db_transaction raise end end end |