Example usage for javax.persistence.criteria Root joinSet

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

Introduction

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

Prototype

<X, Y> SetJoin<X, Y> joinSet(String attributeName);

Source Link

Document

Create an inner join to the specified Set-valued attribute.

Usage

From source file:org.ngrinder.perftest.repository.TagSpecification.java

/**
 * Get the {@link Specification} which checks if the tag has corresponding perfTests.
 *
 * @return {@link Specification}/*from w  ww  .  j  a va 2 s .  c o  m*/
 */
public static Specification<Tag> hasPerfTest() {
    return new Specification<Tag>() {
        @Override
        public Predicate toPredicate(Root<Tag> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            SetJoin<Object, Object> join = root.joinSet("perfTests");
            query.groupBy(root.get("id"));
            return join.get("id").isNotNull();
        }
    };
}

From source file:org.ngrinder.perftest.repository.PerfTestSpecification.java

/**
 * Get the {@link Specification} checking if the {@link PerfTest#getTags()} has the given tagValue.
 *
 * @param tagValue tagValue//w  w w.  ja v  a2 s . c om
 * @return {@link Specification}
 */
public static Specification<PerfTest> hasTag(final String tagValue) {
    return new Specification<PerfTest>() {
        @Override
        public Predicate toPredicate(Root<PerfTest> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
            SetJoin<Object, Object> join = root.joinSet("tags");
            return cb.equal(join.get("tagValue"), tagValue);
        }
    };
}

From source file:de.ks.idnadrev.information.view.InformationOverviewDS.java

private List<InformationPreviewItem> getResults(String name, List<String> tagNames, Category category,
        EntityManager em, CriteriaBuilder builder, Class<? extends Information<?>> clazz) {
    CriteriaQuery<InformationPreviewItem> query = builder.createQuery(InformationPreviewItem.class);
    Root<? extends Information<?>> root = query.from(clazz);

    ArrayList<Predicate> filters = new ArrayList<>();
    if (!name.isEmpty()) {
        filters.add(builder.like(builder.lower(root.<String>get(KEY_NAME)), name));
    }//ww w . j ava 2s. co  m
    if (!tagNames.isEmpty()) {
        List<Tag> tags = getTags(tagNames, em);
        SetJoin<TextInfo, Tag> tagJoin = root.joinSet(KEY_TAGS);
        filters.add(tagJoin.in(tags));
    }
    if (category != null) {
        filters.add(builder.equal(root.get(KEY_CATEGORY), category));
    }
    query.distinct(true);

    query.where(filters.toArray(new Predicate[filters.size()]));
    query.select(
            builder.construct(InformationPreviewItem.class, root.get(KEY_NAME), root.get(KEY_CREATIONTIME)));
    List<InformationPreviewItem> resultList = em.createQuery(query).getResultList();
    return resultList;
}