List of usage examples for javax.persistence.criteria CriteriaBuilder min
<N extends Number> Expression<N> min(Expression<N> x);
From source file:org.easy.criteria.CriteriaComposer.java
/** * @param criteriaBuilder/*w w w.j a v a 2 s . co m*/ * @param out */ @SuppressWarnings("unchecked") protected void generateHaving(final CriteriaBuilder criteriaBuilder, final List<Predicate> out) { // log.debug("generateHaving :"); Preconditions.checkNotNull(out); Preconditions.checkNotNull(criteriaBuilder); Preconditions.checkNotNull(root); if (_joins != null && _joins.size() > 0) { Set<Entry<JoinContainer<E>, CriteriaComposer<?>>> allSetJoins = _joins.entrySet(); for (Entry<JoinContainer<E>, CriteriaComposer<?>> joinEntry : allSetJoins) { CriteriaComposer<?> subCriteria = joinEntry.getValue(); if (subCriteria != null) subCriteria.generateHaving(criteriaBuilder, out); } } if (_havings != null) { List<Predicate> andPredicates = new ArrayList<Predicate>(0); List<Predicate> orPredicates = new ArrayList<Predicate>(0); LogicOperator lastOperator = LogicOperator.NONE; for (HavingContainer<E> havingContainer : _havings) { @SuppressWarnings("rawtypes") Expression expression = null; switch (havingContainer.function) { case COUNT: expression = criteriaBuilder.count(root.get(havingContainer.attribute)); break; case AVG: expression = criteriaBuilder.avg(root.get(havingContainer.attribute)); break; case SUM: expression = criteriaBuilder.sum(root.get(havingContainer.attribute)); break; case MAX: expression = criteriaBuilder.max(root.get(havingContainer.attribute)); break; case MIN: expression = criteriaBuilder.min(root.get(havingContainer.attribute)); break; } Predicate predicate = ComparisonOperatorProcessor.process(criteriaBuilder, expression, havingContainer.comparisionOperator, havingContainer.value); if (havingContainer.notOperator != null) predicate = ComparisonOperatorProcessor.negate(criteriaBuilder, predicate); LogicOperator nextOperator = havingContainer.logicOperator; if (nextOperator == LogicOperator.NONE && !nextOperator.equals(lastOperator)) nextOperator = lastOperator; switch (nextOperator) { case AND: case NONE: andPredicates.add(predicate); break; case OR: orPredicates.add(predicate); break; default: throw new java.lang.IllegalStateException( "Unknown operator found " + havingContainer.comparisionOperator.toString()); } lastOperator = nextOperator; } // end for if (andPredicates != null && andPredicates.size() > 0) out.add(criteriaBuilder.and(andPredicates.toArray(new Predicate[andPredicates.size()]))); if (orPredicates != null && orPredicates.size() > 0) out.add(criteriaBuilder.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } // end if }
From source file:org.easy.criteria.CriteriaComposer.java
/** * @param out//www . j a v a2 s . co m */ @SuppressWarnings("unchecked") protected void generateSelect(final CriteriaBuilder criteriaBuilder, final List<Selection<?>> out) { Preconditions.checkNotNull(out); if (multiselect != null && multiselect.size() > 0) { out.addAll(multiselect); } if (_selects != null && _selects.size() > 0) { for (SelectContainer<E> selectContainer : _selects) { if (selectContainer.function == null) { Selection<?> selection = root.get(selectContainer.singularAttribute); selection.alias(selectContainer.alias); out.add(selection); } else { @SuppressWarnings("rawtypes") Expression numExp = null; switch (selectContainer.function) { case COUNT: numExp = criteriaBuilder.count(root.get(selectContainer.singularAttribute)); numExp.alias(selectContainer.alias); break; case AVG: numExp = criteriaBuilder.avg(root.get(selectContainer.singularAttribute)); numExp.alias(selectContainer.alias); break; case SUM: numExp = criteriaBuilder.sum(root.get(selectContainer.singularAttribute)); numExp.alias(selectContainer.alias); break; case MAX: numExp = criteriaBuilder.max(root.get(selectContainer.singularAttribute)); numExp.alias(selectContainer.alias); break; case MIN: numExp = criteriaBuilder.min(root.get(selectContainer.singularAttribute)); numExp.alias(selectContainer.alias); break; } if (numExp != null) out.add(numExp); } } } if (_joins != null) { Set<Entry<JoinContainer<E>, CriteriaComposer<?>>> allSetJoins = _joins.entrySet(); for (Entry<JoinContainer<E>, CriteriaComposer<?>> join : allSetJoins) { CriteriaComposer<?> subCriteria = join.getValue(); if (subCriteria != null) subCriteria.generateSelect(criteriaBuilder, out); } } }