Search in sources :

Example 31 with FunctionExecutionException

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;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) StringWriter(java.io.StringWriter) EdmPrimitiveTypeException(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) EdmPrimitiveTypeKind(org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind) EdmString(org.apache.olingo.commons.core.edm.primitivetype.EdmString)

Aggregations

FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)31 IOException (java.io.IOException)9 SQLException (java.sql.SQLException)9 ParseException (com.vividsolutions.jts.io.ParseException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 LanguageObject (org.teiid.query.sql.LanguageObject)4 ClobType (org.teiid.core.types.ClobType)3 TransformationException (org.teiid.core.types.TransformationException)3 WKBReader (com.vividsolutions.jts.io.WKBReader)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 StringReader (java.io.StringReader)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathException (net.sf.saxon.trans.XPathException)2 BlockedException (org.teiid.common.buffer.BlockedException)2