Class TransactionPostgresHandler

java.lang.Object
io.github.marcopaglio.booking.transaction.handler.TransactionHandler<jakarta.persistence.EntityManager>
io.github.marcopaglio.booking.transaction.handler.postgres.TransactionPostgresHandler

public class TransactionPostgresHandler extends TransactionHandler<jakarta.persistence.EntityManager>
An implementation of TransactionHandler for using PostgreSQL transactions via EntityManager.
  • Constructor Details

    • TransactionPostgresHandler

      public TransactionPostgresHandler(jakarta.persistence.EntityManager em)
      Constructs a handler for PostgreSQL transactions using an entity manager to interact with the PostgreSQL database.
      Parameters:
      em - the entity manager used to interact with the persistence provider.
  • Method Details

    • startTransaction

      public void startTransaction()
      Starts a new PostgreSQL transaction via the entity manager, if one isn't already active.
      Specified by:
      startTransaction in class TransactionHandler<jakarta.persistence.EntityManager>
    • commitTransaction

      public void commitTransaction()
      Commits changes of the active PostgreSQL transaction via the entity manager.
      Specified by:
      commitTransaction in class TransactionHandler<jakarta.persistence.EntityManager>
    • rollbackTransaction

      public void rollbackTransaction()
      Rolls back changes of the active PostgreSQL transaction via the entity manager. Note: an already committed transaction cannot be rolled back.
      Specified by:
      rollbackTransaction in class TransactionHandler<jakarta.persistence.EntityManager>
    • closeHandler

      public void closeHandler()
      Closes the entity manager, if still open.
      Specified by:
      closeHandler in class TransactionHandler<jakarta.persistence.EntityManager>