Search in sources :

Example 6 with FunctionExecutionException

use of org.teiid.api.exception.query.FunctionExecutionException in project teiid by teiid.

the class FunctionMethods method insert.

// ================== Function = insert =====================
public static Object insert(String string1, Integer start, Integer length, String str2) throws FunctionExecutionException {
    int startValue = start.intValue();
    int len = length.intValue();
    // Check some invalid cases
    if (startValue < 1 || (startValue - 1) > string1.length()) {
        throw new FunctionExecutionException(QueryPlugin.Event.TEIID30399, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30399, start, string1));
    } else if (len < 0) {
        throw new FunctionExecutionException(QueryPlugin.Event.TEIID30400, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30400, len));
    } else if (string1.length() == 0 && (startValue > 1 || len > 0)) {
        throw new FunctionExecutionException(QueryPlugin.Event.TEIID30401, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30401));
    }
    StringBuffer result = new StringBuffer();
    result.append(string1.substring(0, startValue - 1));
    int endValue = startValue + len - 1;
    // str2.length() = 0 is a valid case
    if (endValue > string1.length()) {
        result.append(str2);
    } else {
        result.append(str2);
        result.append(string1.substring(endValue));
    }
    return result.toString();
}
Also used : FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException)

Example 7 with FunctionExecutionException

use of org.teiid.api.exception.query.FunctionExecutionException in project teiid by teiid.

the class GeometryTransformUtils method lookupProj4Text.

/**
 * Lookup proj4 parameters in SPATIAL_REF_SYS using SRID as key.
 *
 * @param ctx
 * @param srid
 * @return
 * @throws FunctionExecutionException
 */
public static String lookupProj4Text(CommandContext ctx, int srid) throws FunctionExecutionException {
    String projText;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        TeiidConnection conn = ctx.getConnection();
        // $NON-NLS-1$
        pstmt = conn.prepareStatement("select proj4text from SYS.spatial_ref_sys where srid = ?");
        pstmt.setInt(1, srid);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31162, srid));
        }
        projText = rs.getString(1);
    } catch (SQLException e) {
        throw new FunctionExecutionException(e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31163));
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception e) {
        // ignore
        }
        try {
            if (pstmt != null) {
                pstmt.close();
            }
        } catch (Exception e) {
        // ignore
        }
    }
    return projText;
}
Also used : FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) SQLException(java.sql.SQLException) TeiidConnection(org.teiid.jdbc.TeiidConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException)

Example 8 with FunctionExecutionException

use of org.teiid.api.exception.query.FunctionExecutionException in project teiid by teiid.

the class GeometryUtils method getGeometry.

public static Geometry getGeometry(InputStream is1, Integer srid, boolean allowEwkb) throws FunctionExecutionException {
    try {
        WKBReader reader = new WKBReader();
        Geometry jtsGeom = reader.read(new InputStreamInStream(is1));
        if (!allowEwkb && (jtsGeom.getSRID() != GeometryType.UNKNOWN_SRID || (jtsGeom.getCoordinate() != null && !Double.isNaN(jtsGeom.getCoordinate().z)))) {
            // $NON-NLS-1$
            throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31160, "EWKB"));
        }
        if (srid != null) {
            jtsGeom.setSRID(srid);
        }
        return jtsGeom;
    } catch (ParseException e) {
        throw new FunctionExecutionException(e);
    } catch (IOException e) {
        throw new FunctionExecutionException(e);
    } finally {
        if (is1 != null) {
            try {
                is1.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : InputStreamInStream(com.vividsolutions.jts.io.InputStreamInStream) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) ParseException(com.vividsolutions.jts.io.ParseException) IOException(java.io.IOException) WKBReader(com.vividsolutions.jts.io.WKBReader)

Example 9 with FunctionExecutionException

use of org.teiid.api.exception.query.FunctionExecutionException in project teiid by teiid.

the class GeometryUtils method geometryFromGml.

public static GeometryType geometryFromGml(Reader reader, Integer srid) throws FunctionExecutionException {
    Geometry jtsGeometry = null;
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(false);
        factory.setValidating(false);
        SAXParser parser = factory.newSAXParser();
        GmlSridHandler handler = new GmlSridHandler(GEOMETRY_FACTORY, null);
        parser.parse(new InputSource(reader), handler);
        jtsGeometry = handler.getGeometry();
        if (srid == null) {
            if (jtsGeometry.getSRID() == GeometryType.UNKNOWN_SRID) {
                srid = handler.getSrid();
            } else {
                srid = jtsGeometry.getSRID();
            }
        }
    } catch (IOException e) {
        throw new FunctionExecutionException(e);
    } catch (SAXException e) {
        throw new FunctionExecutionException(e);
    } catch (ParserConfigurationException e) {
        throw new FunctionExecutionException(e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
            // Nothing
            }
        }
    }
    return getGeometryType(jtsGeometry, srid);
}
Also used : InputSource(org.xml.sax.InputSource) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SQLException(java.sql.SQLException) ParseException(com.vividsolutions.jts.io.ParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 10 with FunctionExecutionException

use of org.teiid.api.exception.query.FunctionExecutionException in project teiid by teiid.

the class GeometryUtils method geometryFromGeoJson.

public static GeometryType geometryFromGeoJson(ClobType json, int srid) throws FunctionExecutionException {
    try {
        GeoJSONReader reader = new GeoJSONReader();
        String jsonText = ClobType.getString(json);
        Geometry jtsGeometry = reader.read(jsonText);
        return getGeometryType(jtsGeometry, srid);
    } catch (SQLException e) {
        throw new FunctionExecutionException(e);
    } catch (IOException e) {
        throw new FunctionExecutionException(e);
    }
}
Also used : GeoJSONReader(org.wololo.jts2geojson.GeoJSONReader) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

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