Example usage for javax.persistence.criteria CriteriaBuilder or

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

Introduction

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

Prototype

Predicate or(Expression<Boolean> x, Expression<Boolean> y);

Source Link

Document

Create a disjunction of the given boolean expressions.

Usage

From source file:th.co.geniustree.dental.spec.DoctorSpec.java

public static Specification<Doctor> nameLike(final String keyword) {
    return new Specification<Doctor>() {

        @Override//www. j a v a 2s. co  m
        public Predicate toPredicate(Root<Doctor> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return cb.or(cb.like(root.get(Doctor_.nameTh), keyword),
                    cb.like(cb.upper(root.get(Doctor_.nameEng)), keyword.toUpperCase()));
        }
    };
}

From source file:th.co.geniustree.dental.spec.StaffSpec.java

public static Specification<Staff> nameLike(final String keyword) {
    return new Specification<Staff>() {

        @Override/* w  ww.  j a  va 2  s  .  c  o  m*/
        public Predicate toPredicate(Root<Staff> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return cb.or(cb.like(root.get(Staff_.nameTh), keyword),
                    cb.like(cb.upper(root.get(Staff_.nameEng)), keyword.toUpperCase()));
        }
    };
}

From source file:th.co.geniustree.dental.spec.AppointmentSpec.java

public static Specification<Appointment> nameDoctorLike(final String keyword) {
    return new Specification<Appointment>() {

        @Override/*from w  w w  .jav  a 2s  .com*/
        public Predicate toPredicate(Root<Appointment> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            return cb.or(
                    cb.like(cb.upper(root.get(Appointment_.doctor).get(Doctor_.nameEng)),
                            keyword.toUpperCase()),
                    cb.like(root.get(Appointment_.doctor).get(Doctor_.nameTh), keyword));
        }
    };
}

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. j av  a  2 s.  c om
 *
 * @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.mtt.myapp.user.repository.UserSpecification.java

/**
 * Create "Name Like" query spec.//from   w w w .j av  a 2s.c om
 * @param query query
 * @return created spec
 */
public static Specification<User> nameLike(final String query) {
    return new Specification<User>() {
        @Override
        public Predicate toPredicate(Root<User> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder cb) {
            String pattern = ("%" + query + "%").toLowerCase();
            return cb.or(cb.like(cb.lower(root.get("userName").as(String.class)), pattern),
                    cb.like(cb.lower(root.get("userId").as(String.class)), pattern));
        }
    };
}

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.co m*/
 * @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: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 a  2  s.  c o  m
 * @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:edu.pitt.dbmi.ccd.db.specification.GroupSpecification.java

private static List<Predicate> inNameOrDescription(Root<Group> root, CriteriaBuilder cb, Set<String> terms) {
    return terms.stream().map(t -> containsLike(t))
            .map(t -> cb.or(nameContains(root, cb, t), descriptionContains(root, cb, t)))
            .collect(Collectors.toList());
}

From source file:edu.pitt.dbmi.ccd.db.specification.GroupSpecification.java

private static List<Predicate> notInNameOrDescription(Root<Group> root, CriteriaBuilder cb, Set<String> terms) {
    return terms.stream().map(t -> containsLike(t))
            .map(t -> cb.not(cb.or(nameContains(root, cb, t), descriptionContains(root, cb, t))))
            .collect(Collectors.toList());
}

From source file:edu.pitt.dbmi.ccd.db.specification.VocabularySpecification.java

private static List<Predicate> inNameOrDescription(Root<Vocabulary> root, CriteriaBuilder cb,
        Set<String> terms) {
    return terms.stream().map(t -> containsLike(t))
            .map(t -> cb.or(nameContains(root, cb, t), descriptionContains(root, cb, t)))
            .collect(Collectors.toList());
}