Module: ArJdbc::Abstract::TransactionSupport
- Included in:
- ActiveRecord::ConnectionAdapters::JdbcAdapter, ActiveRecord::ConnectionAdapters::MSSQLAdapter, ActiveRecord::ConnectionAdapters::Mysql2Adapter, ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, ActiveRecord::ConnectionAdapters::SQLite3Adapter
- Defined in:
- lib/arjdbc/abstract/transaction_support.rb
Overview
Provides the basic interface needed to support transactions for JDBC based adapters
Instance Method Summary collapse
-
#begin_db_transaction ⇒ Object
Starts a database transaction.
-
#begin_isolated_db_transaction(isolation) ⇒ Object
Starts a database transaction.
-
#commit_db_transaction ⇒ Object
Commits the current database transaction.
-
#create_savepoint(name = current_savepoint_name) ⇒ Object
Creates a (transactional) save-point one can rollback to.
-
#exec_rollback_db_transaction ⇒ Object
Rolls back the current database transaction.
-
#exec_rollback_to_savepoint(name = current_savepoint_name) ⇒ Object
Transaction rollback to a given (previously created) save-point.
-
#release_savepoint(name = current_savepoint_name) ⇒ Object
Release a previously created save-point.
-
#supports_savepoints? ⇒ Boolean
Does our database (+ its JDBC driver) support save-points?.
- #supports_transaction_isolation? ⇒ Boolean
Instance Method Details
#begin_db_transaction ⇒ Object
Starts a database transaction.
26 27 28 |
# File 'lib/arjdbc/abstract/transaction_support.rb', line 26 def begin_db_transaction log('BEGIN', 'TRANSACTION') { @connection.begin } end |
#begin_isolated_db_transaction(isolation) ⇒ Object
Starts a database transaction.
32 33 34 |
# File 'lib/arjdbc/abstract/transaction_support.rb', line 32 def begin_isolated_db_transaction(isolation) log("BEGIN ISOLATED - #{isolation}", 'TRANSACTION') { @connection.begin(isolation) } end |
#commit_db_transaction ⇒ Object
Commits the current database transaction.
38 39 40 |
# File 'lib/arjdbc/abstract/transaction_support.rb', line 38 def commit_db_transaction log('COMMIT', 'TRANSACTION') { @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.
57 58 59 |
# File 'lib/arjdbc/abstract/transaction_support.rb', line 57 def create_savepoint(name = current_savepoint_name) log("SAVEPOINT #{name}", 'TRANSACTION') { @connection.create_savepoint(name) } end |
#exec_rollback_db_transaction ⇒ Object
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') { @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
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}", 'TRANSACTION') { @connection.rollback_savepoint(name) } end |
#release_savepoint(name = current_savepoint_name) ⇒ Object
Save-points are auto-released with the transaction they're created
Release a previously created save-point. in (on transaction commit or roll-back).
75 76 77 |
# File 'lib/arjdbc/abstract/transaction_support.rb', line 75 def release_savepoint(name = current_savepoint_name) log("RELEASE SAVEPOINT #{name}", 'TRANSACTION') { @connection.release_savepoint(name) } end |
#supports_savepoints? ⇒ Boolean
Does our database (+ its JDBC driver) support save-points?
14 15 16 |
# File 'lib/arjdbc/abstract/transaction_support.rb', line 14 def supports_savepoints? @connection.supports_savepoints? end |
#supports_transaction_isolation? ⇒ Boolean
18 19 20 |
# File 'lib/arjdbc/abstract/transaction_support.rb', line 18 def supports_transaction_isolation? @connection.supports_transaction_isolation? end |