Sha256: 1803a41ce05f7adf9b8500e6c070b7d9edeed21e9f654ccbede23a658e54f23d

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

require 'keymap/errors'

module Keymap

  module ConnectionAdapters # :nodoc:

    module TransactionManagement
      # 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.
      def outside_transaction?
        nil
      end

      # Runs the given block in a database transaction, and returns the result
      # of the block.
      def transaction(options = {})
        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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
keymap-0.3.2 lib/keymap/connection_adapters/abstract/transaction_management.rb
keymap-0.3.1 lib/keymap/connection_adapters/abstract/transaction_management.rb
keymap-0.3.0 lib/keymap/connection_adapters/abstract/transaction_management.rb
keymap-0.2.0 lib/keymap/connection_adapters/abstract/transaction_management.rb