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.



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

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



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

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

#commit_db_transactionObject

Commits the current database transaction.



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

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



55
56
57
# File 'lib/arjdbc/abstract/transaction_support.rb', line 55

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



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

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



64
65
66
# File 'lib/arjdbc/abstract/transaction_support.rb', line 64

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



73
74
75
# File 'lib/arjdbc/abstract/transaction_support.rb', line 73

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?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/arjdbc/abstract/transaction_support.rb', line 16

def supports_transaction_isolation?
  @connection.supports_transaction_isolation?
end