Example usage for javax.persistence.criteria CriteriaQuery getGroupRestriction

List of usage examples for javax.persistence.criteria CriteriaQuery getGroupRestriction

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaQuery getGroupRestriction.

Prototype

Predicate getGroupRestriction();

Source Link

Document

Return the predicate that corresponds to the restriction(s) over the grouping items, or null if no restrictions have been specified.

Usage

From source file:org.jdal.dao.jpa.JpaUtils.java

/**
 * Copy criteria without selection and order.
 * @param from source Criteria./*w  w  w.  j a v a 2 s  .c om*/
 * @param to destination Criteria.
 */
private static void copyCriteriaWithoutSelectionAndOrder(CriteriaQuery<?> from, CriteriaQuery<?> to) {
    if (isEclipseLink(from) && from.getRestriction() != null) {
        // EclipseLink adds roots from predicate paths to critera. Skip copying 
        // roots as workaround.
    } else {
        // Copy Roots
        for (Root<?> root : from.getRoots()) {
            Root<?> dest = to.from(root.getJavaType());
            dest.alias(getOrCreateAlias(root));
            copyJoins(root, dest);
        }
    }

    to.groupBy(from.getGroupList());
    to.distinct(from.isDistinct());

    if (from.getGroupRestriction() != null)
        to.having(from.getGroupRestriction());

    Predicate predicate = from.getRestriction();
    if (predicate != null)
        to.where(predicate);
}

From source file:com.zero.dao.impl.BaseDaoImpl.java

protected Long count(CriteriaQuery<T> criteriaQuery, List<Filter> filters) {
    Assert.notNull(criteriaQuery);/*from   w ww  .j  a  v  a 2  s .c om*/
    Assert.notNull(criteriaQuery.getSelection());
    Assert.notEmpty(criteriaQuery.getRoots());

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    addRestrictions(criteriaQuery, filters);

    CriteriaQuery<Long> countCriteriaQuery = criteriaBuilder.createQuery(Long.class);

    for (Root<?> root : criteriaQuery.getRoots()) {
        Root<?> dest = countCriteriaQuery.from(root.getJavaType());
        dest.alias(getAlias(root));
        copyJoins(root, dest);
    }

    Root<?> countRoot = getRoot(countCriteriaQuery, criteriaQuery.getResultType());
    countCriteriaQuery.select(criteriaBuilder.count(countRoot.get("id").<String>get("stcd")));

    if (criteriaQuery.getGroupList() != null) {
        countCriteriaQuery.groupBy(criteriaQuery.getGroupList());
    }
    if (criteriaQuery.getGroupRestriction() != null) {
        countCriteriaQuery.having(criteriaQuery.getGroupRestriction());
    }
    if (criteriaQuery.getRestriction() != null) {
        countCriteriaQuery.where(criteriaQuery.getRestriction());
    }
    return entityManager.createQuery(countCriteriaQuery).setFlushMode(FlushModeType.COMMIT).getSingleResult();
}

From source file:net.groupbuy.dao.impl.BaseDaoImpl.java

protected Long count(CriteriaQuery<T> criteriaQuery, List<Filter> filters) {
    Assert.notNull(criteriaQuery);//from w  w  w.  jav  a 2s.  c  o m
    Assert.notNull(criteriaQuery.getSelection());
    Assert.notEmpty(criteriaQuery.getRoots());

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    addRestrictions(criteriaQuery, filters);

    CriteriaQuery<Long> countCriteriaQuery = criteriaBuilder.createQuery(Long.class);
    for (Root<?> root : criteriaQuery.getRoots()) {
        Root<?> dest = countCriteriaQuery.from(root.getJavaType());
        dest.alias(getAlias(root));
        copyJoins(root, dest);
    }

    Root<?> countRoot = getRoot(countCriteriaQuery, criteriaQuery.getResultType());
    countCriteriaQuery.select(criteriaBuilder.count(countRoot));

    if (criteriaQuery.getGroupList() != null) {
        countCriteriaQuery.groupBy(criteriaQuery.getGroupList());
    }
    if (criteriaQuery.getGroupRestriction() != null) {
        countCriteriaQuery.having(criteriaQuery.getGroupRestriction());
    }
    if (criteriaQuery.getRestriction() != null) {
        countCriteriaQuery.where(criteriaQuery.getRestriction());
    }
    return entityManager.createQuery(countCriteriaQuery).setFlushMode(FlushModeType.COMMIT).getSingleResult();
}

From source file:org.agric.oxm.utils.JpaUtils.java

/**
 * Copy Criteria without Selection/*from   ww  w  .  j a va  2 s.  c o  m*/
 * 
 * @param from
 *            source Criteria
 * @param to
 *            destination Criteria
 */
public static void copyCriteriaNoSelection(CriteriaQuery<?> from, CriteriaQuery<?> to) {

    // Copy Roots
    for (Root<?> root : from.getRoots()) {
        Root<?> dest = to.from(root.getJavaType());
        dest.alias(getOrCreateAlias(root));
        copyJoins(root, dest);
    }

    to.groupBy(from.getGroupList());
    to.distinct(from.isDistinct());
    to.having(from.getGroupRestriction());
    to.where(from.getRestriction());
    to.orderBy(from.getOrderList());
}

From source file:org.jboss.pressgang.ccms.filter.utils.JPAUtils.java

/**
 * Copy Criteria without Selection//from   ww  w.  j  a  v a2 s  .c o m
 *
 * @param from source Criteria
 * @param to   destination Criteria
 */
public static void copyCriteriaNoSelection(CriteriaQuery<?> from, CriteriaQuery<?> to) {

    // Copy Roots
    for (Root<?> root : from.getRoots()) {
        Root<?> dest = to.from(root.getJavaType());
        dest.alias(getOrCreateAlias(root));
        copyJoins(root, dest);
    }

    if (from.getGroupList() != null)
        to.groupBy(from.getGroupList());
    to.distinct(from.isDistinct());
    if (from.getGroupRestriction() != null)
        to.having(from.getGroupRestriction());
    if (from.getRestriction() != null)
        to.where(from.getRestriction());
    if (from.getOrderList() != null)
        to.orderBy(from.getOrderList());
}