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.



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

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

#begin_isolated_db_transaction(isolation) ⇒ Object

Starts a database transaction.

Parameters:

  • isolation

    the transaction isolation to use



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

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

#commit_db_transactionObject

Commits the current database transaction.



43
44
45
# File 'lib/arjdbc/abstract/transaction_support.rb', line 43

def commit_db_transaction
  log('COMMIT TRANSACTION'.freeze, 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



62
63
64
# File 'lib/arjdbc/abstract/transaction_support.rb', line 62

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



50
51
52
# File 'lib/arjdbc/abstract/transaction_support.rb', line 50

def exec_rollback_db_transaction
  log('ROLLBACK TRANSACTION'.freeze, 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



71
72
73
# File 'lib/arjdbc/abstract/transaction_support.rb', line 71

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



80
81
82
# File 'lib/arjdbc/abstract/transaction_support.rb', line 80

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



12
13
14
# File 'lib/arjdbc/abstract/transaction_support.rb', line 12

def supports_savepoints?
  @connection.supports_savepoints?
end

#supports_transaction_isolation?(level = nil) ⇒ Boolean

Does this adapter support setting the isolation level for a transaction? Unlike 'plain' ActiveRecord we allow checking for concrete transaction isolation level support by the database.

Parameters:

  • level (defaults to: nil)

    optional to check if we support a specific isolation level

Returns:

  • (Boolean)

Since:

  • 1.3.0



22
23
24
25
# File 'lib/arjdbc/abstract/transaction_support.rb', line 22

def supports_transaction_isolation?(level = nil)
  return false unless level
  @connection.supports_transaction_isolation?(level)
end