Java Code Examples for javax.persistence.criteria.CriteriaBuilder#lessThanOrEqualTo()
The following examples show how to use
javax.persistence.criteria.CriteriaBuilder#lessThanOrEqualTo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CmsPlan.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private Predicate documentPredicate_date(CriteriaBuilder cb, Root<Document> root) throws Exception { if (null == this.dateRange || (!this.dateRange.available())) { return null; } Expression var1 = root.get(Document_.publishTime); if(this.draft){ var1 = root.get(Document_.updateTime); } if (null == this.dateRange.start) { return cb.lessThanOrEqualTo(var1, this.dateRange.completed); } else if (null == this.dateRange.completed) { return cb.greaterThanOrEqualTo(var1, this.dateRange.start); } else { return cb.between(var1, this.dateRange.start, this.dateRange.completed); } }
Example 2
Source File: Calendar_EventFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listNeedAlarmEventIds(Date date) throws Exception { EntityManager em = this.entityManagerContainer().get(Calendar_Event.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Calendar_Event> root = cq.from(Calendar_Event.class); Predicate p = cb.lessThanOrEqualTo( root.get(Calendar_Event_.alarmTime), date ); p = cb.and( p, cb.isFalse( root.get(Calendar_Event_.alarmAlready ) )); cq.select(root.get(Calendar_Event_.id)); return em.createQuery(cq.where(p)).getResultList(); }
Example 3
Source File: ProcessPlatformPlan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Predicate workPredicate_date(CriteriaBuilder cb, Root<Work> root) throws Exception { if (null == this.dateRange || (!this.dateRange.available())) { return null; } if (null == this.dateRange.start) { return cb.lessThanOrEqualTo(root.get(Work_.startTime), this.dateRange.completed); } else if (null == this.dateRange.completed) { return cb.greaterThanOrEqualTo(root.get(Work_.startTime), this.dateRange.start); } else { return cb.between(root.get(Work_.startTime), this.dateRange.start, this.dateRange.completed); } }
Example 4
Source File: ProcessPlatformPlan.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Predicate workCompletedPredicate_date(CriteriaBuilder cb, Root<WorkCompleted> root) throws Exception { if (null == this.dateRange || (!this.dateRange.available())) { return null; } if (null == this.dateRange.start) { return cb.lessThanOrEqualTo(root.get(WorkCompleted_.completedTime), this.dateRange.completed); } else if (null == this.dateRange.completed) { return cb.greaterThanOrEqualTo(root.get(WorkCompleted_.startTime), this.dateRange.start); } else { return cb.and(cb.greaterThanOrEqualTo(root.get(WorkCompleted_.startTime), this.dateRange.start), cb.lessThanOrEqualTo(root.get(WorkCompleted_.completedTime), this.dateRange.completed)); } }
Example 5
Source File: RangeSpecification.java From docs-manage with MIT License | 5 votes |
@SuppressWarnings("unchecked") private Predicate buildRangePredicate(Range<T> range, Root<T> root, CriteriaBuilder cb) { if (range.isBetween()) { return cb.between(root.get(range.getField()), range.getFrom(), range.getTo()); } else if (range.isFromSet()) { return cb.greaterThanOrEqualTo(root.get(range.getField()), range.getFrom()); } else if (range.isToSet()) { return cb.lessThanOrEqualTo(root.get(range.getField()), range.getTo()); } return null; }
Example 6
Source File: Calendar_EventFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listNeedAlarmEventIds(Date date) throws Exception { EntityManager em = this.entityManagerContainer().get(Calendar_Event.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Calendar_Event> root = cq.from(Calendar_Event.class); Predicate p = cb.lessThanOrEqualTo( root.get(Calendar_Event_.alarmTime), date ); p = cb.and( p, cb.isFalse( root.get(Calendar_Event_.alarmAlready ) )); cq.select(root.get(Calendar_Event_.id)); return em.createQuery(cq.where(p)).getResultList(); }
Example 7
Source File: RdbmsUtils.java From modeldb with Apache License 2.0 | 5 votes |
/** * Return the where clause predicate based on given parameters * * @param builder : Hibernate criteria builder * @param valueExpression : field value path for criteria query * @param operator : operator like EQ, GTE, LE etc. * @param operatorValue : field value which set to where clause based on field, Operator and this * value * @return {@link Predicate} : return predicate (where clause condition) for criteria query */ private static Predicate getOperatorPredicate( CriteriaBuilder builder, Expression valueExpression, Operator operator, Object operatorValue) { switch (operator.ordinal()) { case Operator.GT_VALUE: return builder.greaterThan(valueExpression, (Comparable) operatorValue); case Operator.GTE_VALUE: return builder.greaterThanOrEqualTo(valueExpression, (Comparable) operatorValue); case Operator.LT_VALUE: return builder.lessThan(valueExpression, (Comparable) operatorValue); case Operator.LTE_VALUE: return builder.lessThanOrEqualTo(valueExpression, (Comparable) operatorValue); case Operator.NE_VALUE: return builder.notEqual(valueExpression, operatorValue); case Operator.CONTAIN_VALUE: return builder.like( builder.lower(valueExpression), ("%" + Pattern.compile((String) operatorValue) + "%").toLowerCase()); case Operator.NOT_CONTAIN_VALUE: return builder.notLike( builder.lower(valueExpression), ("%" + Pattern.compile((String) operatorValue) + "%").toLowerCase()); case Operator.IN_VALUE: return valueExpression.in(operatorValue); default: return builder.equal(valueExpression, operatorValue); } }
Example 8
Source File: ByRangeUtil.java From javaee-lab with Apache License 2.0 | 5 votes |
private static <D extends Comparable<? super D>, E> Predicate buildRangePredicate(Range<E, D> range, Root<E> root, CriteriaBuilder builder) { Predicate rangePredicate = null; Path<D> path = JpaUtil.getInstance().getPath(root, range.getAttributes()); if (range.isBetween()) { rangePredicate = builder.between(path, range.getFrom(), range.getTo()); } else if (range.isFromSet()) { rangePredicate = builder.greaterThanOrEqualTo(path, range.getFrom()); } else if (range.isToSet()) { rangePredicate = builder.lessThanOrEqualTo(path, range.getTo()); } if (rangePredicate != null) { if (!range.isIncludeNullSet() || range.getIncludeNull() == FALSE) { return rangePredicate; } else { return builder.or(rangePredicate, builder.isNull(path)); } } else { // no from/to is set, but include null or not could be: if (TRUE == range.getIncludeNull()) { return builder.isNull(path); } else if (FALSE == range.getIncludeNull()) { return builder.isNotNull(path); } } return null; }
Example 9
Source File: LeRestriction.java From base-framework with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public Predicate build(Path expression, Object value,CriteriaBuilder builder) { return builder.lessThanOrEqualTo(expression, (Comparable)value); }
Example 10
Source File: Condition.java From activejpa with Apache License 2.0 | 4 votes |
@Override Predicate createPredicate(CriteriaBuilder builder, Path path, Expression... parameter) { return builder.lessThanOrEqualTo(path, parameter[0]); }
Example 11
Source File: GenericRsqlSpecification.java From tutorials with MIT License | 4 votes |
@Override public Predicate toPredicate(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) { final List<Object> args = castArguments(root); final Object argument = args.get(0); switch (RsqlSearchOperation.getSimpleOperator(operator)) { case EQUAL: { if (argument instanceof String) { return builder.like(root.get(property), argument.toString().replace('*', '%')); } else if (argument == null) { return builder.isNull(root.get(property)); } else { return builder.equal(root.get(property), argument); } } case NOT_EQUAL: { if (argument instanceof String) { return builder.notLike(root.<String> get(property), argument.toString().replace('*', '%')); } else if (argument == null) { return builder.isNotNull(root.get(property)); } else { return builder.notEqual(root.get(property), argument); } } case GREATER_THAN: { return builder.greaterThan(root.<String> get(property), argument.toString()); } case GREATER_THAN_OR_EQUAL: { return builder.greaterThanOrEqualTo(root.<String> get(property), argument.toString()); } case LESS_THAN: { return builder.lessThan(root.<String> get(property), argument.toString()); } case LESS_THAN_OR_EQUAL: { return builder.lessThanOrEqualTo(root.<String> get(property), argument.toString()); } case IN: return root.get(property).in(args); case NOT_IN: return builder.not(root.get(property).in(args)); } return null; }
Example 12
Source File: LessThanOrEqual.java From specification-arg-resolver with Apache License 2.0 | 4 votes |
@Override protected <Y extends Comparable<? super Y>> Predicate makePredicate(CriteriaBuilder cb, Expression<? extends Y> x, Y y) { return cb.lessThanOrEqualTo(x, y); }
Example 13
Source File: DateBeforeInclusive.java From specification-arg-resolver with Apache License 2.0 | 4 votes |
@Override public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return cb.lessThanOrEqualTo(this.<Date>path(root), date); }
Example 14
Source File: AuditRecordRepositoryImpl.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override public Page<AuditRecord> findByActionTypeAndOperationTypeAndDate(AuditOperationType[] operations, AuditActionType[] actions, Instant fromDate, Instant toDate, Pageable pageable) { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final CriteriaQuery<AuditRecord> query = cb.createQuery(AuditRecord.class); final Root<AuditRecord> auditRecordRoot = query.from(AuditRecord.class); final Path<AuditActionType> auditAction = auditRecordRoot.get("auditAction"); final Path<AuditOperationType> auditOperation = auditRecordRoot.get("auditOperation"); final Path<Instant> createdOn = auditRecordRoot.get("createdOn"); final Predicate datePredicate; if (fromDate != null && toDate == null) { datePredicate = cb.greaterThanOrEqualTo(createdOn, fromDate); } else if (fromDate == null && toDate != null) { datePredicate = cb.lessThanOrEqualTo(createdOn, toDate); } else if (fromDate != null && toDate != null) { datePredicate = cb.between(createdOn, fromDate, toDate); } else { datePredicate = null; } final List<Predicate> auditActionPredicates = new ArrayList<>(); if (actions != null && actions.length > 0) { for (AuditActionType action : actions) { auditActionPredicates.add(cb.equal(auditAction, action)); } } final List<Predicate> auditOperationsPredicates = new ArrayList<>(); if (operations != null && operations.length > 0) { for (AuditOperationType operation : operations) { auditOperationsPredicates.add(cb.equal(auditOperation, operation)); } } final List<Predicate> finalQueryPredicates = new ArrayList<>(); if (!auditActionPredicates.isEmpty()) { final Predicate auditActionPredicatesOr = cb.or(auditActionPredicates.toArray(new Predicate[0])); finalQueryPredicates.add(auditActionPredicatesOr); } if (datePredicate != null) { finalQueryPredicates.add(datePredicate); } if (!auditOperationsPredicates.isEmpty()) { final Predicate auditOperationsPredicatesOr = cb.or(auditOperationsPredicates.toArray(new Predicate[0])); finalQueryPredicates.add(auditOperationsPredicatesOr); } final CriteriaQuery<AuditRecord> select = query.select(auditRecordRoot); if (!finalQueryPredicates.isEmpty()) { select.where(finalQueryPredicates.toArray(new Predicate[0])); } if (pageable.getSort().isUnsorted()) { select.orderBy(QueryUtils.toOrders(pageable.getSort().and(Sort.by("id")).ascending(), auditRecordRoot, cb)); } else { select.orderBy(QueryUtils.toOrders(pageable.getSort(), auditRecordRoot, cb)); } final TypedQuery<AuditRecord> typedQuery = entityManager.createQuery(select); typedQuery.setFirstResult((int) pageable.getOffset()); typedQuery.setMaxResults(pageable.getPageSize()); final List<AuditRecord> resultList = typedQuery.getResultList(); final CriteriaQuery<Long> countQuery = cb.createQuery(Long.class); countQuery.select(cb.count(countQuery.from(AuditRecord.class))); if (!finalQueryPredicates.isEmpty()) { countQuery.where(finalQueryPredicates.toArray(new Predicate[0])); } final Long totalCount = entityManager.createQuery(countQuery) .getSingleResult(); return new PageImpl<>(resultList, pageable, totalCount); }
Example 15
Source File: LeSpecification.java From jpa-spec with MIT License | 4 votes |
@Override public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) { From from = getRoot(property, root); String field = getProperty(property); return cb.lessThanOrEqualTo(from.get(field), compare); }
Example 16
Source File: SimpleExpression.java From sctalk with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) { Path expression = null; if (fieldName.contains(".")) { System.out.println(root); String[] names = StringUtils.split(fieldName, "."); expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); } } else { expression = root.get(fieldName); } switch (operator) { case EQ: return builder.equal(expression, value); case NE: return builder.notEqual(expression, value); case LIKE: return builder.like((Expression<String>) expression, "%" + value + "%"); case RLIKE: return builder.like((Expression<String>) expression, value + "%"); case LLIKE: return builder.like((Expression<String>) expression, value + "%"); case LT: return builder.lessThan(expression, (Comparable) value); case GT: return builder.greaterThan(expression, (Comparable) value); case LTE: return builder.lessThanOrEqualTo(expression, (Comparable) value); case GTE: return builder.greaterThanOrEqualTo(expression, (Comparable) value); case ISNULL: return builder.isNull(expression); case NOTNULL: return builder.isNotNull(expression); case IN: return builder.in(expression); default: return null; } }
Example 17
Source File: SimpleExpression.java From sctalk with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) { Path expression = null; if (fieldName.contains(".")) { System.out.println(root); String[] names = StringUtils.split(fieldName, "."); expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); } } else { expression = root.get(fieldName); } switch (operator) { case EQ: return builder.equal(expression, value); case NE: return builder.notEqual(expression, value); case LIKE: return builder.like((Expression<String>) expression, "%" + value + "%"); case RLIKE: return builder.like((Expression<String>) expression, value + "%"); case LLIKE: return builder.like((Expression<String>) expression, value + "%"); case LT: return builder.lessThan(expression, (Comparable) value); case GT: return builder.greaterThan(expression, (Comparable) value); case LTE: return builder.lessThanOrEqualTo(expression, (Comparable) value); case GTE: return builder.greaterThanOrEqualTo(expression, (Comparable) value); case ISNULL: return builder.isNull(expression); case NOTNULL: return builder.isNotNull(expression); default: return null; } }