in empire-db/src/main/java/org/apache/empire/commons/ValueUtils.java [848:907]
public Object convertToData(DataType dataType, Object value)
{
// check null
if (value == null)
return null;
// Cannot convert DBEXpr, return as is
if (value instanceof DBExpr)
return value;
// Strings special
if ((value instanceof String) && ((String)value).length()==0)
return null;
// check option entry
if (value instanceof OptionEntry)
{ // option value
value = ((OptionEntry)value).getValue();
}
// check for enum
if (value instanceof Enum<?>)
{ // Convert Enum now (optional)
// value = getEnumValue((Enum<?>)value, dataType.isNumeric());
// Otherwise Enum will be converted later
return value;
}
// check type
switch (dataType)
{
case BLOB:
return value; // unchanged
case BOOL:
return toBoolean(value, false);
case DATE:
case DATETIME:
case TIMESTAMP:
// check type
if ((value instanceof Date) || (value instanceof Temporal))
return value; // already a date or temporal
// sysdate
if (DBDatabase.SYSDATE.equals(value))
return value; // leave SYSDATE as is
// try to convert
try {
return toDate(value);
} catch (ParseException e) {
throw new ValueConversionException(Date.class, value, e);
}
case INTEGER:
return (value instanceof Number) ? value : toLong(value);
case FLOAT:
return (value instanceof Number) ? value : toDouble(value);
case DECIMAL:
return (value instanceof Number) ? value : toDecimal(value);
case CHAR:
case CLOB:
case VARCHAR:
return (value instanceof String) ? value : value.toString(); // not not call getString(...);
default:
// use as is
return value;
}
}