Class TransactionPostgresManager

java.lang.Object
io.github.marcopaglio.booking.transaction.manager.TransactionManager
io.github.marcopaglio.booking.transaction.manager.postgres.TransactionPostgresManager

public class TransactionPostgresManager extends TransactionManager
An implementation of TransactionManager for managing code executed on PostgreSQL within transactions.
  • Constructor Details

    • TransactionPostgresManager

      public TransactionPostgresManager(jakarta.persistence.EntityManagerFactory emf, TransactionHandlerFactory transactionHandlerFactory, ClientRepositoryFactory clientRepositoryFactory, ReservationRepositoryFactory reservationRepositoryFactory)
      Constructs a manager for applying code that uses entity repositories using PostgreSQL transactions.
      Parameters:
      emf - the entity manager factory used to interact with the persistence provider.
      transactionHandlerFactory - the factory to create EntityManager instances.
      clientRepositoryFactory - the factory to create ClientPostgresRepository instances.
      reservationRepositoryFactory - the factory to create ReservationPostgresRepository instances.
  • Method Details

    • doInTransaction

      public <R> R doInTransaction(ClientTransactionCode<R> code) throws TransactionException
      Prepares to execution of code that involves the ClientRepository's method(s) on PostgreSQL in a single transaction.
      Specified by:
      doInTransaction in class TransactionManager
      Type Parameters:
      R - the returned type of executed code.
      Parameters:
      code - the code to execute.
      Returns:
      something depending on execution code.
      Throws:
      TransactionException - if the execution or the commitment of the transaction fails.
    • doInTransaction

      public <R> R doInTransaction(ReservationTransactionCode<R> code) throws TransactionException
      Prepares to execution of code that involves the ReservationRepository's method(s) on PostgreSQL in a single transaction.
      Specified by:
      doInTransaction in class TransactionManager
      Type Parameters:
      R - the returned type of executed code.
      Parameters:
      code - the code to execute.
      Returns:
      something depending on execution code.
      Throws:
      TransactionException - if the execution or the commitment of the transaction fails.
    • doInTransaction

      public <R> R doInTransaction(ClientReservationTransactionCode<R> code) throws TransactionException
      Prepares to execution of code that involves both ClientRepository's and ReservationRepository's methods on PostgreSQL in a single transaction.
      Specified by:
      doInTransaction in class TransactionManager
      Type Parameters:
      R - the returned type of executed code.
      Parameters:
      code - the code to execute.
      Returns:
      something depending on execution code.
      Throws:
      TransactionException - if the execution or the commitment of the transaction fails.