示例#1
0
  /** /xml/State/forCountry */
  public Collection<State> findSubsetForCountry(String countryParamId, Map<String, String> params) {
    Map<String, Object> map = buildParamsMap(params);
    Filter filters = dao.buildFiltersFromMap(map);

    Country countryParam = Country.DAO().findById(countryParamId);

    int pageNumber =
        params.get("_page") == null ? 1 : Integer.parseInt(params.get("_page").toString());
    int first = (pageNumber - 1) * 50;
    int max = params.get("_page") == null ? Integer.MAX_VALUE : 50;
    String hints = null;

    String order = (String) params.get("_order");
    if (order != null) {
      int index =
          (order.indexOf("d") > 0)
              ? Integer.valueOf(order.substring(0, order.indexOf("d")))
              : Integer.valueOf(order);
      String[] columns = new String[] {"name", ""};
      order = columns[index] + (order.indexOf("d") > 0 ? " desc" : "");
    }

    if (order == null) {
      order = "name";
    }

    int count = dao.count(filters.and(dao.getForCountrySubsetFilter(countryParam)));
    List<State> list = dao.findForCountry(countryParam, filters, order, first, max, hints);
    return new Page<State>(list, pageNumber, (count - 1) / max + 1, count);
  }
示例#2
0
  public Object store(String id, State voobj) {
    State obj;

    if (id.equals("0")) {
      obj = new State();

    } else {
      obj = State.DAO().findById(id);
    }

    boolean isNewStateN65961 = obj.getId() == null || obj.getId().equals(0L);

    obj.setName(voobj.getName());
    obj.setCountry(Country.DAO().findBy(voobj.getCountry()));

    return obj.store();
  }