예제 #1
0
 @Nullable
 public static List<String> getStrings(
     Map<String, Object> map, String name, @Nullable List<String> defaultValue) throws Exception {
   @Nullable Object value = map.get(name);
   if (value == null) {
     if (map.containsKey(name)) {
       throw new IncorrectTypeException(name, map, "a string or a list");
     }
     return defaultValue;
   }
   if (Data.isNull(value)) {
     // This is a JSON literal null.  When represented as a list of strings,
     // this is an empty list.
     return Collections.<String>emptyList();
   }
   @Nullable String singletonString = decodeValue(value, String.class);
   if (singletonString != null) {
     return Collections.singletonList(singletonString);
   }
   if (!(value instanceof List)) {
     throw new IncorrectTypeException(name, map, "a string or a list");
   }
   @SuppressWarnings("unchecked")
   List<Object> elements = (List<Object>) value;
   List<String> result = new ArrayList<>(elements.size());
   for (Object o : elements) {
     @Nullable String s = decodeValue(o, String.class);
     if (s == null) {
       throw new IncorrectTypeException(name, map, "a list of strings");
     }
     result.add(s);
   }
   return result;
 }
예제 #2
0
  @Nullable
  public static List<Map<String, Object>> getListOfMaps(
      Map<String, Object> map, String name, @Nullable List<Map<String, Object>> defaultValue)
      throws Exception {
    @Nullable Object value = map.get(name);
    if (value == null) {
      if (map.containsKey(name)) {
        throw new IncorrectTypeException(name, map, "a list");
      }
      return defaultValue;
    }
    if (Data.isNull(value)) {
      // This is a JSON literal null.  When represented as a list,
      // this is an empty list.
      return Collections.<Map<String, Object>>emptyList();
    }

    if (!(value instanceof List)) {
      throw new IncorrectTypeException(name, map, "a list");
    }

    List<?> elements = (List<?>) value;
    for (Object elem : elements) {
      if (!(elem instanceof Map)) {
        throw new IncorrectTypeException(name, map, "a list of Map objects");
      }
    }

    @SuppressWarnings("unchecked")
    List<Map<String, Object>> result = (List<Map<String, Object>>) elements;
    return result;
  }
예제 #3
0
  /** {@inheritDoc} */
  @Override
  public Object getObject(int columnIndex) throws SQLException {
    // to make the logfiles smaller!
    // logger.debug("Function call getObject columnIndex is: " + String.valueOf(columnIndex));
    this.closestrm();
    if (this.isClosed()) {
      throw new BQSQLException("This Resultset is Closed");
    }
    this.ThrowCursorNotValidExeption();
    if (this.RowsofResult == null) {
      throw new BQSQLException("There are no rows in this Resultset");
    }
    if (this.getMetaData().getColumnCount() < columnIndex || columnIndex < 1) {
      throw new BQSQLException("ColumnIndex is not valid");
    }
    String Columntype = this.Result.getSchema().getFields().get(columnIndex - 1).getType();

    TableCell field = ((TableRow) this.RowsofResult[this.Cursor]).getF().get(columnIndex - 1);

    if (Data.isNull(field.getV())) {
      this.wasnull = true;
      return null;
    } else {
      String result = field.getV().toString();
      this.wasnull = false;
      try {
        if (Columntype.equals("STRING")) {
          // removing the excess byte by the setmaxFiledSize
          if (maxFieldSize == 0 || maxFieldSize == Integer.MAX_VALUE) {
            return result;
          } else {
            try { // lets try to remove the excess bytes
              return result.substring(0, maxFieldSize);
            } catch (IndexOutOfBoundsException iout) {
              // we don't need to remove any excess byte
              return result;
            }
          }
        }
        if (Columntype.equals("FLOAT")) {
          return Float.parseFloat(result);
        }
        if (Columntype.equals("BOOLEAN")) {
          return Boolean.parseBoolean(result);
        }
        if (Columntype.equals("INTEGER")) {
          return Long.parseLong(result);
        }
        if (Columntype.equals("TIMESTAMP")) {
          long val = new BigDecimal(result).longValue() * 1000;
          return new Timestamp(val);
        }
        throw new BQSQLException("Unsupported Type (" + Columntype + ")");
      } catch (NumberFormatException e) {
        throw new BQSQLException(e);
      }
    }
  }
예제 #4
0
 public static Map<String, Object> getDictionary(Map<String, Object> map, String name)
     throws Exception {
   @Nullable Object value = map.get(name);
   if (value == null) {
     throw new ParameterNotFoundException(name, map);
   }
   if (Data.isNull(value)) {
     // This is a JSON literal null.  When represented as a dictionary, this is
     // an empty map.
     return Collections.<String, Object>emptyMap();
   }
   if (!(value instanceof Map)) {
     throw new IncorrectTypeException(name, map, "a dictionary");
   }
   @SuppressWarnings("unchecked")
   Map<String, Object> result = (Map<String, Object>) value;
   return result;
 }
예제 #5
0
 private static Map<String, Object> checkObject(Object value, Map<String, Object> map, String name)
     throws Exception {
   if (Data.isNull(value)) {
     // This is a JSON literal null.  When represented as an object, this is an
     // empty map.
     return Collections.<String, Object>emptyMap();
   }
   if (!(value instanceof Map)) {
     throw new IncorrectTypeException(name, map, "an object (not a map)");
   }
   @SuppressWarnings("unchecked")
   Map<String, Object> mapValue = (Map<String, Object>) value;
   if (!mapValue.containsKey(PropertyNames.OBJECT_TYPE_NAME)) {
     throw new IncorrectTypeException(
         name, map, "an object (no \"" + PropertyNames.OBJECT_TYPE_NAME + "\" field)");
   }
   return mapValue;
 }