示例#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;
  }
 /**
  * Encode the given value into a stream that can then be passed to <code>writeByteStream</code>.
  */
 public ByteArrayOutputStream encodeValue(ValueSource value, ServerType type, boolean binary)
     throws IOException {
   if (value.isNull()) return null;
   if ((zeroDateTimeBehavior != ZeroDateTimeBehavior.NONE)
       && (((type.getType().typeClass() == MDateAndTime.DATE) && (value.getInt32() == 0))
           || ((type.getType().typeClass() == MDateAndTime.DATETIME)
               && (value.getInt64() == 0)))) {
     switch (zeroDateTimeBehavior) {
       case EXCEPTION:
         throw new ZeroDateTimeException();
       case ROUND:
         value =
             (type.getType().typeClass() == MDateAndTime.DATETIME)
                 ? ROUND_ZERO_DATETIME_SOURCE
                 : ROUND_ZERO_DATE_SOURCE;
         break;
       case CONVERT_TO_NULL:
         return null;
     }
   }
   reset();
   appendValue(value, type, binary);
   return getByteStream();
 }