- All Superinterfaces:
ConnectionProvider,TransactionControl
- All Known Implementing Classes:
DefaultTransactionManager,LitebridgeTransactionManager
Defines a contract for managing transactions within an application.
Provides methods to begin, commit, and rollback transactions, as well
as handling transaction-specific behaviors such as callbacks and cleanup.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommitCallback(Runnable callback) Adds aRunnableto be executed if the transaction is committed.voidaddRollbackCallback(Runnable callback) Adds aRunnableto be executed if the transaction is rolled back.voidbegin()Begins a new transaction for the current thread.voidvoidcleanup()Performs cleanup operations for the transaction manager, releasing any resources held.booleanIndicates whether cleanup operations are yet to be performed for the transaction manager (i.e. whether the manager itself "active" and holding onto resources).Methods inherited from interface org.litebridgedb.db.spi.tx.ConnectionProvider
connectionMethods inherited from interface org.litebridgedb.db.spi.tx.TransactionControl
commit, isRollbackOnly, isTransactionActive, rollback
-
Method Details
-
begin
Begins a new transaction for the current thread.This method should be called before performing operations that need to be executed within a transactional context. It ensures that subsequent database interactions are part of the same transaction until it is either committed or rolled back.
This method may be called multiple times (nested).
- Throws:
TransactionException- if an error occurs during starting the transaction
-
begin
- Throws:
TransactionException
-
cleanup
Performs cleanup operations for the transaction manager, releasing any resources held. This method should be called when the transaction manager is no longer needed to ensure proper resource management.This method is idempotent; subsequent calls do nothing after the first cleanup.
This is typically called directly by implementations of
TransactionControl.commit()andTransactionControl.rollback().- Throws:
TransactionException- if an error occurs during cleanup operations
-
requiresCleanup
boolean requiresCleanup()Indicates whether cleanup operations are yet to be performed for the transaction manager (i.e. whether the manager itself "active" and holding onto resources).This method returns
trueif cleanup still needs to be performed,falseotherwise.- Returns:
trueif cleanup still needs to be performed,falseotherwise
-
addCommitCallback
Adds aRunnableto be executed if the transaction is committed.- Parameters:
callback- The runnable to execute when the transaction is committed.
-
addRollbackCallback
Adds aRunnableto be executed if the transaction is rolled back.- Parameters:
callback- The runnable to execute on transaction rollback.
-