List of usage examples for javax.persistence.criteria CriteriaBuilder lower
Expression<String> lower(Expression<String> x);
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate existsInData(Root<Annotation> root, CriteriaQuery query, CriteriaBuilder cb, String term) {/*from ww w . ja v a 2 s . c o m*/ final Subquery<AnnotationData> subquery = query.subquery(AnnotationData.class); final Root<AnnotationData> subroot = subquery.from(AnnotationData.class); return cb.exists(subquery.select(subroot) .where(cb.and(cb.equal(subroot.get(ANNO), root), cb.like(cb.lower(subroot.get(VALUE)), term)))); }
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate hasAttributeName(Root<Annotation> root, CriteriaQuery query, CriteriaBuilder cb, String attributeName) {//from w ww. j a v a 2 s . c om final Subquery<AnnotationData> subquery = query.subquery(AnnotationData.class); final Root<AnnotationData> subroot = subquery.from(AnnotationData.class); return cb.exists(subquery.select(subroot).where(cb.and(cb.equal(subroot.get(ANNO), root), cb.like(cb.lower(subroot.get(ATTRIB).get(NAME)), attributeName.toLowerCase())))); }
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate hasAttributeLevel(Root<Annotation> root, CriteriaQuery query, CriteriaBuilder cb, String attributeLevel) {//from w w w .j a v a2s.c o m final Subquery<AnnotationData> subquery = query.subquery(AnnotationData.class); final Root<AnnotationData> subroot = subquery.from(AnnotationData.class); return cb.exists(subquery.select(subroot).where(cb.and(cb.equal(subroot.get(ANNO), root), cb.like(cb.lower(subroot.get(ATTRIB).get(LEVEL)), attributeLevel.toLowerCase())))); }
From source file:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java
private static Predicate hasAttributeReqLevel(Root<Annotation> root, CriteriaQuery query, CriteriaBuilder cb, String attributeReqLevel) { final Subquery<AnnotationData> subquery = query.subquery(AnnotationData.class); final Root<AnnotationData> subroot = subquery.from(AnnotationData.class); return cb.exists(subquery.select(subroot).where(cb.and(cb.equal(subroot.get(ANNO), root), cb.like(cb.lower(subroot.get(ATTRIB).get(REQ_LEVEL)), attributeReqLevel.toLowerCase())))); }
From source file:com.ocs.dynamo.dao.query.JpaQueryBuilder.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private static Predicate createLikePredicate(CriteriaBuilder builder, Root<?> root, Filter filter) { Like like = (Like) filter;/* w w w.j a v a2 s . c om*/ if (like.isCaseSensitive()) { return builder.like((Expression) getPropertyPath(root, like.getPropertyId()), like.getValue()); } else { return builder.like(builder.lower((Expression) getPropertyPath(root, like.getPropertyId())), like.getValue().toLowerCase()); } }
From source file:com.goodhuddle.huddle.repository.MemberSpecification.java
public static Specification<Member> search(final Huddle huddle, final SearchMembersRequest request) { return new Specification<Member>() { @Override//from w w w . jav a2s. co m public Predicate toPredicate(Root<Member> member, CriteriaQuery<?> query, CriteriaBuilder builder) { Predicate conjunction = builder.conjunction(); // huddle conjunction.getExpressions().add(builder.equal(member.get("huddle"), huddle)); // keywords if (StringUtils.isNotBlank(request.getKeywords())) { String[] terms = StringUtils.split(request.getKeywords()); for (String keyword : terms) { if (keyword != null && keyword.length() > 0) { String matchTerm = "%" + keyword.toLowerCase() + "%"; conjunction.getExpressions().add(builder.or( builder.like(builder.lower(member.<String>get("username")), matchTerm), builder.like(builder.lower(member.<String>get("email")), matchTerm), builder.like(builder.lower(member.<String>get("firstName")), matchTerm), builder.like(builder.lower(member.<String>get("lastName")), matchTerm))); } } } // security groups if (CollectionUtils.isNotEmpty(request.getSecurityGroupIds())) { Join<Object, Object> securityGroup = member.join("securityGroup", request.isIncludeNoAccess() ? JoinType.LEFT : JoinType.INNER); Predicate disjunction = builder.disjunction(); for (Long id : request.getSecurityGroupIds()) { disjunction.getExpressions().add(builder.equal(securityGroup.get("id"), id)); } if (request.isIncludeNoAccess()) { disjunction.getExpressions().add(builder.isNull(securityGroup.get("id"))); } conjunction.getExpressions().add(disjunction); } else if (request.isIncludeNoAccess()) { conjunction.getExpressions().add(builder.isNull(member.get("securityGroup"))); } // tags MemberTagFilter tagFilter = request.getTags(); if (tagFilter != null) { if (tagFilter.getIncluded() != null) { if (CollectionUtils.isNotEmpty(tagFilter.getIncluded().getTagIds())) { MemberTagFilter.TagSet included = request.getTags().getIncluded(); MatchType matchType = included.getMatchType(); Predicate tagPredicate = matchType.equals(MatchType.all) ? builder.conjunction() : builder.disjunction(); for (Long tagId : included.getTagIds()) { Subquery<Member> sq = query.subquery(Member.class); Root<Member> subMember = sq.from(Member.class); Join<Member, Tag> tag = subMember.join("tags"); sq.select(subMember).where(builder.equal(tag.get("id"), tagId)); tagPredicate.getExpressions().add(builder.in(member).value(sq)); } conjunction.getExpressions().add(tagPredicate); } } if (tagFilter.getExcluded() != null) { if (CollectionUtils.isNotEmpty(tagFilter.getExcluded().getTagIds())) { MemberTagFilter.TagSet excluded = request.getTags().getExcluded(); MatchType matchType = excluded.getMatchType(); Predicate tagPredicate = matchType.equals(MatchType.all) ? builder.disjunction() : builder.conjunction(); for (Long tagId : excluded.getTagIds()) { Subquery<Member> sq = query.subquery(Member.class); Root<Member> subMember = sq.from(Member.class); Join<Member, Tag> tag = subMember.join("tags"); sq.select(subMember).where(builder.equal(tag.get("id"), tagId)); tagPredicate.getExpressions().add(builder.in(member).value(sq).not()); } conjunction.getExpressions().add(tagPredicate); } } } return conjunction; } }; }
From source file:com.globalhackv.app.repository.CitationSpec.java
@Override public Predicate toPredicate(Root<Citation> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) { List<Predicate> predicates = new ArrayList<Predicate>(); if (StringUtils.isNotBlank(example.getLastName())) { predicates.add(/* w w w .ja va2 s . co m*/ cb.like(cb.lower(root.get(Citation_.lastName)), example.getLastName().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getFirstName())) { predicates.add( cb.like(cb.lower(root.get(Citation_.firstName)), example.getFirstName().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getDateOfBirth())) { predicates.add(cb.like(cb.lower(root.get(Citation_.dateOfBirth)), example.getDateOfBirth().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getDriversLicense())) { predicates.add(cb.like(cb.lower(root.get(Citation_.driversLicense)), example.getDriversLicense().toLowerCase() + "%")); } if (StringUtils.isNotBlank(example.getAddress())) { predicates .add(cb.like(cb.lower(root.get(Citation_.address)), example.getAddress().toLowerCase() + "%")); } if (example.getCitationNumber() != 0) { predicates.add(cb.equal(root.get(Citation_.citationNumber), example.getCitationNumber())); } return andTogether(predicates, cb); }
From source file:org.zlogic.vogon.web.data.TransactionFilterSpecification.java
/** * Builds the Predicate//from w w w .j av a 2s . c o m * * @param root the FinanceTransaction query root * @param cq the CriteriaQuery instance * @param cb the CriteriaBuilder instance * @return the Predicate of this filter */ @Override public Predicate toPredicate(Root<FinanceTransaction> root, CriteriaQuery<?> cq, CriteriaBuilder cb) { Predicate ownerPredicate = cb.equal(root.get(FinanceTransaction_.owner), owner); Predicate descriptionPredicate = filterDescription != null ? cb.like(cb.lower(root.get(FinanceTransaction_.description)), filterDescription.toLowerCase()) : cb.conjunction(); Predicate tagsPredicate = cb.conjunction(); if (filterTags != null && !filterTags.isEmpty()) { Set<String> filterTagsLowercase = new HashSet<>(); for (String tag : filterTags) filterTagsLowercase.add(tag.toLowerCase()); tagsPredicate = cb.lower(root.join(FinanceTransaction_.tags)).in(cb.literal(filterTagsLowercase)); } Predicate datePredicate = filterDate != null ? cb.equal(root.get(FinanceTransaction_.transactionDate), new java.sql.Date(filterDate.getTime())) : cb.conjunction(); return cb.and(ownerPredicate, descriptionPredicate, datePredicate, tagsPredicate); }
From source file:org.osiam.resource_server.storage.dao.ExtensionDao.java
/** * Retrieves the extension with the given URN from the database * * @param urn/* www. ja v a 2 s . c om*/ * the URN of the extension to look up * @param caseInsensitive * should the case of the URN be ignored * @return the extension entity */ public ExtensionEntity getExtensionByUrn(String urn, boolean caseInsensitive) { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<ExtensionEntity> cq = cb.createQuery(ExtensionEntity.class); Root<ExtensionEntity> extension = cq.from(ExtensionEntity.class); Predicate predicate; if (caseInsensitive) { predicate = cb.equal(cb.lower(extension.get(ExtensionEntity_.urn)), urn.toLowerCase(Locale.ENGLISH)); } else { predicate = cb.equal(extension.get(ExtensionEntity_.urn), urn); } cq.select(extension).where(predicate); TypedQuery<ExtensionEntity> query = em.createQuery(cq); ExtensionEntity singleExtension; try { singleExtension = query.getSingleResult(); } catch (NoResultException e) { throw new OsiamException("Could not find the Extension '" + urn + "'.", e); } return singleExtension; }
From source file:com.jaxio.jpa.querybyexample.JpaUtil.java
public <E> Predicate stringPredicate(Expression<String> path, Object attrValue, SearchMode searchMode, SearchParameters sp, CriteriaBuilder builder) { if (sp.isCaseInsensitive()) { path = builder.lower(path); attrValue = ((String) attrValue).toLowerCase(LocaleContextHolder.getLocale()); }//from ww w .j a v a 2 s .c o 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!"); } }