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

org.datafx.crud.jpa.JpaGetAllCall Maven / Gradle / Ivy

The newest version!
package org.datafx.crud.jpa;

import org.datafx.util.EntityWithId;

import javax.persistence.EntityManager;
import java.util.List;
import java.util.function.Supplier;

public class JpaGetAllCall, T> extends JpaCall> {

    private Class entityClass;

    public JpaGetAllCall(Supplier managerSupplier, Class entityClass) {
        super(managerSupplier);
        this.entityClass = entityClass;
    }

    public JpaGetAllCall(EntityManager manager, Class entityClass) {
        this(() -> manager, entityClass);
    }

    @Override
    public List call(Void dummy) throws Exception {
        System.out.println("Select a from " + entityClass.getSimpleName() + " a");
        return getManager()
                .createQuery("Select a from " + entityClass.getSimpleName() + " a", entityClass)
                .getResultList();
    }
}