Class JpaUtil

java.lang.Object
org.zkoss.zkplus.jpa.JpaUtil

public class JpaUtil extends Object
This class is used to create and hold open EntityManagerFactory objects within a Java EE environment.

Applicable to EJB version 3.2.ga or later

Since:
3.0.2
Author:
Jeff
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Closes the EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope.
    static void
    Closes the EntityManager of the EntityManagerFactory of the specified puName;
    static jakarta.persistence.EntityManager
    Returns an EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope.
    static jakarta.persistence.EntityManager
    Returns or create an EntityManager for the specified persistence unit name.
    static jakarta.persistence.EntityManagerFactory
    Create or return the default EntityManagerFactory as defined in zk.xml.
    static jakarta.persistence.EntityManagerFactory
    Create or return the EntityManagerFactory for the specified persistence unit name.
    static jakarta.persistence.EntityManagerFactory
    getEntityManagerFactory(String puName, Map properties)
    Create the EntityManagerFactory for the specified persistence unit and defined properties.
    static jakarta.persistence.EntityManager
    getEntiyManager(String puName, Map properties)
    Returns an EntityManager for the specified persistence unit name and defined properties.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • JpaUtil

      public JpaUtil()
  • Method Details

    • getEntityManagerFactory

      public static jakarta.persistence.EntityManagerFactory getEntityManagerFactory()
      Create or return the default EntityManagerFactory as defined in zk.xml.

      In WEB-INF/zk.xml, add following lines:

      
      <preference>
              <name>JPA.PersistenceUnitName</name>
              <value>PERSISTENCE_UNIT_NAME</value>
      </preference>
       

      Returns:
      EntityManagerFactory
    • getEntityManagerFactory

      public static jakarta.persistence.EntityManagerFactory getEntityManagerFactory(String puName)
      Create or return the EntityManagerFactory for the specified persistence unit name.
      *Notice:If the EntityManagerFactory with specified persistence unit is not created yet, a new one will be created.
      Parameters:
      puName - Persistence unit name
      Returns:
      EntityManagerFactory
    • getEntityManagerFactory

      public static jakarta.persistence.EntityManagerFactory getEntityManagerFactory(String puName, Map properties)
      Create the EntityManagerFactory for the specified persistence unit and defined properties.
      *Notice: It always creates a new EntityManagerFactory unless properties is null.
      Parameters:
      puName - Persistence unit name
      properties - Defined priorities
      Returns:
      EntityManagerFactory
    • getEntityManager

      public static jakarta.persistence.EntityManager getEntityManager()
      Returns an EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope.

      In WEB-INF/zk.xml, add following lines:

      
      <preference>
              <name>JPA.PersistenceUnitName</name>
              <value>PERSISTENCE_UNIT_NAME</value>
      </preference>
       

      Returns:
      EntityManager
    • getEntityManager

      public static jakarta.persistence.EntityManager getEntityManager(String puName)
      Returns or create an EntityManager for the specified persistence unit name.
      *Notice:If the EntityManagerFactory with specified persistence unit is not created before, a new one will be created automatically.

      The EntityManager get by this method is guaranteed to be the same within one Execution for the specified persistence unit name.

      Parameters:
      puName - - Persistence unit name
      Returns:
      EntityManager
    • closeEntityManager

      public static void closeEntityManager()
      Closes the EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope. It is equals to closeEntityManager(null).

      In WEB-INF/zk.xml, add following lines:

      
      <preference>
              <name>JPA.PersistenceUnitName</name>
              <value>PERSISTENCE_UNIT_NAME</value>
      </preference>
       
      Since:
      3.0.7
    • closeEntityManager

      public static void closeEntityManager(String puName)
      Closes the EntityManager of the EntityManagerFactory of the specified puName;
      Since:
      3.0.7
    • getEntiyManager

      public static jakarta.persistence.EntityManager getEntiyManager(String puName, Map properties)
      Returns an EntityManager for the specified persistence unit name and defined properties.
      *Notice: It always creates a new EntityManagerFactory and thus a new EntityManager unless properties is null.
      Parameters:
      puName - - Persistence unit name
      properties - - Defined priorities
      Returns:
      EntityManager