Ejemplo n.º 1
0
  @Test
  public void Various() {
    StringPath str = user.lastName;
    List<Predicate> predicates = new ArrayList<Predicate>();
    predicates.add(str.between("a", "b"));
    predicates.add(str.contains("a"));
    predicates.add(str.containsIgnoreCase("a"));
    predicates.add(str.endsWith("a"));
    predicates.add(str.endsWithIgnoreCase("a"));
    predicates.add(str.eq("a"));
    predicates.add(str.equalsIgnoreCase("a"));
    predicates.add(str.goe("a"));
    predicates.add(str.gt("a"));
    predicates.add(str.in("a", "b", "c"));
    predicates.add(str.isEmpty());
    predicates.add(str.isNotNull());
    predicates.add(str.isNull());
    //        predicates.add(str.like("a"));
    predicates.add(str.loe("a"));
    predicates.add(str.lt("a"));
    predicates.add(str.matches("a"));
    predicates.add(str.ne("a"));
    predicates.add(str.notBetween("a", "b"));
    predicates.add(str.notIn("a", "b", "c"));
    predicates.add(str.startsWith("a"));
    predicates.add(str.startsWithIgnoreCase("a"));

    for (Predicate predicate : predicates) {
      where(predicate).count();
      where(predicate.not()).count();
    }
  }
Ejemplo n.º 2
0
 @Test(expected = UnsupportedOperationException.class)
 public void Starts_With_Ignore_Case_Phrase_Does_Not_Find_Results() throws Exception {
   testQuery(title.startsWithIgnoreCase("urassic Par"), "+title:urassic* +title:*par*", 0);
 }
Ejemplo n.º 3
0
  /**
   * Creates a Predicate from list of BooleanExpression predicates which represents all search
   * filters.
   *
   * @param config PaginationConfiguration data holding object
   * @return query to filter entities according pagination configuration data.
   */
  @SuppressWarnings({"rawtypes", "unchecked"})
  protected Predicate getPredicate(PaginationConfiguration config) {

    PathBuilder<T> entityPath = new PathBuilder(entityClass, getAliasName(entityClass));
    BooleanExpression predicate = null;

    Map<String, Object> filters = config.getFilters();
    if (filters != null) {
      // first we process nonstandard filters
      List<String> filtersToRemove = processNonStandardFilters(filters, entityPath);
      filters = removeUsedFilters(filtersToRemove, filters);
      if (!filters.isEmpty()) {
        for (Map.Entry<String, Object> entry : filters.entrySet()) {
          String key = entry.getKey();
          Object filter = entry.getValue();
          if (filter != null) {

            // if ranged search (from - to fields)
            if (key.contains("fromRange-")) {
              // CHECKSTYLE:OFF
              String parsedKey = key.substring(10);
              // CHECKSTYLE:ON
              if (filter instanceof Number) {
                NumberPath path = createNumberPath(entityPath, parsedKey, filter);
                predicate = and(predicate, path.goe((Number) filter));
              } else if (filter instanceof Date) {
                DatePath path = entityPath.getDate(parsedKey, Date.class);
                predicate = and(predicate, path.goe((Date) filter));
              }
            } else if (key.contains("toRange-")) {
              // CHECKSTYLE:OFF
              String parsedKey = key.substring(8);
              // CHECKSTYLE:ON
              if (filter instanceof Number) {
                NumberPath path = createNumberPath(entityPath, parsedKey, filter);
                predicate = and(predicate, path.loe((Number) filter));
              } else if (filter instanceof Date) {
                DatePath path = entityPath.getDate(parsedKey, Date.class);
                predicate = and(predicate, path.loe((Date) filter));
              }
            } else if (key.contains("list-")) {
              // CHECKSTYLE:OFF
              // if searching elements from list
              String parsedKey = key.substring(5);
              // CHECKSTYLE:ON
              ListPath path = entityPath.getList(parsedKey, filter.getClass());
              predicate = and(predicate, path.contains(filter));
            } else { // if not ranged search
              if (filter instanceof String) {
                StringPath path = entityPath.getString(key);
                String filterString = (String) filter;
                predicate = and(predicate, path.startsWithIgnoreCase(filterString));
              } else if (filter instanceof Date) {
                DatePath path = entityPath.getDate(key, Date.class);
                predicate = and(predicate, path.eq(filter));
              } else if (filter instanceof Number) {
                NumberPath path = createNumberPath(entityPath, key, filter);
                predicate = and(predicate, path.eq(filter));
              } else if (filter instanceof Boolean) {
                BooleanPath path = entityPath.getBoolean(key);
                predicate = and(predicate, path.eq((Boolean) filter));
              } else if (filter instanceof Enum) {
                EnumPath path = entityPath.getEnum(key, Enum.class);
                predicate = and(predicate, path.eq(filter));
              } else if (BaseEntity.class.isAssignableFrom(filter.getClass())) {
                PathBuilder path = entityPath.get(key);
                predicate = and(predicate, path.eq(filter));
              }
            }
          }
        }
      }
    }
    return predicate;
  }