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

info.unterrainer.commons.httpserver.daos.JpqlTransactionManager Maven / Gradle / Ivy

There is a newer version: 0.3.14
Show newest version
package info.unterrainer.commons.httpserver.daos;

import java.util.function.Function;

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

import io.javalin.http.Context;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class JpqlTransactionManager implements DaoTransactionManager {

	protected final EntityManagerFactory emf;
	protected final Function entityManagerFactorySupplier;

	@Override
	public DaoTransaction beginTransaction(final Context ctx) {
		EntityManagerFactory emf = this.emf;
		if (entityManagerFactorySupplier != null)
			emf = entityManagerFactorySupplier.apply(ctx);
		EntityManager em = emf.createEntityManager();
		if (!em.getTransaction().isActive())
			em.getTransaction().begin();
		return new JpqlTransaction(em);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy