Search in sources :

Example 1 with TeiidConnection

use of org.teiid.jdbc.TeiidConnection 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)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1 TeiidConnection (org.teiid.jdbc.TeiidConnection)1