io.datafx.crud.jpa.JpaQueryCall Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crud Show documentation
Show all versions of crud Show documentation
Visualizing Enterprise Data in JavaFX
package io.datafx.crud.jpa;
import io.datafx.crud.util.EntityWithId;
import io.datafx.crud.util.QueryParameter;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;
import java.util.function.Supplier;
public class JpaQueryCall, T> extends JpaCall, List> {
private Class entityClass;
private String query;
public JpaQueryCall(Supplier managerSupplier, Class entityClass, String query) {
super(managerSupplier);
this.entityClass = entityClass;
this.query = query;
}
public JpaQueryCall(EntityManager manager, Class entityClass, String query) {
this(() -> manager, entityClass, query);
}
@Override
public List call(List params) throws Exception {
Query queryObject = getManager().createQuery(query);
for(QueryParameter param : params) {
queryObject.setParameter(param.getName(), param.getValue());
}
return queryObject.getResultList();
}
}