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

Included in:
DataMapper::Adapters::AbstractAdapter
Defined in:
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:



171
172
173
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 171

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:



158
159
160
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 158

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:



146
147
148
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 146

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)


194
195
196
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 194

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.



181
182
183
# File 'lib/dm-core/adapters/abstract_adapter.rb', line 181

def within_transaction?
  !current_transaction.nil?
end