Class TransactionalDatabaseProvider

java.lang.Object
org.litebridge.orm.persistence.TransactionalDatabaseProvider
All Implemented Interfaces:
DatabaseProvider

public final class TransactionalDatabaseProvider extends Object implements DatabaseProvider
A decorator class that wraps a DatabaseProvider to provide transactional support using a TransactionManager.

This class ensures that any database operation is executed with proper transaction management and cleanup logic when necessary.

Responsibilities:

  • Delegates all database operations to the underlying DatabaseProvider.
  • Ensures that transactional contexts are handled properly using the provided TransactionManager.
  • Cleans up the transaction context if it's no longer active and cleanup is required.

Thread Safety:

This class is thread-safe if the provided TransactionManager and DatabaseProvider are thread-safe.

Implementation Details:

  • The class uses a SqlOperationSupplier functional interface to wrap database operations and ensure proper invocation of cleanup logic via the executeAndCleanupIfNeeded(SqlOperationSupplier) method.
  • Transaction cleanup logic is triggered if no active transaction exists in the TransactionManager, and cleanup is deemed necessary.
See Also:
  • Constructor Details

    • TransactionalDatabaseProvider

      public TransactionalDatabaseProvider(TransactionManager transactionManager, DatabaseProvider databaseProvider)
      Constructs a new TransactionalDatabaseProvider with the provided transaction manager and database provider.

      This class is responsible for managing transactional interactions with the underlying database provider.

      Parameters:
      transactionManager - The transaction manager responsible for managing transaction lifecycles.
      databaseProvider - The database provider that executes database operations within transactions.
  • Method Details