Java Code Examples for javax.persistence.criteria.CriteriaBuilder#greaterThan()
The following examples show how to use
javax.persistence.criteria.CriteriaBuilder#greaterThan() .
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: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 8 votes |
private Long durationWork(Business business, Date start, Date current, ActivityStub activityStub) throws Exception { EntityManager em = business.entityManagerContainer().get(Work.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Date> cq = cb.createQuery(Date.class); Root<Work> root = cq.from(Work.class); Predicate p = cb.greaterThan(root.get(Work_.startTime), start); p = cb.and(p, cb.equal(root.get(Work_.activity), activityStub.getValue())); cq.select(root.get(Work_.startTime)).where(p); List<Date> os = em.createQuery(cq).getResultList(); long duration = 0; for (Date o : os) { duration += current.getTime() - o.getTime(); } duration = duration / (1000L * 60L); return duration; }
Example 2
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 8 votes |
private Long durationWork(Business business, Date start, Date current, ApplicationStub applicationStub) throws Exception { EntityManager em = business.entityManagerContainer().get(Work.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Date> cq = cb.createQuery(Date.class); Root<Work> root = cq.from(Work.class); Predicate p = cb.greaterThan(root.get(Work_.startTime), start); p = cb.and(p, cb.equal(root.get(Work_.application), applicationStub.getValue())); cq.select(root.get(Work_.startTime)).where(p); List<Date> os = em.createQuery(cq).getResultList(); long duration = 0; for (Date o : os) { duration += current.getTime() - o.getTime(); } duration = duration / (1000L * 60L); return duration; }
Example 3
Source File: ActionValidate.java From o2oa with GNU Affero General Public License v3.0 | 8 votes |
private Code get(EntityManagerContainer emc, String mobile, String answer) throws Exception { EntityManager em = emc.get(Code.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Code> cq = cb.createQuery(Code.class); Root<Code> root = cq.from(Code.class); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, -30); Predicate p = cb.greaterThan(root.get(Code_.createTime), cal.getTime()); p = cb.and(p, cb.equal(root.get(Code_.mobile), mobile)); p = cb.and(p, cb.equal(root.get(Code_.answer), answer)); List<Code> list = em.createQuery(cq.where(p)).getResultList(); if (list.isEmpty()) { return null; } else { return list.get(0); } }
Example 4
Source File: TaskFactory.java From o2oa with GNU Affero General Public License v3.0 | 8 votes |
public Long count(Date start, PersonStub personStub) throws Exception { EntityManager em = this.entityManagerContainer().get(Task.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Task> root = cq.from(Task.class); Predicate p = cb.greaterThan(root.get(Task_.startTime), start); p = cb.and(p, cb.equal(root.get(Task_.person), personStub.getValue())); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 5
Source File: NumberCriteria.java From onedev with MIT License | 6 votes |
@Override public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) { Path<Long> attribute = root.get(PullRequest.PROP_NUMBER); Predicate numberPredicate; if (operator == PullRequestQueryLexer.Is) numberPredicate = builder.equal(attribute, number.getNumber()); else if (operator == PullRequestQueryLexer.IsGreaterThan) numberPredicate = builder.greaterThan(attribute, number.getNumber()); else numberPredicate = builder.lessThan(attribute, number.getNumber()); return builder.and( builder.equal(root.get(PullRequest.PROP_TARGET_PROJECT), number.getProject()), numberPredicate); }
Example 6
Source File: TaskCompletedFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public Long count(Date start, UnitStub unitStub) throws Exception { EntityManager em = this.entityManagerContainer().get(TaskCompleted.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<TaskCompleted> root = cq.from(TaskCompleted.class); Predicate p = cb.greaterThan(root.get(TaskCompleted_.completedTime), start); p = cb.and(p, cb.equal(root.get(TaskCompleted_.unit), unitStub.getValue())); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 7
Source File: TimerOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countExpiredWithUnit(Business business, Date start, Date current, List<String> units) throws Exception { EntityManager em = business.entityManagerContainer().get(Task.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Task> root = cq.from(Task.class); Predicate p = cb.greaterThan(root.get(Task_.startTime), start); p = cb.and(p, cb.lessThan(root.get(Task_.expireTime), current)); p = cb.and(p, root.get(Task_.unit).in(units)); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 8
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countWorkExpired(Business business, Date start, Date current, ApplicationStub applicationStub) throws Exception { EntityManager em = business.entityManagerContainer().get(Work.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Work> root = cq.from(Work.class); Predicate p = cb.greaterThan(root.get(Work_.startTime), start); p = cb.and(p, cb.lessThan(root.get(Work_.expireTime), current)); p = cb.and(p, cb.equal(root.get(Work_.application), applicationStub.getValue())); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 9
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long durationTaskCompleted(Business business, Date start, ActivityStub activityStub) throws Exception { EntityManager em = business.entityManagerContainer().get(TaskCompleted.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<TaskCompleted> root = cq.from(TaskCompleted.class); Predicate p = cb.greaterThan(root.get(TaskCompleted_.startTime), start); p = cb.and(p, cb.equal(root.get(TaskCompleted_.activity), activityStub.getValue())); cq.select(cb.sum(root.get(TaskCompleted_.duration))).where(p); return em.createQuery(cq).getSingleResult(); }
Example 10
Source File: NumericFieldCriteria.java From onedev with MIT License | 5 votes |
@Override protected Predicate getValuePredicate(Join<?, ?> field, CriteriaBuilder builder) { Path<Integer> attribute = field.get(IssueField.PROP_ORDINAL); if (operator == IssueQueryLexer.Is) return builder.equal(attribute, value); else if (operator == IssueQueryLexer.IsGreaterThan) return builder.greaterThan(attribute, value); else return builder.lessThan(attribute, value); }
Example 11
Source File: TimerOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countCompletedWithUnit(Business business, Date start, List<String> units) throws Exception { EntityManager em = business.entityManagerContainer().get(TaskCompleted.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<TaskCompleted> root = cq.from(TaskCompleted.class); Predicate p = cb.greaterThan(root.get(TaskCompleted_.completedTime), start); p = cb.and(p, root.get(TaskCompleted_.unit).in(units)); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 12
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countWork(Business business, Date start, ApplicationStub applicationStub) throws Exception { EntityManager em = business.entityManagerContainer().get(Work.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Work> root = cq.from(Work.class); Predicate p = cb.greaterThan(root.get(Work_.startTime), start); p = cb.and(p, cb.equal(root.get(Work_.application), applicationStub.getValue())); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 13
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countTaskCompleted(Business business, Date start, ProcessStub processStub) throws Exception { EntityManager em = business.entityManagerContainer().get(TaskCompleted.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<TaskCompleted> root = cq.from(TaskCompleted.class); Predicate p = cb.greaterThan(root.get(TaskCompleted_.startTime), start); p = cb.and(p, cb.equal(root.get(TaskCompleted_.process), processStub.getValue())); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 14
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countWork(Business business, Date start, ProcessStub processStub) throws Exception { EntityManager em = business.entityManagerContainer().get(Work.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Work> root = cq.from(Work.class); Predicate p = cb.greaterThan(root.get(Work_.startTime), start); p = cb.and(p, cb.equal(root.get(Work_.process), processStub.getValue())); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 15
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countWorkCompleted(Business business, Date start, ProcessStub processStub) throws Exception { EntityManager em = business.entityManagerContainer().get(WorkCompleted.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<WorkCompleted> root = cq.from(WorkCompleted.class); Predicate p = cb.greaterThan(root.get(WorkCompleted_.startTime), start); p = cb.and(p, cb.equal(root.get(WorkCompleted_.process), processStub.getValue())); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 16
Source File: TimerCategory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long durationTaskCompleted(Business business, Date start, ApplicationStub applicationStub) throws Exception { EntityManager em = business.entityManagerContainer().get(TaskCompleted.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<TaskCompleted> root = cq.from(TaskCompleted.class); Predicate p = cb.greaterThan(root.get(TaskCompleted_.startTime), start); p = cb.and(p, cb.equal(root.get(TaskCompleted_.application), applicationStub.getValue())); cq.select(cb.sum(root.get(TaskCompleted_.duration))).where(p); return em.createQuery(cq).getSingleResult(); }
Example 17
Source File: TimerOrganization.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Long countWithUnit(Business business, Date start, List<String> units) throws Exception { EntityManager em = business.entityManagerContainer().get(Task.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Task> root = cq.from(Task.class); Predicate p = cb.greaterThan(root.get(Task_.startTime), start); p = cb.and(p, root.get(Task_.unit).in(units)); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 18
Source File: RangeSpecification.java From gazpachoquest with GNU General Public License v3.0 | 4 votes |
public static <E, D extends Comparable<? super D>> Specification<E> toSpecification(final Range<E, D> range) { Validate.isTrue(range.isSet(), "You must pass an exploitable range"); return new Specification<E>() { @Override public Predicate toPredicate(final Root<E> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) { Predicate rangePredicate = null; if (range.isBetween()) { rangePredicate = builder.between(root.get(range.getField()), range.getFrom(), range.getTo()); } else if (range.isFromSet()) { // rangePredicate = // builder.greaterThanOrEqualTo(root.get(range.getField()), // range.getFrom()); rangePredicate = builder.greaterThan(root.get(range.getField()), range.getFrom()); } else if (range.isToSet()) { // rangePredicate = // builder.lessThanOrEqualTo(root.get(range.getField()), // range.getTo()); rangePredicate = builder.lessThan(root.get(range.getField()), range.getTo()); } if (rangePredicate != null) { if (!range.isIncludeNullSet() || Boolean.FALSE.equals(range.getIncludeNull())) { return rangePredicate; } else { return builder.or(rangePredicate, builder.isNull(root.get(range.getField()))); } } // no range at all // take the opportunity to keep only null... if (Boolean.TRUE.equals(range.getIncludeNull())) { return builder.isNull(root.get(range.getField())); } // ... or non-null only... if (Boolean.FALSE.equals(range.getIncludeNull())) { return builder.isNotNull(root.get(range.getField())); } throw new IllegalStateException("You must pass an exploitable range (should not happen here)"); } }; }
Example 19
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 20
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; } }