Module: DataMapper::Adapters::AbstractAdapter::Transaction

Included in:
DataMapper::Adapters::AbstractAdapter
Defined in:
lib/gems/dm-core-0.9.9/lib/dm-core/adapters/abstract_adapter.rb

Overview

TODO: move to dm-more/dm-transaction

Instance Method Summary collapse

Instance Method Details

#current_transactionDataMapper::Transaction

Retrieve the current transaction for this Adapter.

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

TODO: move to dm-more/dm-transaction

Returns:



166
167
168
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/abstract_adapter.rb', line 166

def current_transaction
  transactions(Thread.current).last
end

#pop_transactionDataMapper::Transaction

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.

TODO: move to dm-more/dm-transaction

Returns:



153
154
155
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/abstract_adapter.rb', line 153

def pop_transaction
  transactions(Thread.current).pop
end

#push_transaction(transaction) ⇒ Object

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.

TODO: move to dm-more/dm-transaction

Parameters:



141
142
143
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/abstract_adapter.rb', line 141

def push_transaction(transaction)
  transactions(Thread.current) << transaction
end

#transaction_primitiveObject

Produces a fresh transaction primitive for this Adapter

Used by DataMapper::Transaction to perform its various tasks.

TODO: move to dm-more/dm-transaction (if possible)

Returns:

  • (Object)

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

Raises:

  • (NotImplementedError)


189
190
191
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/abstract_adapter.rb', line 189

def transaction_primitive
  raise NotImplementedError
end

#within_transaction?Boolean

Returns whether we are within a Transaction.

TODO: move to dm-more/dm-transaction

Returns:

  • (Boolean)

    whether we are within a Transaction.



176
177
178
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/adapters/abstract_adapter.rb', line 176

def within_transaction?
  !current_transaction.nil?
end