コード例 #1
0
ファイル: Handler.java プロジェクト: eimarfandino/resthub
  public Handler(Query query, Form form) throws ResourceException {
    this.query = query;
    this.queryString = form.getQueryString();
    for (QueryParameter p : query.getParameters()) {

      String name = p.getName();
      String svalue = form.getFirstValue(name, true);

      switch (p.getType()) {
        case DATE:
          parameters.put(p, readParameterValue(Date.class, p, svalue));
          break;

        case NUMBER:
          parameters.put(p, readParameterValue(BigDecimal.class, p, svalue));
          break;

        case STRING:
          parameters.put(p, readParameterValue(String.class, p, svalue));
          break;

        case CLOB:
        case BLOB:
          throw new ClientErrorException(
              Status.CLIENT_ERROR_BAD_REQUEST,
              String.format("LOBs are not supported as parameters: %s", name));
      }
    }

    if (log.isDebugEnabled()) {
      for (QueryParameter qp : parameters.keySet()) {
        log.debug(qp.toString(parameters.get(qp)));
      }
    }
  }
コード例 #2
0
ファイル: Handler.java プロジェクト: eimarfandino/resthub
  public void applyParameters(SQLQuery query) throws SQLException {
    for (Map.Entry<QueryParameter, Object> e : parameters.entrySet()) {

      QueryParameter p = e.getKey();
      Object value = e.getValue();
      String name = p.getSqlName();

      if (value != null && p.getArray()) {

        switch (p.getType()) {
          case DATE:
            query.setParameterList(name, (Object[]) value, new DateType());
            break;
          case NUMBER:
            query.setParameterList(name, (Object[]) value, new BigDecimalType());
            break;
          case STRING:
            query.setParameterList(name, (Object[]) value, new StringType());
            break;
          case CLOB:
          case BLOB:
            throw new ClientErrorException(
                Status.CLIENT_ERROR_BAD_REQUEST,
                String.format("LOBs are not supported as parameters: %s", name));
        }

      } else {

        switch (p.getType()) {
          case DATE:
            query.setDate(name, (Date) value);
            break;
          case NUMBER:
            query.setBigDecimal(name, (BigDecimal) value);
            break;
          case STRING:
            query.setString(name, (String) value);
            break;
          case CLOB:
          case BLOB:
            throw new ClientErrorException(
                Status.CLIENT_ERROR_BAD_REQUEST,
                String.format("LOBs are not supported as parameters: %s", name));
        }
      }
    }
  }