All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.phoenix.basic.utils.EntityManagerUtil Maven / Gradle / Ivy

Go to download

对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;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy