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
29
30
31
32
# File 'lib/arjdbc/abstract/transaction_support.rb', line 26

def begin_db_transaction
  log('BEGIN', 'TRANSACTION') do
    with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
      conn.begin
    end
  end
end

#begin_isolated_db_transaction(isolation) ⇒ Object

Starts a database transaction.

Parameters:

  • isolation

    the transaction isolation to use



36
37
38
39
40
41
42
# File 'lib/arjdbc/abstract/transaction_support.rb', line 36

def begin_isolated_db_transaction(isolation)
  log("BEGIN ISOLATED - #{isolation}", 'TRANSACTION') do
    with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
      conn.begin(isolation)
    end
  end
end

#commit_db_transactionObject

Commits the current database transaction.



46
47
48
49
50
51
52
# File 'lib/arjdbc/abstract/transaction_support.rb', line 46

def commit_db_transaction
  log('COMMIT', 'TRANSACTION') do
    with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
      conn.commit
    end
  end
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



73
74
75
76
77
78
79
# File 'lib/arjdbc/abstract/transaction_support.rb', line 73

def create_savepoint(name = current_savepoint_name)
  log("SAVEPOINT #{name}", 'TRANSACTION') do
    with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
      conn.create_savepoint(name)
    end
  end
end

#exec_rollback_db_transactionObject

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



57
58
59
60
61
62
63
# File 'lib/arjdbc/abstract/transaction_support.rb', line 57

def exec_rollback_db_transaction
  log('ROLLBACK', 'TRANSACTION') do
    with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
      conn.rollback
    end
  end
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



86
87
88
89
90
91
92
# File 'lib/arjdbc/abstract/transaction_support.rb', line 86

def exec_rollback_to_savepoint(name = current_savepoint_name)
  log("ROLLBACK TO SAVEPOINT #{name}", 'TRANSACTION') do
    with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
      conn.rollback_savepoint(name)
    end
  end
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



99
100
101
102
103
104
105
# File 'lib/arjdbc/abstract/transaction_support.rb', line 99

def release_savepoint(name = current_savepoint_name)
  log("RELEASE SAVEPOINT #{name}", 'TRANSACTION') do
    with_raw_connection(allow_retry: true, materialize_transactions: false) do |conn|
      conn.release_savepoint(name)
    end
  end
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?
  @raw_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?
  @raw_connection.supports_transaction_isolation?
end