Example usage for javax.persistence.criteria Root get

List of usage examples for javax.persistence.criteria Root get

Introduction

In this page you can find the example usage for javax.persistence.criteria Root get.

Prototype

<Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);

Source Link

Document

Create a path corresponding to the referenced single-valued attribute.

Usage

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

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

        @Override/*from   www.j a v a 2  s.  c om*/
        public Predicate toPredicate(Root<DetailHeal> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return cb.between(root.get(DetailHeal_.dateHeal), keyword, keyword);
        }
    };
}

From source file:org.wallride.repository.PageSpecifications.java

public static Specification<Page> draft(Page page) {
    return (root, query, cb) -> {
        List<Predicate> predicates = new ArrayList<>();
        predicates.add(cb.equal(root.get(Page_.drafted), page));

        Subquery<Long> subquery = query.subquery(Long.class);
        Root<Page> p = subquery.from(Page.class);
        subquery.select(cb.max(p.get(Page_.id))).where(cb.equal(p.get(Page_.drafted), page));

        predicates.add(cb.equal(root.get(Page_.id), subquery));
        return cb.and(predicates.toArray(new Predicate[0]));
    };// w  w w  .j a  v  a  2 s . c  o  m
}

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

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

        @Override//from  w w w . j a  va 2  s . c  o  m
        public Predicate toPredicate(Root<DetailHeal> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
            return cb.like(cb.upper(root.get(DetailHeal_.patient).get(Patient_.name)), keyword);
        }
    };
}

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

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

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

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

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

        @Override// w w  w .j ava2  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:org.wallride.repository.PageSpecifications.java

public static Specification<Page> path(Page page, boolean includeUnpublished) {
    return (root, query, cb) -> {
        //         query.distinct(true);
        Root<Page> p1 = query.from(Page.class);
        Root<Page> p2 = root;//w  ww .  j av  a2 s  .  c  o  m
        Root<Page> p3 = query.from(Page.class);

        List<Predicate> predicates = new ArrayList<>();
        predicates.add(cb.equal(root.get(Page_.language), page.getLanguage()));
        if (!includeUnpublished) {
            predicates.add(cb.equal(root.get(Page_.status), Page.Status.PUBLISHED));
        }

        Subquery<Long> subquery = query.subquery(Long.class);
        Root<Page> p = subquery.from(Page.class);
        subquery.select(p.get(Page_.id)).where(cb.equal(p.get(Page_.language), page.getLanguage()),
                cb.isNull(p.get(Page_.parent)), cb.le(p.get(Page_.lft), page.getLft()),
                cb.ge(p.get(Page_.rgt), page.getRgt()));

        predicates.add(cb.equal(p1.get(Page_.id), subquery));
        predicates.add(cb.equal(p3.get(Page_.id), page.getId()));
        predicates.add(cb.between(p2.get(Page_.lft), p1.get(Page_.lft), p1.get(Page_.rgt)));
        predicates.add(cb.between(p3.get(Page_.lft), p2.get(Page_.lft), p2.get(Page_.rgt)));
        query.orderBy(cb.desc(cb.diff(p2.get(Page_.rgt), p2.get(Page_.lft))));
        return cb.and(predicates.toArray(new Predicate[0]));
    };
}

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./*from   w ww . j  a  v a  2  s. co  m*/
 *
 * @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:th.co.geniustree.dental.spec.DetailHealSpec.java

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

        @Override/*from www  .  j  a va 2 s.c  o  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/*from  w  w  w.  j a  va 2s .c  o  m*/
        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:org.ngrinder.agent.repository.AgentManagerSpecification.java

/**
 * Query specification to query the agent existing in the specified region.
 *
 * @param region region to query//from  w  w  w.  j av  a  2 s. 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));
        }
    };
}