List of usage examples for javax.persistence.criteria CriteriaBuilder lower
Expression<String> lower(Expression<String> x);
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}/*from w w w . j av a2 s . c om*/ */ 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:org.ngrinder.perftest.repository.PerfTestSpecification.java
/** * Get the search {@link Specification} for test name and description fields. * * @param queryString query String// w w w .ja va 2 s . co m * @return {@link Specification} */ public static Specification<PerfTest> likeTestNameOrDescription(final String queryString) { return new Specification<PerfTest>() { @Override public Predicate toPredicate(Root<PerfTest> root, CriteriaQuery<?> query, CriteriaBuilder cb) { String queryStr = ("%" + queryString + "%").toLowerCase(); return cb.or(cb.like(cb.lower(root.get("testName").as(String.class)), queryStr), cb.like(root.get("description").as(String.class), queryStr)); } }; }
From source file:net.sf.companymanager.qbe.JpaUtil.java
public static <E> Predicate stringPredicate(Expression<String> path, Object attrValue, SearchMode searchMode, SearchParameters sp, CriteriaBuilder builder) { if (!sp.isCaseSensitive()) { path = builder.lower(path); // attrValue = ((String) attrValue).toLowerCase(LocaleContextHolder.getLocale()); attrValue = ((String) attrValue).toLowerCase(); }/* ww w. j a va2s . c o m*/ switch (searchMode != null ? searchMode : sp.getSearchMode()) { case EQUALS: return builder.equal(path, attrValue); case NOT_EQUALS: return builder.notEqual(path, attrValue); case ENDING_LIKE: return builder.like(path, "%" + attrValue); case STARTING_LIKE: return builder.like(path, attrValue + "%"); case ANYWHERE: return builder.like(path, "%" + attrValue + "%"); case LIKE: return builder.like(path, (String) attrValue); // assume user // provide the wild // cards default: throw new IllegalStateException("expecting a search mode!"); } }
From source file:net.sf.companymanager.qbe.JpaUtil.java
public static <E> Predicate stringPredicate(Expression<String> path, Object attrValue, final SearchParameters sp, final CriteriaBuilder builder) { if (sp.isCaseInsensitive()) { path = builder.lower(path); attrValue = ((String) attrValue).toLowerCase(Locale.ENGLISH); }//from w w w . j av a2 s .com switch (sp.getSearchMode()) { case EQUALS: return builder.equal(path, attrValue); case ENDING_LIKE: return builder.like(path, "%" + attrValue); case STARTING_LIKE: return builder.like(path, attrValue + "%"); case ANYWHERE: return builder.like(path, "%" + attrValue + "%"); case LIKE: return builder.like(path, (String) attrValue); // assume user // provide the wild // cards default: throw new IllegalStateException("expecting a search mode!"); } }
From source file:org.querybyexample.jpa.JpaUtil.java
public static <E> Predicate stringPredicate(Expression<String> path, Object attrValue, SearchMode searchMode, SearchParameters sp, CriteriaBuilder builder) { if (!sp.isCaseSensitive()) { path = builder.lower(path); attrValue = ((String) attrValue).toLowerCase(LocaleContextHolder.getLocale()); }//w w w. j a v a 2s.co m switch (searchMode != null ? searchMode : sp.getSearchMode()) { case EQUALS: return builder.equal(path, attrValue); case ENDING_LIKE: return builder.like(path, "%" + attrValue); case STARTING_LIKE: return builder.like(path, attrValue + "%"); case ANYWHERE: return builder.like(path, "%" + attrValue + "%"); case LIKE: return builder.like(path, (String) attrValue); // assume user provide the wild cards default: throw new IllegalStateException("expecting a search mode!"); } }
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate belongsToGroup(Root<Annotation> root, CriteriaBuilder cb, String group) { return cb.like(cb.lower(root.get(GROUP).get(NAME)), group.toLowerCase()); }
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate hasVocabulary(Root<Annotation> root, CriteriaBuilder cb, String vocab) { return cb.like(cb.lower(root.get(VOCAB).get(NAME)), vocab.toLowerCase()); }
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate belongsToUser(Root<Annotation> root, CriteriaBuilder cb, String username) { return cb.like(cb.lower(root.get(USER).get(USERNAME)), username.toLowerCase()); }
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//from www .j a va2 s. co 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/*from w w w.j a va 2s. 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; } }; }