use of org.jowidgets.cap.common.api.sort.ISort in project jo-client-platform by jo-source.
the class CriteriaQueryCreator method createReadQuery.
@Override
public Query createReadQuery(final EntityManager entityManager, final List<? extends IBeanKey> parentBeanKeys, final IFilter filter, final List<? extends ISort> sorting, final PARAM_TYPE parameter) {
final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
final CriteriaQuery<?> query = criteriaBuilder.createQuery(beanType);
query.distinct(true);
final Root<?> bean = fillQuery(query, criteriaBuilder, beanType, parentBeanKeys, filter, parameter);
if (sorting != null) {
final List<Order> order = new LinkedList<Order>();
for (final ISort sort : sorting) {
final Path<?> path = getPath(bean, sort.getPropertyName());
// TODO MG fix sorting of joined attributes
if (sort.getSortOrder() == SortOrder.ASC) {
order.add(criteriaBuilder.asc(path));
} else {
order.add(criteriaBuilder.desc(path));
}
}
query.orderBy(order);
}
return entityManager.createQuery(query);
}
Aggregations