Class EntityManagerStoreImpl

java.lang.Object
org.flasby.transactions.EntityManagerStoreImpl
All Implemented Interfaces:
EntityManagerStore

@ApplicationScoped public class EntityManagerStoreImpl extends Object implements EntityManagerStore
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    jakarta.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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 interface EntityManagerStore
      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 interface EntityManagerStore
      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 the createAndRegister() method.
      Specified by:
      unregister in interface EntityManagerStore
      Parameters:
      entityManager - - the entity manager to remove
      Throws:
      IllegalStateException - in case the entity manager was not found on the stack