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, char escapeChar);

Source Link

Document

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

Usage

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/*w w w .ja  va  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));
        }
    };
}

From source file:ch.puzzle.itc.mobiliar.business.server.boundary.ServerView.java

private Predicate addFilters(Predicate p, CriteriaBuilder cb, String hostFilter, String appServerFilter,
        String runtimeFilter, String nodeFilter, String contextFilter, Path<String> hostPath,
        Path<String> appServerPath, Path<String> runtimePath, Path<String> nodePath, Path<String> contextPath) {

    if (!StringUtils.isEmpty(hostFilter)) {
        p = cb.and(p,//from w w w.  ja v a2  s.  co  m
                cb.like(cb.lower(hostPath), hostFilter.toLowerCase(), JpaWildcardConverter.ESCAPE_CHARACTER));
    }
    if (!StringUtils.isEmpty(nodeFilter)) {
        p = cb.and(p,
                cb.like(cb.lower(nodePath), nodeFilter.toLowerCase(), JpaWildcardConverter.ESCAPE_CHARACTER));
    }
    if (!StringUtils.isEmpty(appServerFilter)) {
        p = cb.and(p, cb.like(cb.lower(appServerPath), appServerFilter.toLowerCase(),
                JpaWildcardConverter.ESCAPE_CHARACTER));
    }
    if (!StringUtils.isEmpty(runtimeFilter)) {
        p = cb.and(p, cb.like(cb.lower(runtimePath), runtimeFilter.toLowerCase(),
                JpaWildcardConverter.ESCAPE_CHARACTER));
    }
    if (!StringUtils.isEmpty(contextFilter)) {
        p = cb.and(p, cb.equal(cb.lower(contextPath), contextFilter.toLowerCase()));
    }
    p = cb.and(p, cb.notEqual(contextPath, LOCAL_ENV));

    return p;
}