Package org.zkoss.zkplus.jpa
Class JpaUtil
java.lang.Object
org.zkoss.zkplus.jpa.JpaUtil
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCloses the EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope.static voidcloseEntityManager(String puName) Closes the EntityManager of the EntityManagerFactory of the specified puName;static javax.persistence.EntityManagerReturns an EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope.static javax.persistence.EntityManagergetEntityManager(String puName) Returns or create an EntityManager for the specified persistence unit name.static javax.persistence.EntityManagerFactoryCreate or return the default EntityManagerFactory as defined in zk.xml.static javax.persistence.EntityManagerFactorygetEntityManagerFactory(String puName) Create or return the EntityManagerFactory for the specified persistence unit name.static javax.persistence.EntityManagerFactorygetEntityManagerFactory(String puName, Map properties) Create the EntityManagerFactory for the specified persistence unit and defined properties.static javax.persistence.EntityManagergetEntiyManager(String puName, Map properties) Returns an EntityManager for the specified persistence unit name and defined properties.
-
Field Details
-
CONFIG
- See Also:
-
JPA_EMF_MAP
- See Also:
-
JPA_EM_MAP
- See Also:
-
-
Constructor Details
-
JpaUtil
public JpaUtil()
-
-
Method Details
-
getEntityManagerFactory
public static javax.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
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 javax.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 nameproperties- Defined priorities- Returns:
- EntityManagerFactory
-
getEntityManager
public static javax.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
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
Closes the EntityManager of the EntityManagerFactory of the specified puName;- Since:
- 3.0.7
-
getEntiyManager
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 nameproperties- - Defined priorities- Returns:
- EntityManager
-