use of org.apache.olingo.commons.api.edm.EdmPrimitiveType in project teiid by teiid.
the class ODataTypeManager method parseLiteral.
public static Object parseLiteral(String odataType, String value) throws TeiidException {
EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.valueOf(odataType.substring(4)));
int maxLength = DataTypeManager.MAX_STRING_LENGTH;
if (primitiveType instanceof EdmBinary || primitiveType instanceof EdmStream) {
maxLength = DataTypeManager.MAX_VARBINARY_BYTES;
}
int precision = 4;
int scale = 3;
if (primitiveType instanceof EdmDecimal) {
precision = 38;
scale = 9;
}
Class<?> expectedClass = primitiveType.getDefaultType();
try {
if (EdmString.getInstance().equals(primitiveType)) {
value = EdmString.getInstance().fromUriLiteral(value);
}
Object converted = primitiveType.valueOfString(value, false, maxLength, precision, scale, true, expectedClass);
if (primitiveType instanceof EdmTimeOfDay) {
Calendar ts = (Calendar) converted;
return new Time(ts.getTimeInMillis());
} else if (primitiveType instanceof EdmDate) {
Calendar ts = (Calendar) converted;
return new Date(ts.getTimeInMillis());
}
return converted;
} catch (EdmPrimitiveTypeException e) {
throw new TeiidException(e);
}
}
Aggregations