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

ch.inftec.ju.ee.db.EntityManagerProvider Maven / Gradle / Ivy

Go to download

Contains helping classes for Unit Testing, supporting CDI and EE features, including DB access

There is a newer version: 4.5.1-11
Show newest version
package ch.inftec.ju.ee.db;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.inftec.ju.db.EmfWork;
import ch.inftec.ju.testing.db.EmfUtilProvider;

/**
 * CDI persistence provider class. Provides a RequestScoped EntityManager instance that can be used
 * for DB tests.
 * @author Martin
 *
 */
public class EntityManagerProvider {
	private Logger logger = LoggerFactory.getLogger(EntityManagerProvider.class);
	
	@Produces
	@RequestScoped
	private EmfWork createEmfWork() {
		return new EmfUtilProvider().createEmfUtil("ju-pu-test", null).startWork();
	}
	
	@Produces
	@RequestScoped
	public EntityManager createEntityManager(EmfWork emfWork) {
		logger.debug("Getting EntityManager from EmfWork");
		return emfWork.getEm();
	}
	
	public void closeEntityManager(@Disposes EmfWork emfWork) {
		logger.debug("Closing EmfWork, disposing EntityManager");
		emfWork.close();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy