
org.datafx.crud.jpa.JpaCrudService Maven / Gradle / Ivy
The newest version!
package org.datafx.crud.jpa;
import org.datafx.crud.BasicCrudService;
import org.datafx.util.EntityWithId;
import javax.persistence.EntityManager;
import java.io.Serializable;
import java.util.function.Supplier;
public class JpaCrudService, T extends Serializable> extends BasicCrudService {
private CreateOnceSupplier entityManagerSupplier;
private EntityManager createdManager;
public JpaCrudService(EntityManager entityManager, Class entityClass) {
this(() -> entityManager, entityClass);
}
public JpaCrudService(Supplier entityManagerSupplier, Class entityClass) {
this(new CreateOnceSupplier(entityManagerSupplier), entityClass);
}
public JpaCrudService(CreateOnceSupplier entityManagerSupplier, Class entityClass) {
super(new JpaGetAllCall(entityManagerSupplier, entityClass),
new JpaGetByIdCall(entityManagerSupplier, entityClass),
new JpaDeleteCall(entityManagerSupplier, entityClass),
new JpaPersistCall(entityManagerSupplier),
new JpaUpdateCall(entityManagerSupplier));
this.entityManagerSupplier = entityManagerSupplier;
}
public EntityManager getEntityManager() {
if(createdManager == null) {
createdManager = entityManagerSupplier.get();
}
return createdManager;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy