List of usage examples for javax.persistence.criteria CriteriaBuilder equal
Predicate equal(Expression<?> x, Object y);
From source file:org.ngrinder.perftest.repository.TagSpecification.java
/** * Get lastModifiedUser and createBy {@link Specification} to get the {@link Tag} whose creator or last modifier is * the given user./* w w w.ja v a2 s . c o m*/ * * @param user user * @return {@link Specification} */ public static Specification<Tag> lastModifiedOrCreatedBy(final User user) { return new Specification<Tag>() { @Override public Predicate toPredicate(Root<Tag> root, CriteriaQuery<?> query, CriteriaBuilder cb) { return cb.or(cb.equal(root.get("lastModifiedUser"), user), cb.equal(root.get("createdUser"), user)); } }; }
From source file:com.goodhuddle.huddle.repository.TagSpecification.java
public static Specification<Tag> search(final Huddle huddle, final SearchTagsRequest request) { return new Specification<Tag>() { @Override// w w w . j a v a 2 s . c o m public Predicate toPredicate(Root<Tag> tag, CriteriaQuery<?> query, CriteriaBuilder builder) { Predicate conjunction = builder.conjunction(); conjunction.getExpressions().add(builder.equal(tag.get("huddle"), huddle)); if (StringUtils.isNotBlank(request.getName())) { String nameTerm = "%" + request.getName().toLowerCase() + "%"; conjunction.getExpressions() .add(builder.like(builder.lower(tag.<String>get("name")), nameTerm)); } return conjunction; } }; }
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// w w w. j a v a2 s. c o m 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 ID. * * @param id perf test id//from w w w .jav a 2s .c o 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: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// ww w .jav a2 s . c om * @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 ww.j av a 2 s . com * @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:example.springdata.jpa.showcase.snippets.CustomerSpecifications.java
/** * All customers with an {@link Account} expiring before the given date. * /*from ww w . jav a 2 s. c o m*/ * @param date * @return */ public static Specification<Customer> accountExpiresBefore(final LocalDate date) { return new Specification<Customer>() { @Override public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Root<Account> accounts = query.from(Account.class); Path<Date> expiryDate = accounts.<Date>get("expiryDate"); Predicate customerIsAccountOwner = cb.equal(accounts.<Customer>get("customer"), root); Predicate accountExpiryDateBefore = cb.lessThan(expiryDate, date.toDateTimeAtStartOfDay().toDate()); return cb.and(customerIsAccountOwner, accountExpiryDateBefore); } }; }
From source file:org.ngrinder.perftest.repository.PerfTestSpecification.java
/** * Get the {@link Specification} checking if the {@link PerfTest#getTags()} has the given tagValue. * * @param tagValue tagValue/* w w w . j a va 2 s. c om*/ * @return {@link Specification} */ public static Specification<PerfTest> hasTag(final String tagValue) { return new Specification<PerfTest>() { @Override public Predicate toPredicate(Root<PerfTest> root, CriteriaQuery<?> query, CriteriaBuilder cb) { SetJoin<Object, Object> join = root.joinSet("tags"); return cb.equal(join.get("tagValue"), tagValue); } }; }
From source file:com.netflix.genie.server.repository.jpa.ApplicationSpecs.java
/** * Get a specification using the specified parameters. * * @param name The name of the application * @param userName The name of the user who created the application * @param statuses The status of the application * @param tags The set of tags to search the command for * @return A specification object used for querying *//*w w w. j a v a2s . c o m*/ public static Specification<Application> find(final String name, final String userName, final Set<ApplicationStatus> statuses, final Set<String> tags) { return new Specification<Application>() { @Override public Predicate toPredicate(final Root<Application> root, final CriteriaQuery<?> cq, final CriteriaBuilder cb) { final List<Predicate> predicates = new ArrayList<>(); if (StringUtils.isNotBlank(name)) { predicates.add(cb.equal(root.get(Application_.name), name)); } if (StringUtils.isNotBlank(userName)) { predicates.add(cb.equal(root.get(Application_.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 ApplicationStatus status : statuses) { orPredicates.add(cb.equal(root.get(Application_.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(Application_.tags))); } } } return cb.and(predicates.toArray(new Predicate[predicates.size()])); } }; }
From source file:org.ngrinder.agent.repository.AgentManagerSpecification.java
/** * Query specification to query the agent existing in the specified region. * * @param region region to query//from w ww . j a v a 2s. c om * @return Specification of this query */ public static Specification<AgentInfo> startWithRegion(final String region) { return new Specification<AgentInfo>() { @Override public Predicate toPredicate(Root<AgentInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Expression<String> regionField = root.get("region").as(String.class); return cb.or(cb.like(regionField, region + "/_owned%", cb.literal('/')), cb.equal(regionField, region)); } }; }