Class LitebridgeTransactionManager

java.lang.Object
org.springframework.transaction.support.AbstractPlatformTransactionManager
org.springframework.jdbc.datasource.DataSourceTransactionManager
org.litebridgedb.spring.LitebridgeTransactionManager
All Implemented Interfaces:
Serializable, ConnectionProvider, TransactionControl, TransactionManager, org.springframework.beans.factory.InitializingBean, org.springframework.transaction.ConfigurableTransactionManager, org.springframework.transaction.PlatformTransactionManager, org.springframework.transaction.support.ResourceTransactionManager, org.springframework.transaction.TransactionManager

public class LitebridgeTransactionManager extends org.springframework.jdbc.datasource.DataSourceTransactionManager implements TransactionManager
Spring-compatible PlatformTransactionManager for Litebridge.

This class extends DataSourceTransactionManager to provide standard JDBC transaction management while implementing Litebridge's TransactionManager interface to allow Litebridge to participate in Spring-managed transactions.

See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager

    org.springframework.transaction.support.AbstractPlatformTransactionManager.SuspendedResourcesHolder
  • Field Summary

    Fields inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager

    logger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • 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.
    void
    Commits the current transaction.
    Provides a transaction-bound managed connection to the underlying database.
    boolean
    Checks if the current transaction is marked as rollback-only.
    boolean
    Checks if there is an active transaction for the current thread.
    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).
    void
    Rolls back the current transaction.

    Methods inherited from class org.springframework.jdbc.datasource.DataSourceTransactionManager

    afterPropertiesSet, doBegin, doCleanupAfterCompletion, doCommit, doGetTransaction, doResume, doRollback, doSetRollbackOnly, doSuspend, getDataSource, getResourceFactory, isEnforceReadOnly, isExistingTransaction, obtainDataSource, prepareTransactionalConnection, setDataSource, setEnforceReadOnly, translateException

    Methods inherited from class org.springframework.transaction.support.AbstractPlatformTransactionManager

    commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionExecutionListeners, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, prepareForCommit, prepareSynchronization, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionExecutionListeners, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.transaction.ConfigurableTransactionManager

    addListener

    Methods inherited from interface org.springframework.transaction.PlatformTransactionManager

    commit, getTransaction, rollback
  • Constructor Details

    • LitebridgeTransactionManager

      public LitebridgeTransactionManager(DataSource dataSource)
  • Method Details

    • begin

      public void begin() throws TransactionException
      Description copied from interface: TransactionManager
      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).

      Specified by:
      begin in interface TransactionManager
      Throws:
      TransactionException - if an error occurs during starting the transaction
    • begin

      public void begin(boolean readOnly, Isolation isolation) throws TransactionException
      Specified by:
      begin in interface TransactionManager
      Throws:
      TransactionException
    • cleanup

      public void cleanup() throws TransactionException
      Description copied from interface: TransactionManager
      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().

      Specified by:
      cleanup in interface TransactionManager
      Throws:
      TransactionException - if an error occurs during cleanup operations
    • requiresCleanup

      public boolean requiresCleanup()
      Description copied from interface: TransactionManager
      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.

      Specified by:
      requiresCleanup in interface TransactionManager
      Returns:
      true if cleanup still needs to be performed, false otherwise
    • addCommitCallback

      public void addCommitCallback(Runnable callback)
      Description copied from interface: TransactionManager
      Adds a Runnable to be executed if the transaction is committed.
      Specified by:
      addCommitCallback in interface TransactionManager
      Parameters:
      callback - The runnable to execute when the transaction is committed.
    • addRollbackCallback

      public void addRollbackCallback(Runnable callback)
      Description copied from interface: TransactionManager
      Adds a Runnable to be executed if the transaction is rolled back.
      Specified by:
      addRollbackCallback in interface TransactionManager
      Parameters:
      callback - The runnable to execute on transaction rollback.
    • commit

      public void commit() throws TransactionException, IllegalStateException
      Description copied from interface: TransactionControl
      Commits the current transaction.

      This method finalises all operations performed during the transaction and applies any changes to the underlying database. After a successful commit, the transaction is no longer active.

      Specified by:
      commit in interface TransactionControl
      Throws:
      TransactionException - if an error occurs during the commit process
      IllegalStateException - if there is no active transaction to commit
    • rollback

      public void rollback() throws TransactionException, IllegalStateException
      Description copied from interface: TransactionControl
      Rolls back the current transaction.

      This method undoes all changes made during the active transaction. It reverts the state of the underlying data store to the point before the transaction began. After a successful rollback, the transaction is no longer active.

      It should be called in cases where the transaction cannot be successfully completed, such as when an error occurs during the operations performed within the transaction.

      Specified by:
      rollback in interface TransactionControl
      Throws:
      TransactionException - if an error occurs during the rollback process
      IllegalStateException - if there is no active transaction to roll back
    • isTransactionActive

      public boolean isTransactionActive()
      Description copied from interface: TransactionControl
      Checks if there is an active transaction for the current thread.

      This method determines whether a transaction has been started and is not yet committed or rolled back.

      Specified by:
      isTransactionActive in interface TransactionControl
      Returns:
      true if a thread-bound transaction is currently active, false otherwise
    • isRollbackOnly

      public boolean isRollbackOnly()
      Description copied from interface: TransactionControl
      Checks if the current transaction is marked as rollback-only. This indicates that the transaction cannot be successfully committed and must be rolled back.
      Specified by:
      isRollbackOnly in interface TransactionControl
      Returns:
      true if the transaction is marked for rollback, false otherwise
    • connection

      public ManagedConnection connection() throws SQLException
      Description copied from interface: ConnectionProvider
      Provides a transaction-bound managed connection to the underlying database.

      This method is typically used to execute database operations within the context of the current transaction (or not, if the connection is in auto-commit mode).

      Transactions themselves (and corresponding Connection lifecycle methods) are managed by a TransactionManager and are not supported by the returned ManagedConnection.

      Specified by:
      connection in interface ConnectionProvider
      Returns:
      a ManagedConnection instance representing the database connection
      Throws:
      SQLException - if an error occurs while obtaining the connection