br.com.andrewribeiro.ribrest.services.orm.EMFFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Ribrest Show documentation
Show all versions of Ribrest Show documentation
Ribrest Framework - A simple Java framework that truly improve your productivity when developing restful based webservices.
package br.com.andrewribeiro.ribrest.services.orm;
import javax.inject.Inject;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.glassfish.hk2.api.Factory;
/**
*
* @author Andrew Ribeiro
*/
public class EMFFactory implements Factory{
private EntityManagerFactory emf;
@Inject
PersistenceUnitWrapper puw;
@Override
public EntityManagerFactory provide() {
emf = emf != null ? emf : Persistence.createEntityManagerFactory(puw.getPersistenceUnitName());
return emf;
}
@Override
public void dispose(EntityManagerFactory t) {
emf.close();
}
}