Package org.flasby.transactions
Class EntityManagerStoreImpl
java.lang.Object
org.flasby.transactions.EntityManagerStoreImpl
- All Implemented Interfaces:
EntityManagerStore
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionjakarta.persistence.EntityManager
Creates an entity manager and stores it in a stack.jakarta.persistence.EntityManager
get()
Looks for the current entity manager and returns it.void
init
(org.jboss.weld.environment.se.events.ContainerInitialized containerInitialized) void
unregister
(jakarta.persistence.EntityManager entityManager) Removes an entity manager from the thread local stack.
-
Constructor Details
-
EntityManagerStoreImpl
public EntityManagerStoreImpl()
-
-
Method Details
-
init
public void init(@Observes org.jboss.weld.environment.se.events.ContainerInitialized containerInitialized) -
get
public jakarta.persistence.EntityManager get()Description copied from interface:EntityManagerStore
Looks for the current entity manager and returns it. If no entity manager was found, this method logs a warn message and returns null. This will cause a NullPointerException in most cases and will cause a stack trace starting from your service method.- Specified by:
get
in interfaceEntityManagerStore
- Returns:
- the currently used entity manager or
null
if none was found
-
createAndRegister
public jakarta.persistence.EntityManager createAndRegister()Creates an entity manager and stores it in a stack. The use of a stack allows to implement transaction with a 'requires new' behaviour.- Specified by:
createAndRegister
in interfaceEntityManagerStore
- Returns:
- the created entity manager
-
unregister
public void unregister(jakarta.persistence.EntityManager entityManager) Removes an entity manager from the thread local stack. It needs to be created using thecreateAndRegister()
method.- Specified by:
unregister
in interfaceEntityManagerStore
- Parameters:
entityManager
- - the entity manager to remove- Throws:
IllegalStateException
- in case the entity manager was not found on the stack
-