Gabriel (and other arcsde folks!)

I'm attaching a patch that deals with four JIRA issues. The two versions are exactly the same, one just works with trunk paths, the other with 2.3.x paths.

Jira issues http://jira.codehaus.org/browse/GEOT-1007 and http://jira.codehaus.org/browse/GEOT-1006

Easy ones.  Both describe improvements made with this patch.



http://jira.codehaus.org/browse/GEOT-986 (and dependent geoserver JIRA http://jira.codehaus.org/browse/GEOS-747)


Logging sql in SDE is hard, and mostly impossible to do. The comments say exactly why. This patch gets a *little* further by showing which portions of the gt filter are getting set to which parts of the SDE query. At least it will tip you off to the fact that your query is not getting sent to the db at all.

It also prints the SQL for the "where-clause" (non-spatial) portion of the SDE query.


Can you give feedback and (if you don't have any objections) apply to 2.3.x and trunk gabriel? Thanks!

I'm working on porting this to 2.2.x as well.  I'll post that later.

--saul


Index: plugin/arcsde/datastore/src/org/geotools/filter/SQLEncoderSDE.java
===================================================================
--- plugin/arcsde/datastore/src/org/geotools/filter/SQLEncoderSDE.java	(revision 22550)
+++ plugin/arcsde/datastore/src/org/geotools/filter/SQLEncoderSDE.java	(working copy)
@@ -101,6 +101,7 @@
         capabilities.addType(FilterCapabilities.FID);
         capabilities.addType(FilterCapabilities.NONE);
         capabilities.addType(FilterCapabilities.ALL);
+        capabilities.addType(FilterCapabilities.LIKE);
 
         return capabilities;
     }
Index: plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEDataStore.java
===================================================================
--- plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEDataStore.java	(revision 22550)
+++ plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEDataStore.java	(working copy)
@@ -18,10 +18,8 @@
 
 import java.io.IOException;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
@@ -846,8 +844,20 @@
      */
     protected Envelope getBounds(Query query) throws IOException {
         LOGGER.info("getBounds");
-
-        Envelope ev = ArcSDEQuery.calculateQueryExtent(this, query);
+        
+        Envelope ev;
+        if (query.getFilter() == null || query.getFilter().equals(Filter.NONE)) {
+        	LOGGER.fine("getting bounds of entire layer.  Using optimized SDE call.");
+        	// we're really asking for a bounds of the WHOLE layer,
+        	// let's just ask SDE metadata for that, rather than doing an expensive query
+        	SeLayer thisLayer = this.connectionPool.getSdeLayer(query.getTypeName());
+        	SeExtent extent = thisLayer.getExtent();
+        	ev = new Envelope(extent.getMinX(), extent.getMaxX(),
+                    extent.getMinY(), extent.getMaxY());
+        } else {
+        	ev = ArcSDEQuery.calculateQueryExtent(this, query);
+        }
+        
         LOGGER.info("bounds: " + ev);
 
         return ev;
Index: plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEAttributeReader.java
===================================================================
--- plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEAttributeReader.java	(revision 22550)
+++ plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEAttributeReader.java	(working copy)
@@ -201,7 +201,8 @@
 									throw new DataSourceException("Unable to reliably determine an FID column for this table, so we defaulted to using the '" + featureIDAttributeName +"' column.  But it was null, leaving us no FID for this feature.");
 								} else {
 									this.currentFid = Long.parseLong(value.toString());
-									LOGGER.fine("Fetched fid " + this.currentFid + " from column " + featureIDAttributeName);
+									if (LOGGER.isLoggable(Level.FINER))
+										LOGGER.finer("Fetched fid " + this.currentFid + " from column " + featureIDAttributeName);
 									continue;
 								}
 							}
Index: plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEQuery.java
===================================================================
--- plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEQuery.java	(revision 22550)
+++ plugin/arcsde/datastore/src/org/geotools/data/arcsde/ArcSDEQuery.java	(working copy)
@@ -243,7 +243,7 @@
         }
         
         if (!hasFIDColumn) {
-        	LOGGER.warning("No FID attribute was contained in your query.  Appending the discovered one to the list of columns to be fetched.");
+        	LOGGER.info("No FID attribute was contained in your query.  Appending the discovered one to the list of columns to be fetched.");
         	for (int i = 0; i < schema.getAttributeCount(); i++) {
         		AttributeType type = schema.getAttributeType(i);
             	if (type instanceof ArcSDEAttributeType) {
@@ -251,7 +251,7 @@
             			String[] newQCols = new String[queryColumns.length + 1];
             			System.arraycopy(queryColumns, 0, newQCols, 0, queryColumns.length);
             			newQCols[queryColumns.length] = type.getName();
-            			LOGGER.warning("Appendend " + newQCols[queryColumns.length] + " to column list.");
+            			LOGGER.fine("Appendend " + newQCols[queryColumns.length] + " to column list.");
                     	queryColumns = newQCols;
             			break;
             		}
@@ -342,8 +342,8 @@
         if (LOGGER.isLoggable(Level.FINE)) {
             LOGGER.fine("constructing new sql query with connection: "
                 + connection + ", propnames: "
-                + java.util.Arrays.asList(propertyNames) + " sqlConstruct: "
-                + this.filters.getSeSqlConstruct());
+                + java.util.Arrays.asList(propertyNames) + " sqlConstruct where clause: '"
+                + this.filters.getSeSqlConstruct().getWhere());
         }
 
         SeQuery query = new SeQuery(connection, propertyNames,
@@ -929,6 +929,9 @@
             unpacker.unPackAND(this.sourceFilter);
 
             this.sqlFilter = unpacker.getSupported();
+            
+            if (LOGGER.isLoggable(Level.FINE) && sqlFilter != null)
+            	LOGGER.fine("SQL portion of SDE Query: '" + sqlFilter + "'");
 
             Filter remainingFilter = unpacker.getUnSupported();
 
@@ -936,7 +939,12 @@
             unpacker.unPackAND(remainingFilter);
 
             this.geometryFilter = unpacker.getSupported();
+            if (LOGGER.isLoggable(Level.FINE) && geometryFilter != null)
+            	LOGGER.fine("Spatial-Filter portion of SDE Query: '" + geometryFilter + "'");
+            
             this.unsupportedFilter = unpacker.getUnSupported();
+            if (LOGGER.isLoggable(Level.FINE) && unsupportedFilter != null)
+            	LOGGER.fine("Unsupported (and therefore ignored) portion of SDE Query: '" + unsupportedFilter + "'");
         }
 
         /**
Index: modules/unsupported/arcsde/datastore/src/main/java/org/geotools/filter/SQLEncoderSDE.java
===================================================================
--- modules/unsupported/arcsde/datastore/src/main/java/org/geotools/filter/SQLEncoderSDE.java	(revision 22554)
+++ modules/unsupported/arcsde/datastore/src/main/java/org/geotools/filter/SQLEncoderSDE.java	(working copy)
@@ -101,6 +101,7 @@
         capabilities.addType(FilterCapabilities.FID);
         capabilities.addType(FilterCapabilities.NONE);
         capabilities.addType(FilterCapabilities.ALL);
+        capabilities.addType(FilterCapabilities.LIKE);
 
         return capabilities;
     }
Index: modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEDataStore.java
===================================================================
--- modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEDataStore.java	(revision 22554)
+++ modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEDataStore.java	(working copy)
@@ -18,10 +18,8 @@
 
 import java.io.IOException;
 import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
@@ -846,8 +844,20 @@
      */
     protected Envelope getBounds(Query query) throws IOException {
         LOGGER.info("getBounds");
-
-        Envelope ev = ArcSDEQuery.calculateQueryExtent(this, query);
+        
+        Envelope ev;
+        if (query.getFilter() == null || query.getFilter().equals(Filter.NONE)) {
+        	LOGGER.fine("getting bounds of entire layer.  Using optimized SDE call.");
+        	// we're really asking for a bounds of the WHOLE layer,
+        	// let's just ask SDE metadata for that, rather than doing an expensive query
+        	SeLayer thisLayer = this.connectionPool.getSdeLayer(query.getTypeName());
+        	SeExtent extent = thisLayer.getExtent();
+        	ev = new Envelope(extent.getMinX(), extent.getMaxX(),
+                    extent.getMinY(), extent.getMaxY());
+        } else {
+        	ev = ArcSDEQuery.calculateQueryExtent(this, query);
+        }
+        
         LOGGER.info("bounds: " + ev);
 
         return ev;
Index: modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEAttributeReader.java
===================================================================
--- modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEAttributeReader.java	(revision 22554)
+++ modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEAttributeReader.java	(working copy)
@@ -201,7 +201,8 @@
 									throw new DataSourceException("Unable to reliably determine an FID column for this table, so we defaulted to using the '" + featureIDAttributeName +"' column.  But it was null, leaving us no FID for this feature.");
 								} else {
 									this.currentFid = Long.parseLong(value.toString());
-									LOGGER.fine("Fetched fid " + this.currentFid + " from column " + featureIDAttributeName);
+									if (LOGGER.isLoggable(Level.FINER))
+										LOGGER.finer("Fetched fid " + this.currentFid + " from column " + featureIDAttributeName);
 									continue;
 								}
 							}
Index: modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEQuery.java
===================================================================
--- modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEQuery.java	(revision 22554)
+++ modules/unsupported/arcsde/datastore/src/main/java/org/geotools/data/arcsde/ArcSDEQuery.java	(working copy)
@@ -243,7 +243,7 @@
         }
         
         if (!hasFIDColumn) {
-        	LOGGER.warning("No FID attribute was contained in your query.  Appending the discovered one to the list of columns to be fetched.");
+        	LOGGER.info("No FID attribute was contained in your query.  Appending the discovered one to the list of columns to be fetched.");
         	for (int i = 0; i < schema.getAttributeCount(); i++) {
         		AttributeType type = schema.getAttributeType(i);
             	if (type instanceof ArcSDEAttributeType) {
@@ -251,7 +251,7 @@
             			String[] newQCols = new String[queryColumns.length + 1];
             			System.arraycopy(queryColumns, 0, newQCols, 0, queryColumns.length);
             			newQCols[queryColumns.length] = type.getName();
-            			LOGGER.warning("Appendend " + newQCols[queryColumns.length] + " to column list.");
+            			LOGGER.fine("Appendend " + newQCols[queryColumns.length] + " to column list.");
                     	queryColumns = newQCols;
             			break;
             		}
@@ -342,8 +342,8 @@
         if (LOGGER.isLoggable(Level.FINE)) {
             LOGGER.fine("constructing new sql query with connection: "
                 + connection + ", propnames: "
-                + java.util.Arrays.asList(propertyNames) + " sqlConstruct: "
-                + this.filters.getSeSqlConstruct());
+                + java.util.Arrays.asList(propertyNames) + " sqlConstruct where clause: '"
+                + this.filters.getSeSqlConstruct().getWhere());
         }
 
         SeQuery query = new SeQuery(connection, propertyNames,
@@ -929,6 +929,9 @@
             unpacker.unPackAND(this.sourceFilter);
 
             this.sqlFilter = unpacker.getSupported();
+            
+            if (LOGGER.isLoggable(Level.FINE) && sqlFilter != null)
+            	LOGGER.fine("SQL portion of SDE Query: '" + sqlFilter + "'");
 
             Filter remainingFilter = unpacker.getUnSupported();
 
@@ -936,7 +939,12 @@
             unpacker.unPackAND(remainingFilter);
 
             this.geometryFilter = unpacker.getSupported();
+            if (LOGGER.isLoggable(Level.FINE) && geometryFilter != null)
+            	LOGGER.fine("Spatial-Filter portion of SDE Query: '" + geometryFilter + "'");
+            
             this.unsupportedFilter = unpacker.getUnSupported();
+            if (LOGGER.isLoggable(Level.FINE) && unsupportedFilter != null)
+            	LOGGER.fine("Unsupported (and therefore ignored) portion of SDE Query: '" + unsupportedFilter + "'");
         }
 
         /**
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to