예제 #1
0
 /**
  * Convert the value as loaded from the SQL table into the expected variable value type (column
  * type may not match exactly the variable value type).
  *
  * @param variable
  * @param value
  * @return
  */
 private Value convertValue(Variable variable, Value value) {
   if (value.getValueType() != variable.getValueType()) {
     return variable.isRepeatable()
         ? convertToSequence(variable, value)
         : variable.getValueType().convert(value);
   }
   if (variable.isRepeatable() && !value.isSequence()) {
     return convertToSequence(variable, value);
   }
   return value;
 }
예제 #2
0
  public Value getValue(Variable variable) {
    if (variable.getValueType().isBinary()) return getBinaryValue(variable);

    loadResultSetCache();

    Value value = convertValue(variable, resultSetCache.get(variable.getName()));
    resultSetCache.put(variable.getName(), value);
    return value;
  }
예제 #3
0
  private Value getBinaryValue(Variable variable) {
    List<Map<String, Value>> res =
        loadValues(
            Lists.newArrayList(getValueTable().getVariableSqlName(variable.getName())), mapper);

    if (res.isEmpty())
      return variable.isRepeatable()
          ? variable.getValueType().nullSequence()
          : variable.getValueType().nullValue();

    Value value = res.get(0).get(variable.getName());
    return convertValue(variable, value);
  }
    /** Returns an iterator of category names */
    private Iterator<String> categoryNames() {
      if (variable.getValueType().equals(BooleanType.get())) {
        return ImmutableList.<String>builder() //
            .add(BooleanType.get().trueValue().toString()) //
            .add(BooleanType.get().falseValue().toString())
            .build()
            .iterator();
      }

      return Iterables.transform(
              variable.getCategories(),
              new Function<Category, String>() {

                @Override
                public String apply(Category from) {
                  return from.getName();
                }
              })
          .iterator();
    }
예제 #5
0
 private Value convertToSequence(Variable variable, Value value) {
   return value.isNull()
       ? variable.getValueType().nullSequence()
       : variable.getValueType().sequenceOf(value.toString());
 }