From: <svn...@os...> - 2010-02-26 14:06:16
|
Author: jdeolive Date: 2010-02-26 09:05:31 -0500 (Fri, 26 Feb 2010) New Revision: 34955 Modified: trunk/modules/plugin/jdbc/jdbc-h2/pom.xml trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2Dialect.java trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectBasic.java trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectPrepared.java Log: upgraded geodb dependency Modified: trunk/modules/plugin/jdbc/jdbc-h2/pom.xml =================================================================== --- trunk/modules/plugin/jdbc/jdbc-h2/pom.xml 2010-02-26 10:57:53 UTC (rev 34954) +++ trunk/modules/plugin/jdbc/jdbc-h2/pom.xml 2010-02-26 14:05:31 UTC (rev 34955) @@ -68,7 +68,7 @@ <dependency> <groupId>org.opengeo</groupId> <artifactId>geodb</artifactId> - <version>0.1</version> + <version>0.2</version> <exclusions> <exclusion> <groupId>com.h2database</groupId> Modified: trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DataStoreFactory.java 2010-02-26 10:57:53 UTC (rev 34954) +++ trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DataStoreFactory.java 2010-02-26 14:05:31 UTC (rev 34955) @@ -138,8 +138,15 @@ //use current working directory dataSource.setUrl("jdbc:h2:" + database); } else { - //use directory specified - String location = new File(baseDirectory, database).getAbsolutePath(); + //use directory specified if the patch is relative + String location; + if (!new File(database).isAbsolute()) { + location = new File(baseDirectory, database).getAbsolutePath(); + } + else { + location = database; + } + dataSource.setUrl("jdbc:h2:file:" + location); } Modified: trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2Dialect.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2Dialect.java 2010-02-26 10:57:53 UTC (rev 34954) +++ trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2Dialect.java 2010-02-26 14:05:31 UTC (rev 34955) @@ -29,14 +29,18 @@ import java.sql.Statement; import java.sql.Types; import java.util.Map; +import java.util.logging.Level; import org.geotools.geometry.jts.Geometries; import org.geotools.jdbc.JDBCDataStore; import org.geotools.jdbc.SQLDialect; +import org.geotools.referencing.CRS; import org.opengis.feature.simple.SimpleFeatureType; import org.opengis.feature.type.AttributeDescriptor; import org.opengis.feature.type.GeometryDescriptor; import org.opengis.feature.type.PropertyDescriptor; +import org.opengis.referencing.FactoryException; +import org.opengis.referencing.crs.CoordinateReferenceSystem; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; @@ -104,6 +108,16 @@ } @Override + public boolean includeTable(String schemaName, String tableName, Connection cx) + throws SQLException { + if ("_GEODB".equals(tableName) || tableName.endsWith("_HATBOX")) { + return false; + } + + return true; + } + + @Override public Class<?> getMapping(ResultSet columnMetaData, Connection cx) throws SQLException { @@ -137,14 +151,17 @@ SimpleFeatureType featureType, Connection cx) throws SQLException { Statement st = cx.createStatement(); + String tableName = featureType.getTypeName(); + try { //post process the feature type and set up constraints based on geometry type for ( PropertyDescriptor ad : featureType.getDescriptors() ) { if ( ad instanceof GeometryDescriptor ) { + GeometryDescriptor gd = (GeometryDescriptor)ad; Class binding = ad.getType().getBinding(); + String propertyName = ad.getName().getLocalPart(); + if ( isConcreteGeometry( binding ) ) { - String tableName = featureType.getTypeName(); - String propertyName = ad.getName().getLocalPart(); StringBuffer sql = new StringBuffer(); sql.append( "ALTER TABLE "); encodeTableName(tableName, sql); @@ -161,6 +178,38 @@ LOGGER.fine( sql.toString() ); st.execute( sql.toString() ); } + + //create a spatial index + CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); + if (crs == null) { + continue; + } + + Integer epsg = null; + try { + epsg = CRS.lookupEpsgCode(crs, true); + } + catch (FactoryException e) { + LOGGER.log(Level.FINER, "Unable to look epsg code", e); + } + + if (epsg != null) { + StringBuffer sql = new StringBuffer(); + sql.append("CALL CreateSpatialIndex("); + if (schemaName == null) { + sql.append("NULL"); + } + else { + sql.append("'").append(schemaName).append("'"); + } + + sql.append(",'").append(tableName).append("'"); + sql.append(",'").append(propertyName).append("'"); + sql.append(",'").append(epsg).append("')"); + + LOGGER.fine(sql.toString()); + st.execute(sql.toString()); + } } } } Modified: trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectBasic.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectBasic.java 2010-02-26 10:57:53 UTC (rev 34954) +++ trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectBasic.java 2010-02-26 14:05:31 UTC (rev 34955) @@ -61,6 +61,12 @@ } @Override + public boolean includeTable(String schemaName, String tableName, Connection cx) + throws SQLException { + return delegate.includeTable(schemaName, tableName, cx); + } + + @Override public String getNameEscape() { return delegate.getNameEscape(); } Modified: trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectPrepared.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectPrepared.java 2010-02-26 10:57:53 UTC (rev 34954) +++ trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DialectPrepared.java 2010-02-26 14:05:31 UTC (rev 34955) @@ -64,6 +64,12 @@ } @Override + public boolean includeTable(String schemaName, String tableName, Connection cx) + throws SQLException { + return delegate.includeTable(schemaName, tableName, cx); + } + + @Override public String getNameEscape() { return delegate.getNameEscape(); } |