com.talanlabs.taskmanager.jpa.DefaultJPAAccess Maven / Gradle / Ivy
The newest version!
package com.talanlabs.taskmanager.jpa;
import com.talanlabs.taskmanager.jpa.model.IBusinessTaskObject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class DefaultJPAAccess implements IJPAAccess {
private final String persistenceUnitName;
private EntityManagerFactory emf;
private EntityManager em;
public DefaultJPAAccess(String persistenceUnitName) {
super();
this.persistenceUnitName = persistenceUnitName;
}
public void start() {
emf = Persistence.createEntityManagerFactory(persistenceUnitName);
em = emf.createEntityManager();
}
public void stop() {
em.close();
emf.close();
}
public final EntityManagerFactory getEntityManagerFactory() {
return emf;
}
@Override
public final EntityManager getEntityManager() {
return em;
}
@Override
public E find(Class businessTaskObject, Long id) {
return getEntityManager().find(businessTaskObject, id);
}
@Override
public Class instanceToClass(E businessTask) {
return (Class) businessTask.getClass();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy