List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
From source file:com.invariantproperties.project.student.specification.TermSpecifications.java
/** * Creates a specification used to find terms with the specified testUuid. * //from www.ja va 2 s . c o m * @param testRun * @return */ public static Specification<Term> testRunIs(final TestRun testRun) { return new Specification<Term>() { @Override public Predicate toPredicate(Root<Term> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate p = null; if (testRun == null || testRun.getUuid() == null) { p = cb.isNull(root.<Term_>get("testRun")); } else { p = cb.equal(root.<Term_>get("testRun").<TestRun_>get("uuid"), testRun.getUuid()); } return p; } }; }
From source file:com.hengyi.japp.execution.Util.java
public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Task> root, TaskQueryCommand command) {//from w w w . ja v a 2s . c o m Predicate p1 = cb.equal(root.get(Task_.charger), command.getOperator()); ListJoin<Task, Operator> joinFollowers = root.join(Task_.followers, JoinType.LEFT); Predicate p2 = cb.equal(joinFollowers.get(Operator_.id), command.getOperator().getId()); ListJoin<Task, Operator> joinExecutors = root.join(Task_.executors, JoinType.LEFT); Predicate p3 = cb.equal(joinExecutors.get(Operator_.id), command.getOperator().getId()); Predicate p = cb.or(p1, p2, p3); if (command.getExecutor() != null) { p = cb.and(p, cb.equal(p, cb.isMember(command.getExecutor(), root.get(Task_.executors)))); } if (command.getCustomer() != null) { p = cb.and(p, cb.equal(root.get(Task_.customer), command.getCustomer())); } if (!isBlank(command.getContent())) { p = cb.and(p, cb.like(root.get(Task_.content), command.getContentQuery())); } Collection<TaskType> TaskTypes = command.getTypes(); if (TaskTypes != null && !TaskTypes.isEmpty()) { p = cb.and(p, root.get(Task_.type).in(TaskTypes)); } Collection<TaskStatus> statuses = command.getStatuses(); if (statuses != null && !statuses.isEmpty()) { p = cb.and(p, root.get(Task_.status).in(statuses)); } if (command.getCreateDate() != null) { Date createDateStart = LocalDate.fromDateFields(command.getCreateDate()).toDate(); Date createDateEnd = LocalDate.fromDateFields(command.getCreateDate()).plusDays(1).toDate(); p = cb.and(p, cb.between(root.get(Task_.logInfo).get(LogInfo_.createDateTime), createDateStart, createDateEnd)); // TODO timestamp date convert //p = cb.and(p, cb.equal(root.get(Task_.logInfo).get(LogInfo_.createDateTime).as(java.sql.Date.class), command.getCreateDate())); } cq.where(p); }
From source file:com.invariantproperties.project.student.specification.SectionSpecifications.java
/** * Creates a specification used to find sections with the specified * testUuid.//from www .jav a2s . com * * @param testRun * @return */ public static Specification<Section> testRunIs(final TestRun testRun) { return new Specification<Section>() { @Override public Predicate toPredicate(Root<Section> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate p = null; if (testRun == null || testRun.getUuid() == null) { p = cb.isNull(root.<Section_>get("testRun")); } else { p = cb.equal(root.<Section_>get("testRun").<TestRun_>get("uuid"), testRun.getUuid()); } return p; } }; }
From source file:com.invariantproperties.project.student.specification.StudentSpecifications.java
/** * Creates a specification used to find students with the specified * testUuid./*w w w . j a v a 2 s. co m*/ * * @param testRun * @return */ public static Specification<Student> testRunIs(final TestRun testRun) { return new Specification<Student>() { @Override public Predicate toPredicate(Root<Student> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate p = null; if (testRun == null || testRun.getUuid() == null) { p = cb.isNull(root.<Student_>get("testRun")); } else { p = cb.equal(root.<Student_>get("testRun").<TestRun_>get("uuid"), testRun.getUuid()); } return p; } }; }
From source file:com.invariantproperties.project.student.specification.ClassroomSpecifications.java
/** * Creates a specification used to find classrooms with the specified * testUuid.// w ww .j a va 2s .c om * * @param testRun * @return */ public static Specification<Classroom> testRunIs(final TestRun testRun) { return new Specification<Classroom>() { @Override public Predicate toPredicate(Root<Classroom> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate p = null; if (testRun == null || testRun.getUuid() == null) { p = cb.isNull(root.<Classroom_>get("testRun")); } else { p = cb.equal(root.<Classroom_>get("testRun").<TestRun_>get("uuid"), testRun.getUuid()); } return p; } }; }
From source file:com.invariantproperties.project.student.specification.InstructorSpecifications.java
/** * Creates a specification used to find instructors with the specified * testUuid.//from ww w. j a v a 2s. c o m * * @param testRun * @return */ public static Specification<Instructor> testRunIs(final TestRun testRun) { return new Specification<Instructor>() { @Override public Predicate toPredicate(Root<Instructor> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate p = null; if (testRun == null || testRun.getUuid() == null) { p = cb.isNull(root.<Instructor_>get("testRun")); } else { p = cb.equal(root.<Instructor_>get("testRun").<TestRun_>get("uuid"), testRun.getUuid()); } return p; } }; }
From source file:com.invariantproperties.project.student.specification.CourseSpecifications.java
/** * Creates a specification used to find courses with the specified testUuid. * // www . ja v a2s. c om * @param testRun * @return */ public static Specification<Course> testRunIs(final TestRun testRun) { return new Specification<Course>() { @Override public Predicate toPredicate(Root<Course> courseRoot, CriteriaQuery<?> query, CriteriaBuilder cb) { Predicate p = null; if (testRun == null || testRun.getUuid() == null) { p = cb.isNull(courseRoot.<Course_>get("testRun")); } else { p = cb.equal(courseRoot.<Course_>get("testRun").<TestRun_>get("uuid"), testRun.getUuid()); } return p; } }; }
From source file:com.netflix.genie.core.jpa.specifications.JpaSpecificationUtils.java
/** * Create either an equals or like predicate based on the presence of the '%' character in the search value. * * @param cb The criteria builder to use for predicate creation * @param expression The expression of the field the predicate is acting on * @param value The value to compare the field to * @return A LIKE predicate if the value contains a '%' otherwise an EQUAL predicate *//*w w w .ja va 2 s .c o m*/ public static Predicate getStringLikeOrEqualPredicate(@NotNull final CriteriaBuilder cb, @NotNull final Expression<String> expression, @NotNull final String value) { if (StringUtils.contains(value, PERCENT)) { return cb.like(expression, value); } else { return cb.equal(expression, value); } }
From source file:com.netflix.genie.server.repository.jpa.CommandSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the command * @param userName The name of the user who created the command * @param statuses The status of the command * @param tags The set of tags to search the command for * @return A specification object used for querying *//*from w ww .j a va 2s. com*/ public static Specification<Command> find(final String name, final String userName, final Set<CommandStatus> statuses, final Set<String> tags) { return new Specification<Command>() { @Override public Predicate toPredicate(final Root<Command> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(cb.equal(root.get(Command_.name), name)); } if (StringUtils.isNotBlank(userName)) { predicates.add(cb.equal(root.get(Command_.user), userName)); } if (statuses != null && !statuses.isEmpty()) { //Could optimize this as we know size could use native array final List<Predicate> orPredicates = new ArrayList<>(); for (final CommandStatus status : statuses) { orPredicates.add(cb.equal(root.get(Command_.status), status)); } predicates.add(cb.or(orPredicates.toArray(new Predicate[orPredicates.size()]))); } if (tags != null) { for (final String tag : tags) { if (StringUtils.isNotBlank(tag)) { predicates.add(cb.isMember(tag, root.get(Command_.tags))); } } } return cb.and(predicates.toArray(new Predicate[predicates.size()])); } }; }
From source file:com.netflix.genie.web.data.repositories.jpa.specifications.JpaSpecificationUtils.java
/** * Create either an equals or like predicate based on the presence of the '%' character in the search value. * * @param cb The criteria builder to use for predicate creation * @param expression The expression of the field the predicate is acting on * @param value The value to compare the field to * @return A LIKE predicate if the value contains a '%' otherwise an EQUAL predicate *///from w w w. j a va 2 s .co m static Predicate getStringLikeOrEqualPredicate(@NotNull final CriteriaBuilder cb, @NotNull final Expression<String> expression, @NotNull final String value) { if (StringUtils.contains(value, PERCENT)) { return cb.like(expression, value); } else { return cb.equal(expression, value); } }