use of org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset in project teiid by teiid.
the class EntityCollectionResponse method getPropertyValueInternal.
private static Object getPropertyValueInternal(SingletonPrimitiveType expectedType, boolean isArray, Object value) throws TransformationException, SQLException, IOException {
Class<?> sourceType = DataTypeManager.getRuntimeType(value.getClass());
if (sourceType.isAssignableFrom(expectedType.getDefaultType())) {
return value;
}
if (expectedType instanceof EdmDate && sourceType == Date.class) {
return value;
} else if (expectedType instanceof EdmDateTimeOffset && sourceType == Timestamp.class) {
return value;
} else if (expectedType instanceof EdmTimeOfDay && sourceType == Time.class) {
return value;
} else if (expectedType instanceof EdmBinary) {
// there could be memory implications here, should have been modeled as EdmStream
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_ODATA, "Possible OOM when inlining the stream based values");
if (sourceType == ClobType.class) {
return ClobType.getString((Clob) value).getBytes();
}
if (sourceType == SQLXML.class) {
return ((SQLXML) value).getString().getBytes();
}
if (sourceType == BlobType.class) {
return ObjectConverterUtil.convertToByteArray(((Blob) value).getBinaryStream());
}
if (value instanceof Serializable) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(value);
oos.close();
bos.close();
return bos.toByteArray();
}
}
Class<?> targetType = DataTypeManager.getDataTypeClass(ODataTypeManager.teiidType(expectedType, isArray));
if (sourceType != targetType) {
Transform t = DataTypeManager.getTransform(sourceType, targetType);
value = t != null ? t.transform(value, targetType) : value;
}
return value;
}
Aggregations