Mercurial > dive4elements > gnv-client
diff geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEStatement.java @ 884:12f88239fb33
Updated Javadocs to the Listed Classes.
Also done some Codecleanup and removed unused Methods from the Code.
geo-backend/trunk@842 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 15:23:03 +0000 |
parents | 9bcc423d8d76 |
children | 1c3efbd2fc5a |
line wrap: on
line diff
--- a/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEStatement.java Fri Mar 26 11:07:01 2010 +0000 +++ b/geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEStatement.java Fri Mar 26 15:23:03 2010 +0000 @@ -35,180 +35,194 @@ import de.intevation.gnv.geobackend.util.RedundancyRemover; /** + * This Class wrapps an SDE-Statment to an java.sql.Statement. + * This Class also handles the SDE-Specific -Spatial-Queries and + * RasterQueries. * @author Tim Englich (tim.englich@intevation.de) * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) */ public class ArcSDEStatement implements Statement { - /** + /** * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(ArcSDEStatement.class); - private ArcSDEConnection connection = null; - - /** - * Constructor - */ - public ArcSDEStatement(ArcSDEConnection connection) { - this.connection = connection; - } - - /** - * @see java.sql.Statement#addBatch(java.lang.String) - */ - public void addBatch(String arg0) throws SQLException { - } - - /** - * @see java.sql.Statement#cancel() - */ - public void cancel() throws SQLException { - } - - /** - * @see java.sql.Statement#clearBatch() - */ - public void clearBatch() throws SQLException { - } - - /** - * @see java.sql.Statement#clearWarnings() - */ - public void clearWarnings() throws SQLException { - } - - /** - * @see java.sql.Statement#close() - */ - public void close() throws SQLException { - } - - /** - * @see java.sql.Statement#execute(java.lang.String) - */ - public boolean execute(String arg0) throws SQLException { - - return false; - } - - /** - * @see java.sql.Statement#execute(java.lang.String, int) - */ - public boolean execute(String arg0, int arg1) throws SQLException { - - return false; - } - - /** - * @see java.sql.Statement#execute(java.lang.String, int[]) - */ - public boolean execute(String arg0, int[] arg1) throws SQLException { - - return false; - } - - /** - * @see java.sql.Statement#execute(java.lang.String, java.lang.String[]) - */ - public boolean execute(String arg0, String[] arg1) throws SQLException { - - return false; - } - - /** - * @see java.sql.Statement#executeBatch() - */ - public int[] executeBatch() throws SQLException { - - return null; - } + /** + * The Connection to the ArcSDE-Backend + */ + private ArcSDEConnection connection = null; + + /** + * Constructor + * @param connection the Connection to the ArcSDE-Backend. + */ + public ArcSDEStatement(ArcSDEConnection connection) { + this.connection = connection; + } - /** - * @see java.sql.Statement#executeQuery(java.lang.String) - */ - public ResultSet executeQuery(String statement) throws SQLException { - try { - SeQuery query = null; - if (statement.toLowerCase().contains("st_astext") || statement.toLowerCase().contains("intersects")){ - - String[] values = statement.toLowerCase().split("where", 2); - String where = values.length > 1 ? values[1].trim() : ""; - String[] tableNames = values[0].substring(values[0].indexOf("from")).replaceFirst("from", "").toUpperCase().trim().split(", "); - String columnValueString = values[0].substring(0, values[0].indexOf("from")).trim(); - columnValueString = columnValueString.replaceFirst("select", "").trim(); - String[] returnFields = columnValueString.split(", "); - String geometryColumnName = null; - String byClause = null; - int byClausePos = where.indexOf("group by"); - if (byClausePos < 0){ - byClausePos = where.indexOf("order by"); - } - if (byClausePos > 0){ - byClause = where.substring(byClausePos); - where = where.substring(0,byClausePos); - } - - for (int i = 0; i < returnFields.length; i++){ - returnFields[i] = returnFields[i].trim(); - if (returnFields[i].startsWith("st_astext(")){ - returnFields[i] = returnFields[i].replaceAll("st_astext", ""); - returnFields[i] = returnFields[i].substring(1, returnFields[i].length()-1); - geometryColumnName = returnFields[i]; - } - } - - for (int i = 0; i < tableNames.length; i++){ - tableNames[i] = tableNames[i].trim(); - } - - Geometry g = null; - int pos = where.indexOf("intersects"); - if (pos >= 0 ){ - String substr = where.substring(pos); - where = where.substring(0,where.lastIndexOf("intersects")); - int andPos = where.lastIndexOf("and"); - if (andPos < 0){ - andPos = 0; - } - where = where.substring(0,andPos); // TODO support or also - String intersectsStmt = substr.substring(0, substr.lastIndexOf(")")); // Spatial-Statment is the last one - String wkt = null; - if (intersectsStmt.contains("select")){ - // Anstelle eines WKT ist ein InnerSelect zum Bestimmen der Comparatorgeometrie gegeben. - String stmt = intersectsStmt.substring(intersectsStmt.indexOf("select"),intersectsStmt.lastIndexOf(")")); - ResultSet resultSet = this.executeQuery(stmt); - if (resultSet != null && resultSet.next()){ - // TODO: Support the selection of more than one Geometry - wkt = resultSet.getString("SHAPE"); - } - }else{ - wkt = intersectsStmt.substring(intersectsStmt.indexOf("\""), intersectsStmt.lastIndexOf("\"")).replace("\"", "").trim(); - } - g = new WKTReader().read(wkt.toUpperCase()); - - if (geometryColumnName == null){ - geometryColumnName = "SHAPE"; // TODO dynamisch aus Intersects auslesen. - } - - } - - return this.executeQuery(this.connection.getSeConnection(), tableNames, geometryColumnName, where, g, returnFields,byClause); - }else{ - query = new SeQuery(this.connection.getSeConnection()); - query.prepareSql(statement); - query.execute(); - return this.handleResultSet(query,false,null); - } - - } catch (Exception e) { - log.error(e,e); - throw new SQLException(e.getMessage()); + /** + * @see java.sql.Statement#addBatch(java.lang.String) + */ + public void addBatch(String arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#cancel() + */ + public void cancel() throws SQLException { + } + + /** + * @see java.sql.Statement#clearBatch() + */ + public void clearBatch() throws SQLException { + } + + /** + * @see java.sql.Statement#clearWarnings() + */ + public void clearWarnings() throws SQLException { + } + + /** + * @see java.sql.Statement#close() + */ + public void close() throws SQLException { + } + + /** + * @see java.sql.Statement#execute(java.lang.String) + */ + public boolean execute(String arg0) throws SQLException { + return false; + } + + /** + * @see java.sql.Statement#execute(java.lang.String, int) + */ + public boolean execute(String arg0, int arg1) throws SQLException { + return false; + } + + /** + * @see java.sql.Statement#execute(java.lang.String, int[]) + */ + public boolean execute(String arg0, int[] arg1) throws SQLException { + return false; + } + + /** + * @see java.sql.Statement#execute(java.lang.String, java.lang.String[]) + */ + public boolean execute(String arg0, String[] arg1) throws SQLException { + return false; + } + + /** + * @see java.sql.Statement#executeBatch() + */ + public int[] executeBatch() throws SQLException { + return null; + } + + /** + * @see java.sql.Statement#executeQuery(java.lang.String) + */ + public ResultSet executeQuery(String statement) throws SQLException { + try { + SeQuery query = null; + if (statement.toLowerCase().contains("st_astext") || statement.toLowerCase().contains("intersects")){ + + String[] values = statement.toLowerCase().split("where", 2); + String where = values.length > 1 ? values[1].trim() : ""; + String[] tableNames = values[0].substring(values[0].indexOf("from")).replaceFirst("from", "").toUpperCase().trim().split(", "); + String columnValueString = values[0].substring(0, values[0].indexOf("from")).trim(); + columnValueString = columnValueString.replaceFirst("select", "").trim(); + String[] returnFields = columnValueString.split(", "); + String geometryColumnName = null; + String byClause = null; + int byClausePos = where.indexOf("group by"); + if (byClausePos < 0){ + byClausePos = where.indexOf("order by"); + } + if (byClausePos > 0){ + byClause = where.substring(byClausePos); + where = where.substring(0,byClausePos); + } + + for (int i = 0; i < returnFields.length; i++){ + returnFields[i] = returnFields[i].trim(); + if (returnFields[i].startsWith("st_astext(")){ + returnFields[i] = returnFields[i].replaceAll("st_astext", ""); + returnFields[i] = returnFields[i].substring(1, returnFields[i].length()-1); + geometryColumnName = returnFields[i]; + } + } + + for (int i = 0; i < tableNames.length; i++){ + tableNames[i] = tableNames[i].trim(); + } + + Geometry g = null; + int pos = where.indexOf("intersects"); + if (pos >= 0 ){ + String substr = where.substring(pos); + where = where.substring(0,where.lastIndexOf("intersects")); + int andPos = where.lastIndexOf("and"); + if (andPos < 0){ + andPos = 0; + } + where = where.substring(0,andPos); // TODO support or also + String intersectsStmt = substr.substring(0, substr.lastIndexOf(")")); // Spatial-Statment is the last one + String wkt = null; + if (intersectsStmt.contains("select")){ + // Anstelle eines WKT ist ein InnerSelect zum Bestimmen der Comparatorgeometrie gegeben. + String stmt = intersectsStmt.substring(intersectsStmt.indexOf("select"),intersectsStmt.lastIndexOf(")")); + ResultSet resultSet = this.executeQuery(stmt); + if (resultSet != null && resultSet.next()){ + // TODO: Support the selection of more than one Geometry + wkt = resultSet.getString("SHAPE"); + } + }else{ + wkt = intersectsStmt.substring(intersectsStmt.indexOf("\""), intersectsStmt.lastIndexOf("\"")).replace("\"", "").trim(); + } + g = new WKTReader().read(wkt.toUpperCase()); + + if (geometryColumnName == null){ + geometryColumnName = "SHAPE"; // TODO dynamisch aus Intersects auslesen. + } + + } + + return this.executeQuery(this.connection.getSeConnection(), tableNames, geometryColumnName, where, g, returnFields,byClause); + }else{ + query = new SeQuery(this.connection.getSeConnection()); + query.prepareSql(statement); + query.execute(); + return this.handleResultSet(query,false,null); + } + + } catch (Exception e) { + log.error(e,e); + throw new SQLException(e.getMessage()); } - } - + } + /** + * This Methods Executes the ArcSDE Query if Spatial-Restrictions + * are given + * @param con The Connection to the ArcSDE-Backend. + * @param pLayername The Name of tables which should be used in the Query + * @param pSpatialColumnName the Name of the Spatial Column. + * @param pWhere The where-Clause to limit the Data + * @param g the Geometry to limit the Data + * @param pReturnFields the Fileds that should be fetched from the Database + * @param byClause the byClaus to order the Results. + * @return the @see java.sql.ResultSet with the Data which was retrieved. + * @throws SQLException + */ private ResultSet executeQuery(SeConnection con, String[] pLayername, String pSpatialColumnName, String pWhere, Geometry g, String[] pReturnFields, String byClause) @@ -284,207 +298,194 @@ } } - /** - * @see java.sql.Statement#executeUpdate(java.lang.String) - */ - public int executeUpdate(String arg0) throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#executeUpdate(java.lang.String, int) - */ - public int executeUpdate(String arg0, int arg1) throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#executeUpdate(java.lang.String, int[]) - */ - public int executeUpdate(String arg0, int[] arg1) throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[]) - */ - public int executeUpdate(String arg0, String[] arg1) throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getConnection() - */ - public Connection getConnection() throws SQLException { - return this.connection; - } - - /** - * @see java.sql.Statement#getFetchDirection() - */ - public int getFetchDirection() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getFetchSize() - */ - public int getFetchSize() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getGeneratedKeys() - */ - public ResultSet getGeneratedKeys() throws SQLException { - - return null; - } - - /** - * @see java.sql.Statement#getMaxFieldSize() - */ - public int getMaxFieldSize() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getMaxRows() - */ - public int getMaxRows() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getMoreResults() - */ - public boolean getMoreResults() throws SQLException { - - return false; - } - - /** - * @see java.sql.Statement#getMoreResults(int) - */ - public boolean getMoreResults(int arg0) throws SQLException { - - return false; - } - - /** - * @see java.sql.Statement#getQueryTimeout() - */ - public int getQueryTimeout() throws SQLException { + /** + * @see java.sql.Statement#executeUpdate(java.lang.String) + */ + public int executeUpdate(String arg0) throws SQLException { + return 0; + } - return 0; - } - - /** - * @see java.sql.Statement#getResultSet() - */ - public ResultSet getResultSet() throws SQLException { - - return null; - } - - /** - * @see java.sql.Statement#getResultSetConcurrency() - */ - public int getResultSetConcurrency() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getResultSetHoldability() - */ - public int getResultSetHoldability() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getResultSetType() - */ - public int getResultSetType() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getUpdateCount() - */ - public int getUpdateCount() throws SQLException { - - return 0; - } - - /** - * @see java.sql.Statement#getWarnings() - */ - public SQLWarning getWarnings() throws SQLException { + /** + * @see java.sql.Statement#executeUpdate(java.lang.String, int) + */ + public int executeUpdate(String arg0, int arg1) throws SQLException { + return 0; + } - return null; - } - - /** - * @see java.sql.Statement#setCursorName(java.lang.String) - */ - public void setCursorName(String arg0) throws SQLException { - } - - /** - * @see java.sql.Statement#setEscapeProcessing(boolean) - */ - public void setEscapeProcessing(boolean arg0) throws SQLException { - } - - /** - * @see java.sql.Statement#setFetchDirection(int) - */ - public void setFetchDirection(int arg0) throws SQLException { - } + /** + * @see java.sql.Statement#executeUpdate(java.lang.String, int[]) + */ + public int executeUpdate(String arg0, int[] arg1) throws SQLException { + return 0; + } - /** - * @see java.sql.Statement#setFetchSize(int) - */ - public void setFetchSize(int arg0) throws SQLException { - } - - /** - * @see java.sql.Statement#setMaxFieldSize(int) - */ - public void setMaxFieldSize(int arg0) throws SQLException { - } + /** + * @see java.sql.Statement#executeUpdate(java.lang.String, java.lang.String[]) + */ + public int executeUpdate(String arg0, String[] arg1) throws SQLException { + return 0; + } - /** - * @see java.sql.Statement#setMaxRows(int) - */ - public void setMaxRows(int arg0) throws SQLException { - } + /** + * @see java.sql.Statement#getConnection() + */ + public Connection getConnection() throws SQLException { + return this.connection; + } - /** - * @see java.sql.Statement#setQueryTimeout(int) - */ - public void setQueryTimeout(int arg0) throws SQLException { - } - - /** - * Copied from de.intevation.gnv.geobackend.sde.datasources.SDEQuery - * @param pSeQuery - * @return - * @throws SeException - */ - private ResultSet handleResultSet(SeQuery pSeQuery, boolean isRaster, Geometry geometry) throws SeException { + /** + * @see java.sql.Statement#getFetchDirection() + */ + public int getFetchDirection() throws SQLException { + return 0; + } + /** + * @see java.sql.Statement#getFetchSize() + */ + public int getFetchSize() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getGeneratedKeys() + */ + public ResultSet getGeneratedKeys() throws SQLException { + return null; + } + + /** + * @see java.sql.Statement#getMaxFieldSize() + */ + public int getMaxFieldSize() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getMaxRows() + */ + public int getMaxRows() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getMoreResults() + */ + public boolean getMoreResults() throws SQLException { + return false; + } + + /** + * @see java.sql.Statement#getMoreResults(int) + */ + public boolean getMoreResults(int arg0) throws SQLException { + return false; + } + + /** + * @see java.sql.Statement#getQueryTimeout() + */ + public int getQueryTimeout() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getResultSet() + */ + public ResultSet getResultSet() throws SQLException { + return null; + } + + /** + * @see java.sql.Statement#getResultSetConcurrency() + */ + public int getResultSetConcurrency() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getResultSetHoldability() + */ + public int getResultSetHoldability() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getResultSetType() + */ + public int getResultSetType() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getUpdateCount() + */ + public int getUpdateCount() throws SQLException { + return 0; + } + + /** + * @see java.sql.Statement#getWarnings() + */ + public SQLWarning getWarnings() throws SQLException { + return null; + } + + /** + * @see java.sql.Statement#setCursorName(java.lang.String) + */ + public void setCursorName(String arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setEscapeProcessing(boolean) + */ + public void setEscapeProcessing(boolean arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setFetchDirection(int) + */ + public void setFetchDirection(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setFetchSize(int) + */ + public void setFetchSize(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setMaxFieldSize(int) + */ + public void setMaxFieldSize(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setMaxRows(int) + */ + public void setMaxRows(int arg0) throws SQLException { + } + + /** + * @see java.sql.Statement#setQueryTimeout(int) + */ + public void setQueryTimeout(int arg0) throws SQLException { + } + + /** + * This Method fetches all Rows from the SeQuery-Object and convert it into + * an @see java.sql.ResultSet. + * + * @param pSeQuery the Queryobject where the Data should be fetched from. + * @param isRaster Flag which indicates if the Result is Rasterdata. + * @param geometry The Geometry which might be used to limit the data. + * @return an java.sql:ResultSet which contains the Data. + * @throws SeException + */ + private ResultSet handleResultSet(SeQuery pSeQuery, + boolean isRaster, + Geometry geometry) throws SeException { boolean debug = log.isDebugEnabled(); if (debug) { @@ -546,15 +547,6 @@ SeExtent extent = rasterBand.getExtent(); - /* - if (debug) { - log.debug("Extent: " + - extent.getMinX() + " " + extent.getMinY() + " "+ - extent.getMaxX() + " " + extent.getMaxY()); - log.debug("Query geometry: "+geometry.toText()); - } - */ - double x = ((Point)geometry).getX(); double y = ((Point)geometry).getY(); @@ -582,13 +574,6 @@ ? extent.getMaxY() : extent.getMinY(); - /* - 0 = origin.getX()*mx + bx - rasterBand.getBandWidth() = maxX + bx - - rasterBand.getBandWidth() = (maxX-origin.getX())*mx - */ - double mx = rasterBand.getBandWidth()/(maxX-origin.getX()); double bx = -origin.getX()*mx; double px = mx*x + bx; @@ -597,12 +582,6 @@ double by = -origin.getY()*my; double py = my*y + by; - /* - if (debug) { - log.debug("p(x, y): " + px + " / " + py); - } - */ - SeRasterConstraint constraint = new SeRasterConstraint(); constraint.setLevel(0); // best resolution constraint.setBands(rasterBand.getBandNumber()); @@ -619,12 +598,6 @@ lSet.addCol(new ColDefinition("tile", ColDefinition.FLOAT64)); Row lBackingRow = new Row(1); - /* - 0 = wx1*mt + bt - tileWidth-EPS = wx2*mt + bt - tileWidth-EPS = mt*(wx2 - wx1) - */ - double wx1 = (rasterBand.getTileWidth()*tx - bx)/mx; double wx2 = (rasterBand.getTileWidth()*(tx+1) - bx)/mx; double mxt = (rasterBand.getTileWidth()-1e-5d)/(wx2 - wx1); @@ -646,28 +619,6 @@ lBackingRow.addObject(ro, 0); lSet.addRow(lBackingRow); - /* - if (debug) { - log.debug("x / y: " + x + " / " + y); - log.debug("wx1: " + wx1); - log.debug("wx1 -> " + (wx1*mxt+bxt)); - log.debug("wx2: " + wx2); - log.debug("wx2 -> " + (wx2*mxt+bxt)); - log.debug("wx2 - wx1: " + Math.abs(wx2-wx1)); - log.debug("wy2 - wy1: " + Math.abs(wy2-wy1)); - log.debug("pix: " + (x*mxt + bxt)+ " " + (y*myt + byt)); - log.debug("requesting tile: " + tx + " / " + ty); - log.debug("got tile: " + tile.getColumnIndex() + " / " + tile.getRowIndex()); - log.debug("tile orig: " + origin.getX() + " / " + origin.getY()); - log.debug("tile width: " + rasterBand.getTileWidth()); - log.debug("tile height: " + rasterBand.getTileHeight()); - log.debug("Rasterdimesion (Pixel) " + - rasterBand.getBandWidth() + " / " + rasterBand.getBandHeight()); - log.debug("BAND-ID "+rasterBand.getId().longValue()); - log.debug("Pixels: "+ tile.getNumPixels()); - log.debug("Column / Row "+tile.getColumnIndex()+" / "+tile.getRowIndex()); - } - */ } } else{ @@ -682,21 +633,36 @@ return lSet; } + /** + * @see java.sql.Statement#isClosed() + */ public boolean isClosed() throws SQLException { return false; } + /** + * @see java.sql.Statement#isPoolable() + */ public boolean isPoolable() throws SQLException { return false; } + /** + * @see java.sql.Statement#setPoolable(boolean) + */ public void setPoolable(boolean arg0) throws SQLException { } + /** + * @see java.sql.Wrapper#isWrapperFor(java.lang.Class) + */ public boolean isWrapperFor(Class<?> iface) throws SQLException { return false; } + /** + * @see java.sql.Wrapper#unwrap(java.lang.Class) + */ public <T> T unwrap(Class<T> iface) throws SQLException { return null;