Class Transaction
- All Implemented Interfaces:
ITransaction
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbegin()Begin the transaction - essentially a no-nop, as the transaction is only started when the connection is first acquired.commit()Commit the transactionend()Shutdown the transaction by re-enabling auto commit mode and closing the connection to the database (i.e.Get (creating if none found) the connection associated with this transaction.Get the datasource associated with this transaction.intGet the configured transaction isolation level.Get the savepoints used in this transaction.rollback()Rollback the entire transaction.Rollback the transaction up to the last (named) savepoint.setDataSource(DataSource datasource) Set the datasource associated with this transaction.setIsolationLevel(int isolationLevel) Set isolation level.setSavepoint(Key savepoint) Set a savepoint in the transaction
-
Constructor Details
-
Transaction
Constructor.Note this constructor does NOT accept or open a connecton upon construction. This is so we avoid acquiring connections we don't use; i.e. for a transaction that may never execute a query. Instead, we only open the connection when
getConnection()is first called.- Parameters:
datasource- The datasource associated with this transaction
-
-
Method Details
-
setIsolationLevel
Set isolation level.- Specified by:
setIsolationLevelin interfaceITransaction- Returns:
- The transaction object for chainability.
-
getIsolationLevel
public int getIsolationLevel()Get the configured transaction isolation level.- Specified by:
getIsolationLevelin interfaceITransaction
-
getConnection
Get (creating if none found) the connection associated with this transaction.This method should be called by queries executed inside a transaction body to ensure they run on the correct (transactional) connection. Upon first execution, this method will acquire a connection from the datasource and store it for further use within the transaction.
- Specified by:
getConnectionin interfaceITransaction
-
setDataSource
Set the datasource associated with this transaction.For transactions not initialized with a datasource, allows you to set the datasource after construction.
Will throw an exception if the datasource is already set.
- Specified by:
setDataSourcein interfaceITransaction
-
getDataSource
Get the datasource associated with this transaction.Useful for checking that a given query is using the same datasource as its wrapping transaction.
- Specified by:
getDataSourcein interfaceITransaction
-
begin
Begin the transaction - essentially a no-nop, as the transaction is only started when the connection is first acquired.- Specified by:
beginin interfaceITransaction
-
commit
Commit the transaction- Specified by:
commitin interfaceITransaction- Returns:
- The transaction object for chainability.
-
rollback
Rollback the entire transaction. The transaction will be rolled back to the last committed point, and will ignore any set savepoints.- Specified by:
rollbackin interfaceITransaction- Returns:
- The transaction object for chainability.
-
rollback
Rollback the transaction up to the last (named) savepoint.- Specified by:
rollbackin interfaceITransaction- Parameters:
savepoint- The name of the savepoint to rollback to or NULL for no savepoint.- Returns:
- The transaction object for chainability.
-
setSavepoint
Set a savepoint in the transaction- Specified by:
setSavepointin interfaceITransaction- Parameters:
savepoint- The name of the savepoint- Returns:
- The created JDBC savepoint object or NULL if the savepoint could not be created.
-
end
Shutdown the transaction by re-enabling auto commit mode and closing the connection to the database (i.e. releasing it back to the connection pool from whence it came.)- Specified by:
endin interfaceITransaction- Returns:
- The transaction object for chainability.
-
getSavepoints
Get the savepoints used in this transaction.This method returns a map of savepoint names to their associated savepoint objects, allowing you to manage and rollback to specific points in the transaction.
- Specified by:
getSavepointsin interfaceITransaction- Returns:
- A map of savepoint Keys to JDBC savepoint objects.
- See Also:
-