Module: ArJdbc::Abstract::TransactionSupport

Overview

Provides the basic interface needed to support transactions for JDBC based adapters

Instance Method Summary collapse

Instance Method Details

#begin_db_transactionObject

Starts a database transaction.



26
27
28
# File 'lib/arjdbc/abstract/transaction_support.rb', line 26

def begin_db_transaction
  log('BEGIN TRANSACTION', nil) { @connection.begin }
end

#begin_isolated_db_transaction(isolation) ⇒ Object

Starts a database transaction.

Parameters:

  • isolation

    the transaction isolation to use



32
33
34
# File 'lib/arjdbc/abstract/transaction_support.rb', line 32

def begin_isolated_db_transaction(isolation)
  log("BEGIN ISOLATED TRANSACTION - #{isolation}", nil) { @connection.begin(isolation) }
end

#commit_db_transactionObject

Commits the current database transaction.



38
39
40
# File 'lib/arjdbc/abstract/transaction_support.rb', line 38

def commit_db_transaction
  log('COMMIT TRANSACTION', nil) { @connection.commit }
end

#create_savepoint(name = current_savepoint_name) ⇒ Object

Creates a (transactional) save-point one can rollback to. Unlike 'plain' ActiveRecord it is allowed to pass a save-point name.

Parameters:

  • name (defaults to: current_savepoint_name)

    the save-point name

Returns:

  • save-point name (even if nil passed will be generated)

Since:

  • 1.3.0



57
58
59
# File 'lib/arjdbc/abstract/transaction_support.rb', line 57

def create_savepoint(name = current_savepoint_name)
  log("SAVEPOINT #{name}", 'Savepoint') { @connection.create_savepoint(name) }
end

#exec_rollback_db_transactionObject

Rolls back the current database transaction. Called from 'rollback_db_transaction' in the AbstractAdapter



45
46
47
# File 'lib/arjdbc/abstract/transaction_support.rb', line 45

def exec_rollback_db_transaction
  log('ROLLBACK TRANSACTION', nil) { @connection.rollback }
end

#exec_rollback_to_savepoint(name = current_savepoint_name) ⇒ Object

Transaction rollback to a given (previously created) save-point. If no save-point name given rollback to the last created one. Called from 'rollback_to_savepoint' in AbstractAdapter

Parameters:

  • name (defaults to: current_savepoint_name)

    the save-point name



66
67
68
# File 'lib/arjdbc/abstract/transaction_support.rb', line 66

def exec_rollback_to_savepoint(name = current_savepoint_name)
  log("ROLLBACK TO SAVEPOINT #{name}", 'Savepoint') { @connection.rollback_savepoint(name) }
end

#release_savepoint(name = current_savepoint_name) ⇒ Object

Note:

Save-points are auto-released with the transaction they're created

Release a previously created save-point. in (on transaction commit or roll-back).

Parameters:

  • name (defaults to: current_savepoint_name)

    the save-point name



75
76
77
# File 'lib/arjdbc/abstract/transaction_support.rb', line 75

def release_savepoint(name = current_savepoint_name)
  log("RELEASE SAVEPOINT #{name}", 'Savepoint') { @connection.release_savepoint(name) }
end

#supports_savepoints?Boolean

Does our database (+ its JDBC driver) support save-points?

Returns:

  • (Boolean)

Since:

  • 1.3.0



14
15
16
# File 'lib/arjdbc/abstract/transaction_support.rb', line 14

def supports_savepoints?
  @connection.supports_savepoints?
end

#supports_transaction_isolation?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/arjdbc/abstract/transaction_support.rb', line 18

def supports_transaction_isolation?
  @connection.supports_transaction_isolation?
end