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
.-
Field Summary
Fields inherited from class io.github.marcopaglio.booking.transaction.handler.TransactionHandler
handler
-
Constructor Summary
ConstructorDescriptionTransactionPostgresHandler
(jakarta.persistence.EntityManager em) Constructs a handler for PostgreSQL transactions using an entity manager to interact with the PostgreSQL database. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Closes the entity manager, if still open.void
Commits changes of the active PostgreSQL transaction via the entity manager.void
Rolls back changes of the active PostgreSQL transaction via the entity manager.void
Starts a new PostgreSQL transaction via the entity manager, if one isn't already active.Methods inherited from class io.github.marcopaglio.booking.transaction.handler.TransactionHandler
getHandler
-
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 classTransactionHandler<jakarta.persistence.EntityManager>
-
commitTransaction
public void commitTransaction()Commits changes of the active PostgreSQL transaction via the entity manager.- Specified by:
commitTransaction
in classTransactionHandler<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 classTransactionHandler<jakarta.persistence.EntityManager>
-
closeHandler
public void closeHandler()Closes the entity manager, if still open.- Specified by:
closeHandler
in classTransactionHandler<jakarta.persistence.EntityManager>
-