List of usage examples for javax.persistence.criteria Root get
<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
From source file:org.ngrinder.perftest.repository.TagSpecification.java
/** * Get the {@link Specification} which checks if the tag has corresponding perfTests. * * @return {@link Specification}//from w w w .j a v a 2s.c o m */ public static Specification<Tag> hasPerfTest() { return new Specification<Tag>() { @Override public Predicate toPredicate(Root<Tag> root, CriteriaQuery<?> query, CriteriaBuilder cb) { SetJoin<Object, Object> join = root.joinSet("perfTests"); query.groupBy(root.get("id")); return join.get("id").isNotNull(); } }; }
From source file:org.ngrinder.perftest.repository.PerfTestSpecification.java
/** * Get the {@link Specification} checking if the {@link PerfTest} has the given ID. * * @param id perf test id/* ww w.j a va 2 s.co m*/ * @return {@link Specification} */ public static Specification<PerfTest> idEqual(final Long id) { return new Specification<PerfTest>() { @Override public Predicate toPredicate(Root<PerfTest> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return cb.equal(root.get("id"), id); } }; }
From source file:com.goodhuddle.huddle.repository.BlogPostSpecification.java
public static Specification<BlogPost> search(final Huddle huddle, final SearchBlogPostRequest request) { return new Specification<BlogPost>() { @Override/* ww w. java 2 s .c om*/ public Predicate toPredicate(Root<BlogPost> blogPost, CriteriaQuery<?> query, CriteriaBuilder builder) { Predicate conjunction = builder.conjunction(); conjunction.getExpressions().add(builder.equal(blogPost.get("huddle"), huddle)); if (StringUtils.isNotBlank(request.getPhrase())) { String phrase = "%" + request.getPhrase().toLowerCase() + "%"; conjunction.getExpressions() .add(builder.like(builder.lower(blogPost.<String>get("title")), phrase)); } if (CollectionUtils.isNotEmpty(request.getBlogIds())) { Join<Object, Object> blog = blogPost.join("blog"); conjunction.getExpressions().add(builder.in(blog.get("id")).value(request.getBlogIds())); } if (!request.isIncludeUnpublished()) { conjunction.getExpressions() .add(builder.lessThan((Expression) blogPost.get("publishedOn"), new DateTime())); } return conjunction; } }; }
From source file:org.ngrinder.perftest.repository.PerfTestSpecification.java
/** * Get the {@link Specification} checking if the {@link PerfTest} has the given region. * * @param region region of perf test// w ww. j a v a2s . c o m * @return {@link Specification} * @since 3.1 */ public static Specification<PerfTest> idRegionEqual(final String region) { return new Specification<PerfTest>() { @Override public Predicate toPredicate(Root<PerfTest> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return cb.or(cb.equal(root.get("region"), region), cb.equal(root.get("region"), "")); } }; }
From source file:org.ngrinder.perftest.repository.PerfTestSpecification.java
/** * Get createBy {@link Specification} to get the {@link PerfTest}s whose creator is the given user. * * @param user user//from w w w. ja v a 2s . c om * @return {@link Specification} */ public static Specification<PerfTest> createdBy(final User user) { return new Specification<PerfTest>() { @Override public Predicate toPredicate(Root<PerfTest> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return cb.or(cb.equal(root.get("createdUser"), user)); } }; }
From source file:com.hengyi.japp.execution.Util.java
public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Task> root, TaskQueryCommand command) {/* w w w .j a va2 s . co 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:org.ngrinder.perftest.repository.TagSpecification.java
/** * Get the {@link Specification} to get the {@link Tag} whose value starts with given query. * * @param queryString matching tag value * @return {@link Specification}//w w w . j av a 2 s. com */ public static Specification<Tag> isStartWith(final String queryString) { return new Specification<Tag>() { @Override public Predicate toPredicate(Root<Tag> root, CriteriaQuery<?> query, CriteriaBuilder cb) { String replacedQueryString = StringUtils.replace(queryString, "%", "\\%"); return cb.like(cb.lower(root.get("tagValue").as(String.class)), StringUtils.lowerCase(replacedQueryString) + "%"); } }; }
From source file:com.hengyi.japp.execution.Util.java
public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Customer> root, CustomerQueryCommand command) {//from w ww . j a v a2s . c om List<Predicate> ps = Lists.newArrayListWithCapacity(2); ps.add(cb.equal(root.get(Customer_.deleteFlag), command.isDeleteFlag())); if (!isBlank(command.getName())) { ps.add(cb.like(root.get(Customer_.name), command.getNameQuery())); } cq.where(ps.toArray(new Predicate[ps.size()])); }
From source file:com.hengyi.japp.execution.Util.java
public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Operator> root, OperatorQueryCommand command) {// ww w . j av a 2s. co m List<Predicate> ps = Lists.newArrayListWithCapacity(3); ps.add(cb.equal(root.get(Operator_.deleteFlag), command.isDeleteFlag())); if (command.getCustomer() != null) { ps.add(cb.isMember(command.getCustomer(), root.get(Operator_.customers))); } if (!isBlank(command.getName())) { ps.add(cb.like(root.get(Operator_.name), command.getNameQuery())); } cq.where(ps.toArray(new Predicate[ps.size()])); }
From source file:com.github.dactiv.orm.core.spring.data.jpa.specification.Specifications.java
/** * ???/*from w w w.j a va 2 s .c o m*/ * * @param propertyName ?? * @param root Query roots always reference entities * * @return {@link Path} */ public static Path<?> getPath(String propertyName, Root<?> root) { Path<?> path = null; if (StringUtils.contains(propertyName, ".")) { String[] propertys = StringUtils.splitByWholeSeparator(propertyName, "."); path = root.get(propertys[0]); for (int i = 1; i < propertys.length; i++) { path = path.get(propertys[i]); } } else { path = root.get(propertyName); } return path; }