Search in sources :

Example 6 with ISort

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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) SortOrder(org.jowidgets.cap.common.api.sort.SortOrder) ISort(org.jowidgets.cap.common.api.sort.ISort) LinkedList(java.util.LinkedList)

Aggregations

ISort (org.jowidgets.cap.common.api.sort.ISort)6 LinkedList (java.util.LinkedList)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)3 IBeanDtosUpdate (org.jowidgets.cap.common.api.bean.IBeanDtosUpdate)3 BeanDtosInsertionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate)3 Test (org.junit.Test)3 SortOrder (org.jowidgets.cap.common.api.sort.SortOrder)2 BeanDtosChangeUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Order (javax.persistence.criteria.Order)1 ITextLabelBluePrint (org.jowidgets.api.widgets.blueprint.ITextLabelBluePrint)1 BeanDtosDeletionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosDeletionUpdate)1