Пример #1
0
 /** Give a <code>ValueSource</code> whose {@link #jdbcType} claims
  * to be one of the integer types (<code>TINYINT</code>,
  * <code>SMALLINT</code>, <code>INTEGER</code>,
  * <code>BIGINT<code>), get the integer value.  Needed because of
  * <code>UNSIGNED</code> and <code>YEAR</code> types.
  */
 public long getIntegerValue(ValueSource value) {
   switch (TInstance.underlyingType(value.getType())) {
     case INT_8:
       return value.getInt8();
     case INT_16:
       return value.getInt16();
     case UINT_16:
       return value.getUInt16();
     case INT_32:
       return value.getInt32();
     case INT_64:
     default:
       return value.getInt64();
   }
 }
Пример #2
0
  protected boolean tryFromObject(TExecutionContext context, ValueSource in, ValueTarget out) {
    if (in.getType().equalsExcludingNullable(out.getType())) {
      ValueTargets.copyFrom(in, out);
      return true;
    }

    UnderlyingType underlyingType = TInstance.underlyingType(in.getType());
    if (underlyingType == UnderlyingType.STRING || underlyingType == UnderlyingType.BYTES)
      return false;
    final String asString;
    switch (underlyingType) {
      case BOOL:
        asString = Boolean.toString(in.getBoolean());
        break;
      case INT_8:
        asString = Byte.toString(in.getInt8());
        break;
      case INT_16:
        asString = Short.toString(in.getInt16());
        break;
      case UINT_16:
        asString = Integer.toString(in.getUInt16());
        break;
      case INT_32:
        asString = Integer.toString(in.getInt32());
        break;
      case INT_64:
        asString = Long.toString(in.getInt64());
        break;
      case FLOAT:
        asString = Float.toString(in.getFloat());
        break;
      case DOUBLE:
        asString = Double.toString(in.getDouble());
        break;
      case BYTES:
      case STRING:
      default:
        throw new AssertionError(underlyingType + ": " + in);
    }
    parser.parse(context, new Value(MString.varcharFor(asString), asString), out);
    return true;
  }