Пример #1
0
  /** Add a predicate for each simple property whose value is not null. */
  public <T> List<Predicate> byExample(
      ManagedType<T> mt,
      Path<T> mtPath,
      final T mtValue,
      SearchParameters sp,
      CriteriaBuilder builder) {
    List<Predicate> predicates = newArrayList();
    for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) {
      if (attr.getPersistentAttributeType() == MANY_TO_ONE //
          || attr.getPersistentAttributeType() == ONE_TO_ONE //
          || attr.getPersistentAttributeType() == EMBEDDED) {
        continue;
      }

      Object attrValue = JpaUtil.getValue(mtValue, attr);
      if (attrValue != null) {
        if (attr.getJavaType() == String.class) {
          if (isNotEmpty((String) attrValue)) {
            predicates.add(
                JpaUtil.stringPredicate(
                    mtPath.get(JpaUtil.stringAttribute(mt, attr)), attrValue, sp, builder));
          }
        } else {
          predicates.add(builder.equal(mtPath.get(JpaUtil.attribute(mt, attr)), attrValue));
        }
      }
    }
    return predicates;
  }
Пример #2
0
 @Override
 public Map<String, Map<String, Class<?>>> getTableColumnMap() {
   Metamodel metamodel = entityManager.getEntityManagerFactory().getMetamodel();
   Set<EntityType<?>> entityTypes = metamodel.getEntities();
   Map<String, Map<String, Class<?>>> tableColumnMap =
       new HashMap<String, Map<String, Class<?>>>();
   for (EntityType<?> type : entityTypes) {
     EntityType<Entity> entityType = (EntityType<Entity>) type;
     Set<SingularAttribute<? super Entity, ?>> singularAttributes =
         entityType.getSingularAttributes();
     Map<String, Class<?>> columnMap = new HashMap<String, Class<?>>();
     for (SingularAttribute<? super Entity, ?> singularAttribute : singularAttributes) {
       columnMap.put(singularAttribute.getName(), singularAttribute.getJavaType());
     }
     tableColumnMap.put(entityType.getName(), columnMap);
   }
   return tableColumnMap;
 }
 public boolean isBoolean() {
   return field != null && field.getJavaType().isAssignableFrom(Boolean.class);
 }