@Override
  public List<Map<String, Object>> listAtributosPorFecha(
      Localizacion ejemplo,
      String[] atributos,
      String[] atributosFecha,
      Timestamp fechaInicio,
      Timestamp fechaFin) {
    JPASearchProcessor jpaSP =
        new JPASearchProcessor(
            HibernateMetadataUtil.getInstanceForSessionFactory(this.getSessionFactory()));

    Search searchConfig = new Search(this.getEntityBeanType());

    if (ejemplo != null) {
      ExampleOptions exampleOptions = new ExampleOptions();
      exampleOptions.setExcludeNulls(true);
      searchConfig.addFilter(jpaSP.getFilterFromExample(ejemplo, exampleOptions));
    }

    for (String atrFec : atributosFecha) {
      if (fechaInicio == null) {
        searchConfig.addFilter(Filter.lessOrEqual(atrFec, fechaFin));
      } else {
        searchConfig.addFilter(
            Filter.and(
                Filter.greaterOrEqual(atrFec, fechaInicio), Filter.lessOrEqual(atrFec, fechaFin)));
      }
    }
    if (atributos != null && atributos.length > 0) {
      for (String a : atributos) {
        searchConfig.addField(a);
      }
      searchConfig.setResultMode(Search.RESULT_MAP);
    }
    searchConfig.addSort("fechaCreacion", false, true);

    return jpaSP.search(getEm(), searchConfig);
  }
Esempio n. 2
0
  /**
   * 根据表达式获取过滤
   *
   * @return
   */
  public Filter getFilter() {
    if ("eq".equalsIgnoreCase(this.getOperator()) || "=".equals(this.getOperator())) {
      return Filter.equal(this.getName(), this.getValue());
    } else if ("neq".equalsIgnoreCase(this.getOperator()) || "<>".equals(this.getOperator())) {
      return Filter.notEqual(this.getName(), this.getValue());
    } else if ("goe".equalsIgnoreCase(this.getOperator()) || ">=".equals(this.getOperator())) {
      return Filter.greaterOrEqual(this.getName(), this.getValue());
    } else if ("gt".equalsIgnoreCase(this.getOperator()) || ">".equals(this.getOperator())) {
      return Filter.greaterThan(this.getName(), this.getValue());
    } else if ("ilike".equalsIgnoreCase(this.getOperator())) {
      return Filter.ilike(this.getName(), (String) this.getValue());
    } else if ("like".equalsIgnoreCase(this.getOperator())) {
      return Filter.ilike(this.getName(), (String) this.getValue());
    } else if ("null".equalsIgnoreCase(this.getOperator())) {
      return Filter.isNull(this.getName());
    } else if ("notNull".equalsIgnoreCase(this.getOperator())) {
      return Filter.isNotNull(this.getName());
    } else if ("in".equalsIgnoreCase(this.getOperator())) {
      return Filter.in(this.getName(), this.getValue());
    } else if ("notIn".equalsIgnoreCase(this.getOperator())) {
      return Filter.notIn(this.getName());
    } else if ("lt".equalsIgnoreCase(this.getOperator()) || "<".equals(this.getOperator())) {
      return Filter.lessThan(this.getName(), this.getValue());
    } else if ("loe".equalsIgnoreCase(this.getOperator()) || "<".equals(this.getOperator())) {
      return Filter.lessOrEqual(this.getName(), this.getValue());
    } else if ("empty".equalsIgnoreCase(this.getOperator())) {
      return Filter.isEmpty(this.getName());
    } else if ("notEmpty".equalsIgnoreCase(this.getOperator())) {
      return Filter.isNotEmpty(this.getName());
    }

    return Filter.isNotNull(this.getName());
  }