module DataMapper::Transaction::DataObjectsAdapter

Public Instance Methods

close_connection(connection) click to toggle source

@api semipublic

Calls superclass method
# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 73
def close_connection(connection)
  super unless current_connection.equal?(connection)
end
current_transaction() click to toggle source

Retrieve the current transaction for this Adapter.

Everything done by this Adapter is done within the context of this Transaction.

@return [Transaction]

the 'current' transaction for this Adapter.

@api private

# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 60
def current_transaction
  transactions.last
end
open_connection() click to toggle source

@api semipublic

Calls superclass method
# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 68
def open_connection
  current_connection || super
end
pop_transaction() click to toggle source

Pop the ‘current’ Transaction from the per thread Transaction stack so that everything done by this Adapter is no longer necessarily within the context of said Transaction.

@return [Transaction]

the former 'current' transaction.

@api private

# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 47
def pop_transaction
  transactions.pop
end
push_transaction(transaction) click to toggle source

Pushes the given Transaction onto the per thread Transaction stack so that everything done by this Adapter is done within the context of said Transaction.

@param [Transaction] transaction

a Transaction to be the 'current' transaction until popped.

@return [Array(Transaction)]

the stack of active transactions for the current thread

@api private

# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 35
def push_transaction(transaction)
  transactions << transaction
end
transaction_primitive() click to toggle source

Produces a fresh transaction primitive for this Adapter

Used by Transaction to perform its various tasks.

@return [Object]

a new Object that responds to :close, :begin, :commit,
and :rollback,

@api private

# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 16
def transaction_primitive
  if current_transaction && supports_savepoints?
    DataObjects::SavePoint.create_for_uri(normalized_uri, current_connection)
  else
    DataObjects::Transaction.create_for_uri(normalized_uri)
  end
end

Private Instance Methods

current_connection() click to toggle source

Retrieve the current connection for this Adapter.

@return [Transaction]

the 'current' connection for this Adapter.

@api private

# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 92
def current_connection
  if transaction = current_transaction
    transaction.primitive_for(self).connection
  end
end
supports_savepoints?() click to toggle source

Indicate whether adapter supports transactional savepoints. Not all DO adapters do, so default to false.

@return [Boolean]

whether or not the adapter supports savepoints

@api private

# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 105
def supports_savepoints?
  false
end
transactions() click to toggle source

@api private

# File lib/dm-transactions/adapters/dm-do-adapter.rb, line 81
def transactions
  Thread.current[:dm_transactions]            ||= {}
  Thread.current[:dm_transactions][object_id] ||= []
end