|
|
|
svn_geotools
|
Author: aaime
Date: 2009-10-26 04:11:08 -0400 (Mon, 26 Oct 2009) New Revision: 34245 Modified: branches/2.5.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java branches/2.5.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java branches/2.5.x/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: branches/2.5.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java =================================================================== --- branches/2.5.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java 2009-10-26 07:59:27 UTC (rev 34244) +++ branches/2.5.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/PreparedFilterToSQL.java 2009-10-26 08:11:08 UTC (rev 34245) @@ -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; @@ -50,7 +48,7 @@ * */ public class PreparedFilterToSQL extends FilterToSQL { - + protected GeometryDescriptor currentGeometry; protected Integer currentSRID; /** @@ -241,12 +239,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: branches/2.5.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java =================================================================== --- branches/2.5.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java 2009-10-26 07:59:27 UTC (rev 34244) +++ branches/2.5.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java 2009-10-26 08:11:08 UTC (rev 34245) @@ -75,6 +75,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, @@ -435,7 +442,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 ) { @@ -724,22 +732,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; @@ -747,18 +744,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); } } } @@ -811,5 +816,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: branches/2.5.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java =================================================================== --- branches/2.5.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2009-10-26 07:59:27 UTC (rev 34244) +++ branches/2.5.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleFilterToSQL.java 2009-10-26 08:11:08 UTC (rev 34245) @@ -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; @@ -154,7 +153,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)); @@ -178,6 +177,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 |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |