svn - r34241 - in trunk/modules: library/jdbc/src/main/java/org/geotools/jdbc plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle

1 message Options
Embed this post
Permalink
svn_geotools

svn - r34241 - in trunk/modules: library/jdbc/src/main/java/org/geotools/jdbc plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle

Reply Threaded More More options
Print post
Permalink
Author: aaime
Date: 2009-10-26 02:41:59 -0400 (Mon, 26 Oct 2009)
New Revision: 34241

Modified:
   trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java
   trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java
   trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java
Log:
GEOT-2801, Oracle (NG) datastore may deadlock under high load

Modified: trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java
===================================================================
--- trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java 2009-10-26 04:15:35 UTC (rev 34240)
+++ trunk/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java 2009-10-26 06:41:59 UTC (rev 34241)
@@ -28,8 +28,6 @@
 import org.opengis.feature.type.GeometryDescriptor;
 import org.opengis.filter.BinaryComparisonOperator;
 import org.opengis.filter.Id;
-import org.opengis.filter.expression.Expression;
-import org.opengis.filter.expression.Function;
 import org.opengis.filter.expression.Literal;
 import org.opengis.filter.expression.PropertyName;
 import org.opengis.filter.identity.Identifier;
@@ -52,7 +50,7 @@
  * @source $URL$
  */
 public class PreparedFilterToSQL extends FilterToSQL {
-    
+    protected GeometryDescriptor currentGeometry;
     protected Integer currentSRID;
 
     /**
@@ -243,12 +241,14 @@
         }
         
         // handle native srid
+        currentGeometry = null;
         currentSRID = null;
         if(featureType != null) {
             // going thru evaluate ensures we get the proper result even if the name has
             // not been specified (convention -> the default geometry)
             AttributeDescriptor descriptor = (AttributeDescriptor) property.evaluate(featureType);
             if(descriptor instanceof GeometryDescriptor) {
+                currentGeometry = (GeometryDescriptor) descriptor;
                 currentSRID = (Integer) descriptor.getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID);
             }
         }

Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java 2009-10-26 04:15:35 UTC (rev 34240)
+++ trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java 2009-10-26 06:41:59 UTC (rev 34241)
@@ -77,6 +77,13 @@
     private static final int DEFAULT_AXIS_MAX = 1000000;
 
     private static final int DEFAULT_AXIS_MIN = -10000000;
+    
+    /**
+     * Marks a geometry column as geodetic
+     */
+    public static final String GEODETIC = "geodetic";
+    
+    UnWrapper uw;
 
     /**
      * A map from JTS Geometry type to Oracle geometry type. See Oracle Spatial documentation,
@@ -443,7 +450,8 @@
         }
         
         try {
-            UnWrapper uw = DataSourceFinder.getUnWrapper( cx );
+            if(uw == null)
+                uw = DataSourceFinder.getUnWrapper( cx );
             if ( uw != null ) {
                 Connection uwcx = uw.unwrap( cx );
                 if ( uwcx != null && uwcx instanceof OracleConnection ) {
@@ -732,22 +740,11 @@
         
     }
 
-    protected boolean isGeodeticSrid(Integer srid) {
-        Connection cx = null;
-        try {
-            cx = dataStore.getDataSource().getConnection();
-            return isGeodeticSrid(srid, cx);
-        } catch (SQLException e) {
-            LOGGER.warning("Could not evaluate if SRID is Geodetic. Wrong results may occur.");
-        } finally {
-            if (cx != null)
-                dataStore.closeSafe(cx);
-        }
-        
-        return false;
-    }
-
-    protected boolean isGeodeticSrid(Integer srid, Connection cx) throws SQLException {
+    /**
+     * Checks if the specified srid is geodetic or not
+     * @throws SQLException
+     */
+    protected boolean isGeodeticSrid(Integer srid, Connection cx) {
         if (srid == null)
             return false;
         
@@ -755,18 +752,26 @@
         
         if(geodetic == null) {
             synchronized (this) {
+                geodetic = geodeticCache.get(srid);
+                
                 if(geodetic == null) {
                     PreparedStatement ps = null;
                     ResultSet rs = null;
+                    boolean closeConnection = false;
                     try {
                         ps = cx.prepareStatement("SELECT COUNT(*) FROM MDSYS.GEODETIC_SRIDS WHERE SRID = ?");
                         ps.setInt(1, srid);
                         rs = ps.executeQuery();
                         rs.next();
                         geodetic = rs.getInt(1) > 0;
+                        geodeticCache.put(srid, geodetic);
+                    } catch(SQLException e) {
+                        LOGGER.log(Level.WARNING, "Could not evaluate if the SRID " + srid + " is geodetic", e);
                     } finally {
                         dataStore.closeSafe(rs);
                         dataStore.closeSafe(ps);
+                        if(closeConnection)
+                            dataStore.closeSafe(cx);
                     }
                 }
             }
@@ -819,5 +824,17 @@
      overrides.put(Types.DOUBLE, "DOUBLE PRECISION");
      overrides.put(Types.FLOAT, "FLOAT");
     }
+    
+    @Override
+    public void postCreateAttribute(AttributeDescriptor att, ResultSet columnMetadata,
+            String tableName, String schemaName, Connection cx) throws SQLException {
+        super.postCreateAttribute(att, columnMetadata, tableName, schemaName, cx);
+        
+        if(att instanceof GeometryDescriptor) {
+            Integer srid = (Integer) att.getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID);
+            boolean geodetic = isGeodeticSrid(srid, cx);
+            att.getUserData().put(GEODETIC, geodetic);
+        }
+    }
 
 }

Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java
===================================================================
--- trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2009-10-26 04:15:35 UTC (rev 34240)
+++ trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2009-10-26 06:41:59 UTC (rev 34241)
@@ -50,7 +50,6 @@
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryCollection;
 import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.LinearRing;
 import com.vividsolutions.jts.geom.MultiLineString;
 import com.vividsolutions.jts.geom.MultiPoint;
 import com.vividsolutions.jts.geom.MultiPolygon;
@@ -156,7 +155,7 @@
             Geometry eval = geometry.evaluate(filter, Geometry.class);
             // Oracle cannot deal with filters using geometries that span beyond the whole world
             // in case the
-            if (dialect != null && ((OracleDialect)dialect).isGeodeticSrid(currentSRID) &&
+            if (dialect != null && isCurrentGeometryGeodetic() &&
                     !WORLD.contains(eval.getEnvelopeInternal())) {
                 Geometry result = eval.intersection(JTS.toGeometry(WORLD));
                 
@@ -180,6 +179,18 @@
         return extraData;
     }
     
+    /**
+     * Returns true if the current geometry has the geodetic marker raised
+     * @return
+     */
+    boolean isCurrentGeometryGeodetic() {
+        if(currentGeometry != null) {
+            Boolean geodetic = (Boolean) currentGeometry.getUserData().get(OracleDialect.GEODETIC);
+            return geodetic != null && geodetic;
+        }
+        return false;    
+    }
+
     protected Geometry distillSameTypeGeometries(GeometryCollection coll, Geometry original) {
         if(original instanceof Polygon || original instanceof MultiPolygon) {
             List<Polygon> polys = new ArrayList<Polygon>();


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoTools-commits mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-commits