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

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

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

import java.time.LocalDateTime;
import java.util.function.Function;

import javax.persistence.EntityManager;

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

@RequiredArgsConstructor
public class UpdateQueryBuilder

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); } /** * Update the given entity. * * @return the entity after the update */ public P execute() { return withEntityManager(em -> { LocalDateTime time = DateUtils.nowUtc(); entity.setEditedOn(time); return em.merge(entity); }); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy