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();
}
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;
}
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) {
}
}
}
}
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);
}
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);
}
}
Aggregations