Interface TransactionManager

All Superinterfaces:
ConnectionProvider, TransactionControl
All Known Implementing Classes:
DefaultTransactionManager, LitebridgeTransactionManager

public interface TransactionManager extends TransactionControl
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 Type
    Method
    Description
    void
    Adds a Runnable to be executed if the transaction is committed.
    void
    Adds a Runnable to be executed if the transaction is rolled back.
    void
    Begins a new transaction for the current thread.
    void
    begin(boolean readOnly, Isolation isolation)
     
    void
    Performs cleanup operations for the transaction manager, releasing any resources held.
    boolean
    Indicates 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

    connection

    Methods inherited from interface org.litebridgedb.db.spi.tx.TransactionControl

    commit, isRollbackOnly, isTransactionActive, rollback
  • Method Details

    • begin

      void begin() throws TransactionException
      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

      void begin(boolean readOnly, Isolation isolation) throws TransactionException
      Throws:
      TransactionException
    • cleanup

      void cleanup() throws TransactionException
      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() and TransactionControl.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 true if cleanup still needs to be performed, false otherwise.

      Returns:
      true if cleanup still needs to be performed, false otherwise
    • addCommitCallback

      void addCommitCallback(Runnable callback)
      Adds a Runnable to be executed if the transaction is committed.
      Parameters:
      callback - The runnable to execute when the transaction is committed.
    • addRollbackCallback

      void addRollbackCallback(Runnable callback)
      Adds a Runnable to be executed if the transaction is rolled back.
      Parameters:
      callback - The runnable to execute on transaction rollback.