Example usage for javax.persistence.criteria CriteriaBuilder like

List of usage examples for javax.persistence.criteria CriteriaBuilder like

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder like.

Prototype

Predicate like(Expression<String> x, String pattern);

Source Link

Document

Create a predicate for testing whether the expression satisfies the given pattern.

Usage

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// w ww  .  j ava2s .c  om
        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.hengyi.japp.execution.Util.java

public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Customer> root,
        CustomerQueryCommand command) {//w  w  w . ja v a  2s. 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.goodhuddle.huddle.repository.BlogPostSpecification.java

public static Specification<BlogPost> search(final Huddle huddle, final SearchBlogPostRequest request) {
    return new Specification<BlogPost>() {
        @Override/*from  w ww.j a  va 2 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:edu.pitt.dbmi.ccd.db.specification.AnnotationSpecification.java

/**
 * Requester access predicate//  w w  w  .  j  a  v a2  s  .  c o m
 * <p>
 * annotation has public access OR annotation has private access AND
 * annotation belongs to requester OR annotation has group access AND
 * requester is in group
 */
private static Predicate authFilter(Root<Annotation> root, CriteriaBuilder cb, UserAccount requester) {
    final List<Predicate> predicates = new ArrayList<>(0);

    // public access
    predicates.add(cb.like(root.get(ACCESS).get(NAME), PUBLIC_ACCESS));

    // private access AND belongs to requester
    predicates.add(
            cb.and(cb.like(root.get(ACCESS).get(NAME), PRIVATE_ACCESS), cb.equal(root.get(USER), requester)));

    // group access AND requester in group
    // criteriabuilder's in clause throws
    // sql error if collection has no elements
    if (requester.getGroups().size() > 0) {
        predicates.add(cb.and(cb.like(root.get(ACCESS).get(NAME), GROUP_ACCESS),
                root.get(GROUP).in(requester.getGroups())));
    }
    return cb.or(predicates.toArray(new Predicate[predicates.size()]));
}

From source file:com.hengyi.japp.execution.Util.java

public static void queryCommand(CriteriaBuilder cb, CriteriaQuery<?> cq, Root<Experience> root,
        ExperienceQueryCommand command) {
    List<Predicate> ps = Lists.newArrayListWithCapacity(2);
    if (command.getCustomers() != null) {
        ps.add(root.get(Experience_.customer).in(command.getCustomers()));
    }/*from w ww.  j  a v  a  2s  .  c  om*/
    if (!isBlank(command.getName())) {
        ps.add(cb.like(root.get(Experience_.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<ExperienceTag> root,
        ExperienceTagQueryCommand command) {
    List<Predicate> ps = Lists.newArrayListWithCapacity(2);
    if (command.getCustomers() != null) {
        ps.add(root.get(ExperienceTag_.customer).in(command.getCustomers()));
    }//from  w  w w.j  a  v a 2s .  c  om
    if (!isBlank(command.getName())) {
        ps.add(cb.like(root.get(ExperienceTag_.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<TaskSmsTemplate> root,
        TaskSmsTemplateQueryCommand command) {
    List<Predicate> ps = Lists.newArrayListWithCapacity(2);
    if (command.getCustomers() != null) {
        ps.add(root.get(TaskSmsTemplate_.customer).in(command.getCustomers()));
    }// w w w  .  ja  v a 2 s  .com
    if (!isBlank(command.getName())) {
        ps.add(cb.like(root.get(TaskSmsTemplate_.name), command.getNameQuery()));
    }
    cq.where(ps.toArray(new Predicate[ps.size()]));
}