Class JPAContainerFactory

java.lang.Object
com.vaadin.featurepack.data.jpacontainer.JPAContainerFactory

public class JPAContainerFactory extends Object
A factory for creating instances of JPAContainers backed by different default entity providers.
Author:
Jonatan Kronqvist / Vaadin Ltd
  • Constructor Details

    • JPAContainerFactory

      public JPAContainerFactory()
  • Method Details

    • make

      public static <T> JPAContainer<T> make(Class<T> entityClass, jakarta.persistence.EntityManager entityManager)
      Creates a new instance of JPAContainer backed by a CachingMutableLocalEntityProvider. This method should be used if you already know an instance of EntityManager.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      entityManager - the entity manager to use
      Returns:
      a fully configured JPAContainer instance
    • make

      public static <T> JPAContainer<T> make(Class<T> entityClass, String persistenceUnitName)
      Creates a new instance of a JPAContainer backed by a CachingMutableLocalEntityProvider. This method can be used if you do not know and do not need/want to know the instance of EntityManager that is used, which is the case in simplistic instances. An instance of EntityManagerFactory will be created for the persistence unit and used to build entity managers.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      persistenceUnitName - the persistency context to use to create entity managers
      Returns:
      a fully configured JPAContainer instance
    • createEntityManagerForPersistenceUnit

      public static jakarta.persistence.EntityManager createEntityManagerForPersistenceUnit(String name)
      Creates an EntityManager using the cached EntityManagerFactory for the persistence unit. If no entity manager factory exists, one is created before using it to build the entity manager.
      Parameters:
      name - the name of the persistence unit.
      Returns:
      an entity manager for the persistence unit.
    • makeReadOnly

      public static <T> JPAContainer<T> makeReadOnly(Class<T> entityClass, jakarta.persistence.EntityManager entityManager)
      Creates a new instance of JPAContainer backed by a CachingLocalEntityProvider. This method should be used if you already know an instance of EntityManager.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      entityManager - the entity manager to use
      Returns:
      a fully configured JPAContainer instance
    • makeReadOnly

      public static <T> JPAContainer<T> makeReadOnly(Class<T> entityClass, String persistenceUnitName)
      Creates a new instance of JPAContainer backed by a CachingLocalEntityProvider. This method can be used if you do not know and do not need/want to know the instance of EntityManager that is used, which is the case in simplistic instances. An instance of EntityManagerFactory will be created for the persistence unit and used to build entity managers.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      persistenceUnitName - the persistency context to use to create entity managers
      Returns:
      a fully configured JPAContainer instance
    • makeBatchable

      public static <T> JPAContainer<T> makeBatchable(Class<T> entityClass, jakarta.persistence.EntityManager entityManager)
      Creates a new instance of JPAContainer backed by a CachingBatchableLocalEntityProvider. This method should be used if you already know an instance of EntityManager.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      entityManager - the entity manager to use
      Returns:
      a fully configured JPAContainer instance
    • makeBatchable

      public static <T> JPAContainer<T> makeBatchable(Class<T> entityClass, String persistenceUnitName)
      Creates a new instance of JPAContainer backed by a CachingBatchableLocalEntityProvider. This method can be used if you do not know and do not need/want to know the instance of EntityManager that is used, which is the case in simplistic instances. An instance of EntityManagerFactory will be created for the persistence unit and used to build entity managers.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      persistenceUnitName - the persistency context to use to create entity managers
      Returns:
      a fully configured JPAContainer instance
    • makeNonCached

      public static <T> JPAContainer<T> makeNonCached(Class<T> entityClass, jakarta.persistence.EntityManager entityManager)
      Creates a new instance of JPAContainer backed by a MutableLocalEntityProvider. This method should be used if you already know an instance of EntityManager.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      entityManager - the entity manager to use
      Returns:
      a fully configured JPAContainer instance
    • makeNonCached

      public static <T> JPAContainer<T> makeNonCached(Class<T> entityClass, String persistenceUnitName)
      Creates a new instance of JPAContainer backed by a MutableLocalEntityProvider. This method can be used if you do not know and do not need/want to know the instance of EntityManager that is used, which is the case in simplistic instances. An instance of EntityManagerFactory will be created for the persistence unit and used to build entity managers.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      persistenceUnitName - the persistency context to use to create entity managers
      Returns:
      a fully configured JPAContainer instance
    • makeNonCachedReadOnly

      public static <T> JPAContainer<T> makeNonCachedReadOnly(Class<T> entityClass, jakarta.persistence.EntityManager entityManager)
      Creates a new instance of JPAContainer backed by a LocalEntityProvider. This method should be used if you already know an instance of EntityManager.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      entityManager - the entity manager to use
      Returns:
      a fully configured JPAContainer instance
    • makeNonCachedReadOnly

      public static <T> JPAContainer<T> makeNonCachedReadOnly(Class<T> entityClass, String persistenceUnitName)
      Creates a new instance of JPAContainer backed by a LocalEntityProvider. This method can be used if you do not know and do not need/want to know the instance of EntityManager that is used, which is the case in simplistic instances. An instance of EntityManagerFactory will be created for the persistence unit and used to build entity managers.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      persistenceUnitName - the persistency context to use to create entity managers
      Returns:
      a fully configured JPAContainer instance
    • makeNonCachedReadOnlyJndi

      public static <T> JPAContainer<T> makeNonCachedReadOnlyJndi(Class<T> entityClass)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      Returns:
      a fully configured JPAContainer instance
    • makeNonCachedReadOnlyJndi

      public static <T> JPAContainer<T> makeNonCachedReadOnlyJndi(Class<T> entityClass, JndiAddresses jndiAddresses)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      jndiAddresses - to be used to get references to EntityManager and UserTransaction
      Returns:
      a fully configured JPAContainer instance
    • makeNonCachedJndi

      public static <T> JPAContainer<T> makeNonCachedJndi(Class<T> entityClass)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      Returns:
      a fully configured JPAContainer instance
    • makeNonCachedJndi

      public static <T> JPAContainer<T> makeNonCachedJndi(Class<T> entityClass, JndiAddresses jndiAddresses)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      jndiAddresses - to be used to get references to EntityManager and UserTransaction
      Returns:
      a fully configured JPAContainer instance
    • makeJndi

      public static <T> JPAContainer<T> makeJndi(Class<T> entityClass)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      Returns:
      a fully configured JPAContainer instance
    • makeJndi

      public static <T> JPAContainer<T> makeJndi(Class<T> entityClass, JndiAddresses jndiAddresses)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      jndiAddresses - to be used to get references to EntityManager and UserTransaction
      Returns:
      a fully configured JPAContainer instance
    • makeBatchableJndi

      public static <T> JPAContainer<T> makeBatchableJndi(Class<T> entityClass)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      Returns:
      a fully configured JPAContainer instance
    • makeBatchableJndi

      public static <T> JPAContainer<T> makeBatchableJndi(Class<T> entityClass, JndiAddresses jndiAddresses)
      Creates a JPAContainer that uses JNDI lookups to fetch entity manager from "java:comp/env/persistence/em". Container also uses JTA transactions. This type of container commonly suits for JEE6 environment.
      Type Parameters:
      T - the type of entity to be contained in the JPAContainer
      Parameters:
      entityClass - the class of the entity
      jndiAddresses - to be used to get references to EntityManager and UserTransaction
      Returns:
      a fully configured JPAContainer instance