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

info.unterrainer.commons.httpserver.daos.InsertQueryBuilder 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 jakarta.persistence.EntityManager;

import info.unterrainer.commons.rdbutils.Transactions;
import info.unterrainer.commons.rdbutils.entities.BasicJpa;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class InsertQueryBuilder

extends BasicQueryEntityManagerBuilder> { @Getter protected final BasicJpqlDao

dao; protected final P entity; protected V withEntityManager(final Function func) { if (entityManager == null) return Transactions.withNewTransactionReturning(dao.emf, em -> func.apply(em)); return func.apply(entityManager); } /** * Insert the given entity. * * @return the entity after insertion */ public P execute() { return withEntityManager(em -> dao.coreDao.create(em, entity, writeTenantIds)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy