use of com.robo4j.db.sql.support.SortType in project robo4j by Robo4J.
the class DefaultRepository method findByFields.
@SuppressWarnings("unchecked")
@Override
public <T> List<T> findByFields(Class<T> clazz, Map<String, Object> map, int limit, SortType sort) {
EntityManager em = dataSourceContext.getEntityManager(clazz);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery(clazz);
Root<T> rs = cq.from(clazz);
List<Predicate> predicates = map.entrySet().stream().map(e -> cb.equal(rs.get(e.getKey()), e.getValue())).collect(Collectors.toList());
CriteriaQuery<T> cq2 = cq.where(predicates.toArray(new Predicate[predicates.size()])).orderBy(getOrderById(cb, rs, sort)).select(rs);
TypedQuery<T> tq = em.createQuery(cq2);
//@formatter:off
return tq.setMaxResults(limit).getResultList();
//@formatter:on
}
Aggregations