/** 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(); } }
/** @see #getIntegerValue */ public void setIntegerValue(ValueTarget target, long value) { switch (TInstance.underlyingType(target.getType())) { case INT_8: target.putInt8((byte) value); break; case INT_16: target.putInt16((short) value); break; case UINT_16: target.putUInt16((char) value); break; case INT_32: target.putInt32((int) value); break; case INT_64: default: target.putInt64(value); } }
public static Value valuefromObject(Object object, TInstance type, QueryContext queryContext) { Value value = new Value(type); if (object == null) { value.putNull(); } else if (object instanceof String) { // This is the common case, so let's test for it first if (TInstance.underlyingType(type) == UnderlyingType.STRING) value.putString((String) object, null); else if (type == null) { type = MString.VARCHAR.instance( ((String) object).length(), StringFactory.DEFAULT_CHARSET.ordinal(), StringFactory.NULL_COLLATION_ID, false); value = new Value(type, (String) object); } } else if (type == null) { value = fromObject(object); } else if (object instanceof BlobRef) { value.putObject(object); } else { switch (TInstance.underlyingType(type)) { case INT_8: case INT_16: case UINT_16: case INT_32: case INT_64: if (object instanceof Number) valueFromLong(((Number) object).longValue(), value); break; case FLOAT: if (object instanceof Number) value.putFloat(((Number) object).floatValue()); break; case DOUBLE: if (object instanceof Number) value.putDouble(((Number) object).doubleValue()); break; case BYTES: if (object instanceof byte[]) value.putBytes((byte[]) object); else if (object instanceof ByteSource) value.putBytes(((ByteSource) object).toByteSubarray()); else if (object instanceof JTSSpatialObject) { if (AkBlob.isBlob(type.typeClass())) { byte[] content = Spatial.serializeWKB((JTSSpatialObject) object); value.putObject(new BlobRef(content)); } } break; case STRING: if ((object instanceof JTSSpatialObject)) { value = new Value(type, Spatial.serializeWKT((JTSSpatialObject) object)); } else { throw new IllegalArgumentException("Unsafe toString(): " + object.getClass()); } break; case BOOL: if (object instanceof Boolean) value.putBool((Boolean) object); break; } } if (!value.hasAnyValue()) { if (type == null) { value = fromObject(object); } else { value = convertFromObject(object, type, queryContext); } } return value; }
public static UnderlyingType underlyingType(ValueSource source) { return TInstance.underlyingType(source.getType()); }