package org.jerrymouse.database.jpa;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jerrymouse.database.DaoAdapter;

public final class JPAPMF {
	private static EntityManagerFactory pmfInstance;
	private static Log log = LogFactory.getLog(JPAPMF.class);

	public static EntityManagerFactory get() {
		if (pmfInstance == null) {
			log.debug("pmf:" + DaoAdapter.pmfName);
			pmfInstance = Persistence
					.createEntityManagerFactory(DaoAdapter.pmfName);
		}
		return pmfInstance;
	}

	public static EntityManager getEntityManager() {
		return get().createEntityManager();
	}

	private JPAPMF() {
	}
}
