org.phoenix.basic.utils.EntityManagerUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of phoenix_db Show documentation
Show all versions of phoenix_db Show documentation
对hibernate4的封装。封装了Druid,通过Druid可以轻量级的对其他数据库进行操作
The newest version!
/**
*
*/
package org.phoenix.basic.utils;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
*
* @author mengfeiyang
*
*/
public class EntityManagerUtil {
private static final String PERSISTENCE_UNIT_NAME = "myPersistence";
private static final EntityManagerFactory ENTITY_MANAGER_FACTORY = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
private static final EntityManager ENTITY_MANAGER;
private EntityManagerUtil(){
}
//创建EntityManager实例
static {
ENTITY_MANAGER = ENTITY_MANAGER_FACTORY.createEntityManager();
}
/*
* 获取EntityManager实例
*/
public static synchronized EntityManager getEntityManagerInstance(){
return ENTITY_MANAGER == null ? ENTITY_MANAGER_FACTORY.createEntityManager() : ENTITY_MANAGER;
}
}