Example usage for javax.persistence.criteria CriteriaBuilder and

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

Introduction

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

Prototype

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

Source Link

Document

Create a conjunction of the given boolean expressions.

Usage

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

public static Specification<PriceAndExpireProduct> productLike(final String keyword) {
    return new Specification<PriceAndExpireProduct>() {

        @Override//from w  w  w  . j av a 2  s. co m
        public Predicate toPredicate(Root<PriceAndExpireProduct> root, CriteriaQuery<?> cq,
                CriteriaBuilder cb) {
            return cb.and(cb.like(cb.upper(root.get(PriceAndExpireProduct_.product).get(Product_.name)),
                    keyword.toUpperCase()), cb.isNull(root.get(PriceAndExpireProduct_.status)));
        }
    };
}

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

public static Specification<PriceAndExpireProduct> expireBetween(final Date keyword) {
    return new Specification<PriceAndExpireProduct>() {

        @Override/*from w ww  .  j  ava  2  s  .  co m*/
        public Predicate toPredicate(Root<PriceAndExpireProduct> root, CriteriaQuery<?> cq,
                CriteriaBuilder cb) {
            return cb.and(cb.between(root.get(PriceAndExpireProduct_.expire), keyword, keyword),
                    cb.isNull(root.get(PriceAndExpireProduct_.status)));
        }
    };
}

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

public static Specification<PriceAndExpireProduct> lotInBetween(final Date keyword) {
    return new Specification<PriceAndExpireProduct>() {

        @Override/*from   w ww  .j  a  v  a2s.c  o  m*/
        public Predicate toPredicate(Root<PriceAndExpireProduct> root, CriteriaQuery<?> cq,
                CriteriaBuilder cb) {
            return cb.and(cb.between(root.get(PriceAndExpireProduct_.lot).get(Lot_.dateIn), keyword, keyword),
                    cb.isNull(root.get(PriceAndExpireProduct_.status)));
        }
    };
}

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

public static Specification<DetailHeal> patientLikeForBill(final String keyword) {
    return new Specification<DetailHeal>() {

        @Override// w  ww.java2 s  .  co m
        public Predicate toPredicate(Root<DetailHeal> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return cb.and(cb.like(cb.upper(root.get(DetailHeal_.patient).get(Patient_.name)), keyword),
                    cb.isNull(root.get(DetailHeal_.status)));
        }
    };
}

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

public static Specification<DetailHeal> doctorLikeForBill(final String keyword) {
    return new Specification<DetailHeal>() {

        @Override/*  ww w. j  a v  a  2  s.  c  om*/
        public Predicate toPredicate(Root<DetailHeal> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return cb.and(cb.like(cb.upper(root.get(DetailHeal_.doctor).get(Doctor_.nameTh)), keyword),
                    cb.isNull(root.get(DetailHeal_.status)));
        }
    };
}

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

public static Specification<DetailHeal> dateHealLikeForBill(final Date keyword) {
    return new Specification<DetailHeal>() {

        @Override/* ww w .j ava 2  s  .co m*/
        public Predicate toPredicate(Root<DetailHeal> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return cb.and(cb.between(root.get(DetailHeal_.dateHeal), keyword, keyword),
                    cb.isNull(root.get(DetailHeal_.status)));
        }
    };
}

From source file:example.springdata.jpa.showcase.snippets.CustomerSpecifications.java

/**
 * All customers with an {@link Account} expiring before the given date.
 * //  w  w  w.  j a va  2  s.  co  m
 * @param date
 * @return
 */
public static Specification<Customer> accountExpiresBefore(final LocalDate date) {

    return new Specification<Customer>() {

        @Override
        public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {

            Root<Account> accounts = query.from(Account.class);
            Path<Date> expiryDate = accounts.<Date>get("expiryDate");
            Predicate customerIsAccountOwner = cb.equal(accounts.<Customer>get("customer"), root);
            Predicate accountExpiryDateBefore = cb.lessThan(expiryDate, date.toDateTimeAtStartOfDay().toDate());

            return cb.and(customerIsAccountOwner, accountExpiryDateBefore);
        }
    };
}

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  ww w.  j a  va 2s  .  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(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 ww .  j  a  va 2s .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()))));
}