示例#1
0
  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));
        }
      }
    }
  }
示例#2
0
 private static <T> Object readParameterValue(Class<T> clazz, QueryParameter param, String svalue)
     throws ResourceException {
   if (svalue == null) {
     return null;
   } else {
     try {
       if (param.getArray()) {
         JSONArray ja = new JSONArray(svalue);
         List<T> a = new ArrayList<>();
         for (int i = 0; i < ja.length(); i++) {
           a.add(BaseResource.convertValue(clazz, ja.getString(i)));
         }
         return a.toArray();
       } else {
         return BaseResource.convertValue(clazz, svalue);
       }
     } catch (JSONException ex) {
       throw new ClientErrorException(Status.CLIENT_ERROR_BAD_REQUEST, ex);
     }
   }
 }