use of org.teiid.api.exception.query.FunctionExecutionException in project teiid by teiid.
the class ODataTypeManager method convertToODataURIValue.
public static String convertToODataURIValue(Object val, String odataType) throws EdmPrimitiveTypeException {
if (val == null) {
// is this correct? //$NON-NLS-1$
return "null";
}
if (odataType.startsWith("Edm.")) {
// $NON-NLS-1$
odataType = odataType.substring(4);
}
if (val instanceof GeometryType) {
Geometry g;
try {
g = GeometryUtils.getGeometry((GeometryType) val);
} catch (FunctionExecutionException e1) {
throw new EdmPrimitiveTypeException(e1.getMessage(), e1);
}
StringWriter sw = new StringWriter();
// $NON-NLS-1$
sw.write("geometry'SRID=");
sw.write(String.valueOf(g.getSRID()));
// $NON-NLS-1$
sw.write(";");
ODataWKTWriter writer = new ODataWKTWriter();
try {
writer.write(g, sw);
} catch (IOException e) {
throw new TeiidRuntimeException(e);
}
// $NON-NLS-1$
sw.write("'");
return sw.toString();
}
EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(odataType);
String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString(val, true, null, null, Integer.MAX_VALUE, true);
if (kind == EdmPrimitiveTypeKind.String) {
return EdmString.getInstance().toUriLiteral(value);
}
return value;
}
Aggregations