Exemplo n.º 1
0
 /** Construct a join predicate on collection (eg many to many, List) */
 public <T> List<Predicate> byExampleOnManyToMany(
     ManagedType<T> mt,
     Root<T> mtPath,
     final T mtValue,
     SearchParameters sp,
     CriteriaBuilder builder) {
   List<Predicate> predicates = newArrayList();
   for (PluralAttribute<T, ?, ?> pa : mt.getDeclaredPluralAttributes()) {
     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.getDeclaredList(pa.getName()));
             predicates.add(join.in(value));
           }
         } else {
           ListJoin<T, ?> join = mtPath.join(mt.getDeclaredList(pa.getName()));
           predicates.add(join.in(values));
         }
       }
     }
   }
   return predicates;
 }