org.zkoss.zkplus.jpa
Class JpaUtil

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

public class JpaUtil
extends java.lang.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
static java.lang.String CONFIG
           
static java.lang.String JPA_EM_MAP
           
static java.lang.String JPA_EMF_MAP
           
 
Constructor Summary
JpaUtil()
           
 
Method Summary
static void closeEntityManager()
          Closes the EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope.
static void closeEntityManager(java.lang.String puName)
          Closes the EntityManager of the EntityManagerFactory of the specified puName;
static javax.persistence.EntityManager getEntityManager()
          Returns an EntityManager of the default EntityManagerFactory as defined in zk.xml in an Execution scope.
static javax.persistence.EntityManager getEntityManager(java.lang.String puName)
          Returns or create an EntityManager for the specified persistence unit name.
static javax.persistence.EntityManagerFactory getEntityManagerFactory()
          Create or return the default EntityManagerFactory as defined in zk.xml.
static javax.persistence.EntityManagerFactory getEntityManagerFactory(java.lang.String puName)
          Create or return the EntityManagerFactory for the specified persistence unit name.
static javax.persistence.EntityManagerFactory getEntityManagerFactory(java.lang.String puName, java.util.Map properties)
          Create the EntityManagerFactory for the specified persistence unit and defined properties.
static javax.persistence.EntityManager getEntiyManager(java.lang.String puName, java.util.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 Detail

CONFIG

public static final java.lang.String CONFIG
See Also:
Constant Field Values

JPA_EMF_MAP

public static final java.lang.String JPA_EMF_MAP
See Also:
Constant Field Values

JPA_EM_MAP

public static final java.lang.String JPA_EM_MAP
See Also:
Constant Field Values
Constructor Detail

JpaUtil

public JpaUtil()
Method Detail

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

public static javax.persistence.EntityManagerFactory getEntityManagerFactory(java.lang.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 javax.persistence.EntityManagerFactory getEntityManagerFactory(java.lang.String puName,
                                                                             java.util.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 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

public static javax.persistence.EntityManager getEntityManager(java.lang.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(java.lang.String puName)
Closes the EntityManager of the EntityManagerFactory of the specified puName;

Since:
3.0.7

getEntiyManager

public static javax.persistence.EntityManager getEntiyManager(java.lang.String puName,
                                                              java.util.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


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo