comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/ArcSDEStatement.java @ 885:1c3efbd2fc5a

Removes trailing whitespace. geo-backend/trunk@850 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 29 Mar 2010 07:49:16 +0000
parents 12f88239fb33
children 8b442223741c
comparison
equal deleted inserted replaced
884:12f88239fb33 885:1c3efbd2fc5a
45 45
46 /** 46 /**
47 * the logger, used to log exceptions and additonaly information 47 * the logger, used to log exceptions and additonaly information
48 */ 48 */
49 private static Logger log = Logger.getLogger(ArcSDEStatement.class); 49 private static Logger log = Logger.getLogger(ArcSDEStatement.class);
50 50
51 /** 51 /**
52 * The Connection to the ArcSDE-Backend 52 * The Connection to the ArcSDE-Backend
53 */ 53 */
54 private ArcSDEConnection connection = null; 54 private ArcSDEConnection connection = null;
55 55
56 /** 56 /**
57 * Constructor 57 * Constructor
58 * @param connection the Connection to the ArcSDE-Backend. 58 * @param connection the Connection to the ArcSDE-Backend.
59 */ 59 */
60 public ArcSDEStatement(ArcSDEConnection connection) { 60 public ArcSDEStatement(ArcSDEConnection connection) {
131 */ 131 */
132 public ResultSet executeQuery(String statement) throws SQLException { 132 public ResultSet executeQuery(String statement) throws SQLException {
133 try { 133 try {
134 SeQuery query = null; 134 SeQuery query = null;
135 if (statement.toLowerCase().contains("st_astext") || statement.toLowerCase().contains("intersects")){ 135 if (statement.toLowerCase().contains("st_astext") || statement.toLowerCase().contains("intersects")){
136 136
137 String[] values = statement.toLowerCase().split("where", 2); 137 String[] values = statement.toLowerCase().split("where", 2);
138 String where = values.length > 1 ? values[1].trim() : ""; 138 String where = values.length > 1 ? values[1].trim() : "";
139 String[] tableNames = values[0].substring(values[0].indexOf("from")).replaceFirst("from", "").toUpperCase().trim().split(", "); 139 String[] tableNames = values[0].substring(values[0].indexOf("from")).replaceFirst("from", "").toUpperCase().trim().split(", ");
140 String columnValueString = values[0].substring(0, values[0].indexOf("from")).trim(); 140 String columnValueString = values[0].substring(0, values[0].indexOf("from")).trim();
141 columnValueString = columnValueString.replaceFirst("select", "").trim(); 141 columnValueString = columnValueString.replaceFirst("select", "").trim();
148 } 148 }
149 if (byClausePos > 0){ 149 if (byClausePos > 0){
150 byClause = where.substring(byClausePos); 150 byClause = where.substring(byClausePos);
151 where = where.substring(0,byClausePos); 151 where = where.substring(0,byClausePos);
152 } 152 }
153 153
154 for (int i = 0; i < returnFields.length; i++){ 154 for (int i = 0; i < returnFields.length; i++){
155 returnFields[i] = returnFields[i].trim(); 155 returnFields[i] = returnFields[i].trim();
156 if (returnFields[i].startsWith("st_astext(")){ 156 if (returnFields[i].startsWith("st_astext(")){
157 returnFields[i] = returnFields[i].replaceAll("st_astext", ""); 157 returnFields[i] = returnFields[i].replaceAll("st_astext", "");
158 returnFields[i] = returnFields[i].substring(1, returnFields[i].length()-1); 158 returnFields[i] = returnFields[i].substring(1, returnFields[i].length()-1);
159 geometryColumnName = returnFields[i]; 159 geometryColumnName = returnFields[i];
160 } 160 }
161 } 161 }
162 162
163 for (int i = 0; i < tableNames.length; i++){ 163 for (int i = 0; i < tableNames.length; i++){
164 tableNames[i] = tableNames[i].trim(); 164 tableNames[i] = tableNames[i].trim();
165 } 165 }
166 166
167 Geometry g = null; 167 Geometry g = null;
168 int pos = where.indexOf("intersects"); 168 int pos = where.indexOf("intersects");
169 if (pos >= 0 ){ 169 if (pos >= 0 ){
170 String substr = where.substring(pos); 170 String substr = where.substring(pos);
171 where = where.substring(0,where.lastIndexOf("intersects")); 171 where = where.substring(0,where.lastIndexOf("intersects"));
186 } 186 }
187 }else{ 187 }else{
188 wkt = intersectsStmt.substring(intersectsStmt.indexOf("\""), intersectsStmt.lastIndexOf("\"")).replace("\"", "").trim(); 188 wkt = intersectsStmt.substring(intersectsStmt.indexOf("\""), intersectsStmt.lastIndexOf("\"")).replace("\"", "").trim();
189 } 189 }
190 g = new WKTReader().read(wkt.toUpperCase()); 190 g = new WKTReader().read(wkt.toUpperCase());
191 191
192 if (geometryColumnName == null){ 192 if (geometryColumnName == null){
193 geometryColumnName = "SHAPE"; // TODO dynamisch aus Intersects auslesen. 193 geometryColumnName = "SHAPE"; // TODO dynamisch aus Intersects auslesen.
194 } 194 }
195 195
196 } 196 }
197 197
198 return this.executeQuery(this.connection.getSeConnection(), tableNames, geometryColumnName, where, g, returnFields,byClause); 198 return this.executeQuery(this.connection.getSeConnection(), tableNames, geometryColumnName, where, g, returnFields,byClause);
199 }else{ 199 }else{
200 query = new SeQuery(this.connection.getSeConnection()); 200 query = new SeQuery(this.connection.getSeConnection());
201 query.prepareSql(statement); 201 query.prepareSql(statement);
202 query.execute(); 202 query.execute();
203 return this.handleResultSet(query,false,null); 203 return this.handleResultSet(query,false,null);
204 } 204 }
205 205
206 } catch (Exception e) { 206 } catch (Exception e) {
207 log.error(e,e); 207 log.error(e,e);
208 throw new SQLException(e.getMessage()); 208 throw new SQLException(e.getMessage());
209 } 209 }
210 210
211 211
212 } 212 }
213 /** 213 /**
214 * This Methods Executes the ArcSDE Query if Spatial-Restrictions 214 * This Methods Executes the ArcSDE Query if Spatial-Restrictions
215 * are given 215 * are given
216 * @param con The Connection to the ArcSDE-Backend. 216 * @param con The Connection to the ArcSDE-Backend.
217 * @param pLayername The Name of tables which should be used in the Query 217 * @param pLayername The Name of tables which should be used in the Query
218 * @param pSpatialColumnName the Name of the Spatial Column. 218 * @param pSpatialColumnName the Name of the Spatial Column.
219 * @param pWhere The where-Clause to limit the Data 219 * @param pWhere The where-Clause to limit the Data
220 * @param g the Geometry to limit the Data 220 * @param g the Geometry to limit the Data
221 * @param pReturnFields the Fileds that should be fetched from the Database 221 * @param pReturnFields the Fileds that should be fetched from the Database
222 * @param byClause the byClaus to order the Results. 222 * @param byClause the byClaus to order the Results.
229 throws SQLException { 229 throws SQLException {
230 log.debug("executeQuery()"); 230 log.debug("executeQuery()");
231 try { 231 try {
232 // get the layer for querying 232 // get the layer for querying
233 boolean isRaster = pSpatialColumnName.equalsIgnoreCase("raster"); 233 boolean isRaster = pSpatialColumnName.equalsIgnoreCase("raster");
234 234
235 SeShapeFilter[] filters = null; 235 SeShapeFilter[] filters = null;
236 if (g != null){ 236 if (g != null){
237 if (!isRaster){ 237 if (!isRaster){
238 SeLayer lLayer = new SeLayer(con, pLayername[0], pSpatialColumnName); 238 SeLayer lLayer = new SeLayer(con, pLayername[0], pSpatialColumnName);
239 SeShape shape = new SeShape(); 239 SeShape shape = new SeShape();
240 shape.setCoordRef(lLayer.getCoordRef()); 240 shape.setCoordRef(lLayer.getCoordRef());
241 241
242 SDEPoint[] lPoints = new ArcSDEUtils().createPoints(g); 242 SDEPoint[] lPoints = new ArcSDEUtils().createPoints(g);
243 243
244 int searchMode = SeFilter.METHOD_AI; 244 int searchMode = SeFilter.METHOD_AI;
245 if (g instanceof Polygon){ 245 if (g instanceof Polygon){
246 shape.generatePolygon(lPoints.length, 1, null, lPoints); 246 shape.generatePolygon(lPoints.length, 1, null, lPoints);
247 }else if (g instanceof Point){ 247 }else if (g instanceof Point){
248 shape.generatePoint(1, lPoints); 248 shape.generatePoint(1, lPoints);
249 searchMode = SeFilter.METHOD_PC; 249 searchMode = SeFilter.METHOD_PC;
250 }else if (g instanceof LineString){ 250 }else if (g instanceof LineString){
251 shape.generateLine(lPoints.length, 1, null, lPoints); 251 shape.generateLine(lPoints.length, 1, null, lPoints);
252 searchMode = SeFilter.METHOD_LCROSS; 252 searchMode = SeFilter.METHOD_LCROSS;
253 } 253 }
254 254
255 SeShapeFilter filter = new SeShapeFilter(pLayername[0], 255 SeShapeFilter filter = new SeShapeFilter(pLayername[0],
256 pSpatialColumnName, shape,searchMode); 256 pSpatialColumnName, shape,searchMode);
257 filters = new SeShapeFilter[1]; 257 filters = new SeShapeFilter[1];
258 filters[0] = filter; 258 filters[0] = filter;
259 } 259 }
260 } 260 }
261 261
262 SeQuery spatialQuery = null; 262 SeQuery spatialQuery = null;
263 SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername, pWhere); 263 SeSqlConstruct sqlCons = new SeSqlConstruct(pLayername, pWhere);
264 spatialQuery = new SeQuery(con);//, pReturnFields, sqlCons); 264 spatialQuery = new SeQuery(con);//, pReturnFields, sqlCons);
265 265
266 SeQueryInfo queryInfo = new SeQueryInfo(); 266 SeQueryInfo queryInfo = new SeQueryInfo();
267 queryInfo.setColumns(pReturnFields); 267 queryInfo.setColumns(pReturnFields);
268 268
269 if (byClause != null){ 269 if (byClause != null){
270 queryInfo.setByClause(byClause); 270 queryInfo.setByClause(byClause);
271 } 271 }
272 272
273 queryInfo.setConstruct(sqlCons); 273 queryInfo.setConstruct(sqlCons);
274 spatialQuery.prepareQueryInfo(queryInfo); 274 spatialQuery.prepareQueryInfo(queryInfo);
275 275
276 /* 276 /*
277 * Set spatial constraints 277 * Set spatial constraints
278 */ 278 */
279 if (filters != null){ 279 if (filters != null){
280 spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false, 280 spatialQuery.setSpatialConstraints(SeQuery.SE_OPTIMIZE, false,
281 filters); 281 filters);
282 } 282 }
283 283
284 if (!isRaster){ 284 if (!isRaster){
285 spatialQuery.execute(); 285 spatialQuery.execute();
286 } 286 }
287 287
288 return this.handleResultSet(spatialQuery,isRaster,g); 288 return this.handleResultSet(spatialQuery,isRaster,g);
289 289
290 } catch (Exception e) { 290 } catch (Exception e) {
291 if (e instanceof SeException){ 291 if (e instanceof SeException){
292 ArcSDEUtils.printError((SeException)e); 292 ArcSDEUtils.printError((SeException)e);
293 }else{ 293 }else{
294 log.error(e.getMessage(), e); 294 log.error(e.getMessage(), e);
295 } 295 }
296 296
297 throw new SQLException(e.getMessage()); 297 throw new SQLException(e.getMessage());
298 } 298 }
299 } 299 }
300 300
301 /** 301 /**
470 /** 470 /**
471 * @see java.sql.Statement#setQueryTimeout(int) 471 * @see java.sql.Statement#setQueryTimeout(int)
472 */ 472 */
473 public void setQueryTimeout(int arg0) throws SQLException { 473 public void setQueryTimeout(int arg0) throws SQLException {
474 } 474 }
475 475
476 /** 476 /**
477 * This Method fetches all Rows from the SeQuery-Object and convert it into 477 * This Method fetches all Rows from the SeQuery-Object and convert it into
478 * an @see java.sql.ResultSet. 478 * an @see java.sql.ResultSet.
479 * 479 *
480 * @param pSeQuery the Queryobject where the Data should be fetched from. 480 * @param pSeQuery the Queryobject where the Data should be fetched from.
481 * @param isRaster Flag which indicates if the Result is Rasterdata. 481 * @param isRaster Flag which indicates if the Result is Rasterdata.
482 * @param geometry The Geometry which might be used to limit the data. 482 * @param geometry The Geometry which might be used to limit the data.
483 * @return an java.sql:ResultSet which contains the Data. 483 * @return an java.sql:ResultSet which contains the Data.
484 * @throws SeException 484 * @throws SeException
485 */ 485 */
486 private ResultSet handleResultSet(SeQuery pSeQuery, 486 private ResultSet handleResultSet(SeQuery pSeQuery,
487 boolean isRaster, 487 boolean isRaster,
488 Geometry geometry) throws SeException { 488 Geometry geometry) throws SeException {
489 boolean debug = log.isDebugEnabled(); 489 boolean debug = log.isDebugEnabled();
490 490
491 if (debug) { 491 if (debug) {
492 log.debug("ArcSDEStatement.handleResultSet()"); 492 log.debug("ArcSDEStatement.handleResultSet()");
515 } 515 }
516 short lNumCols = row.getNumColumns(); 516 short lNumCols = row.getNumColumns();
517 Row lBackingRow = new Row(lNumCols); 517 Row lBackingRow = new Row(lNumCols);
518 for (int i = 0; i < lNumCols; i++) { 518 for (int i = 0; i < lNumCols; i++) {
519 lBackingRow.addObject( 519 lBackingRow.addObject(
520 removers[i].filter(row.getObject(i)), 520 removers[i].filter(row.getObject(i)),
521 i); 521 i);
522 } 522 }
523 lSet.addRow(lBackingRow); 523 lSet.addRow(lBackingRow);
524 } 524 }
525 525
542 row = pSeQuery.fetch(); 542 row = pSeQuery.fetch();
543 SeRasterAttr attr = row.getRaster(0); 543 SeRasterAttr attr = row.getRaster(0);
544 SeRaster raster = attr.getRasterInfo(); 544 SeRaster raster = attr.getRasterInfo();
545 SeRasterBand [] bands = raster.getBands(); 545 SeRasterBand [] bands = raster.getBands();
546 SeRasterBand rasterBand = bands[0]; 546 SeRasterBand rasterBand = bands[0];
547 547
548 SeExtent extent = rasterBand.getExtent(); 548 SeExtent extent = rasterBand.getExtent();
549 549
550 double x = ((Point)geometry).getX(); 550 double x = ((Point)geometry).getX();
551 double y = ((Point)geometry).getY(); 551 double y = ((Point)geometry).getY();
552 552
553 boolean isPointInRaster = 553 boolean isPointInRaster =
554 x >= extent.getMinX() && x <= extent.getMaxX() 554 x >= extent.getMinX() && x <= extent.getMaxX()
555 && y >= extent.getMinY() && y <= extent.getMaxY(); 555 && y >= extent.getMinY() && y <= extent.getMaxY();
556 556
557 if (isPointInRaster){ 557 if (isPointInRaster){
558 558
559 if (row == null){ 559 if (row == null){
560 pSeQuery.execute(); 560 pSeQuery.execute();
561 row = pSeQuery.fetch(); 561 row = pSeQuery.fetch();
562 } 562 }
563 563
564 double midX = 0.5d*(extent.getMinX() + extent.getMaxX()); 564 double midX = 0.5d*(extent.getMinX() + extent.getMaxX());
565 double midY = 0.5d*(extent.getMinY() + extent.getMaxY()); 565 double midY = 0.5d*(extent.getMinY() + extent.getMaxY());
566 566
567 SDEPoint origin = rasterBand.getTileOrigin(); 567 SDEPoint origin = rasterBand.getTileOrigin();
568 568
569 double maxX = origin.getX() < midX 569 double maxX = origin.getX() < midX
570 ? extent.getMaxX() 570 ? extent.getMaxX()
571 : extent.getMinX(); 571 : extent.getMinX();
572 572
573 double maxY = origin.getY() < midY 573 double maxY = origin.getY() < midY
574 ? extent.getMaxY() 574 ? extent.getMaxY()
663 /** 663 /**
664 * @see java.sql.Wrapper#unwrap(java.lang.Class) 664 * @see java.sql.Wrapper#unwrap(java.lang.Class)
665 */ 665 */
666 public <T> T unwrap(Class<T> iface) throws SQLException { 666 public <T> T unwrap(Class<T> iface) throws SQLException {
667 return null; 667 return null;
668 668
669 } 669 }
670 } 670 }

http://dive4elements.wald.intevation.org