Example usage for javax.persistence.metamodel ManagedType getList

List of usage examples for javax.persistence.metamodel ManagedType getList

Introduction

In this page you can find the example usage for javax.persistence.metamodel ManagedType getList.

Prototype

ListAttribute<? super X, ?> getList(String name);

Source Link

Document

Return the List-valued attribute of the managed type that corresponds to the specified name.

Usage

From source file:com.dbs.sdwt.jpa.ByExampleUtil.java

public <T> List<Predicate> byExampleOnXToMany(ManagedType<T> mt, Root<T> mtPath, T mtValue, SearchParameters sp,
        CriteriaBuilder builder) {//  www.j  ava2s .c  om
    List<Predicate> predicates = newArrayList();
    for (PluralAttribute<? super T, ?, ?> pa : mt.getPluralAttributes()) {
        if (pa.getCollectionType() == PluralAttribute.CollectionType.LIST) {
            List<?> values = (List<?>) jpaUtil.getValue(mtValue, mt.getAttribute(pa.getName()));
            if (values != null && !values.isEmpty()) {
                if (sp.getUseAndInXToMany()) {
                    if (values.size() > 3) {
                        log.warn(
                                "Please note that using AND restriction on an Many to Many relationship requires as many joins as values");
                    }
                    for (Object value : values) {
                        ListJoin<T, ?> join = mtPath.join(mt.getList(pa.getName()));
                        predicates.add(join.in(value));
                    }
                } else {
                    ListJoin<T, ?> join = mtPath.join(mt.getList(pa.getName()));
                    predicates.add(join.in(values));
                }
            }
        }
    }
    return predicates;
}

From source file:org.querybyexample.jpa.ByExampleUtil.java

/**
 * Construct a join predicate on collection (eg many to many, List)
 *///  w ww  .  jav  a2s . c  o m
public <T> List<Predicate> byExampleOnManyToMany(ManagedType<T> mt, Root<T> mtPath, T mtValue,
        SearchParameters sp, CriteriaBuilder builder) {
    List<Predicate> predicates = newArrayList();
    for (PluralAttribute<? super T, ?, ?> pa : mt.getPluralAttributes()) {
        if (pa.getCollectionType() == PluralAttribute.CollectionType.LIST) {
            List<?> values = (List<?>) JpaUtil.getValue(mtValue, mt.getAttribute(pa.getName()));
            if (values != null && !values.isEmpty()) {
                if (sp.getUseANDInManyToMany()) {
                    if (values.size() > 3) {
                        log.warn(
                                "Please note that using AND restriction on an Many to Many relationship requires as many joins as values");
                    }
                    for (Object value : values) {
                        ListJoin<T, ?> join = mtPath.join(mt.getList(pa.getName()));
                        predicates.add(join.in(value));
                    }
                } else {
                    ListJoin<T, ?> join = mtPath.join(mt.getList(pa.getName()));
                    predicates.add(join.in(values));
                }
            }
        }
    }
    return predicates;
}