From: <svn...@os...> - 2012-04-03 10:49:46
|
Author: aaime Date: 2012-04-03 03:49:34 -0700 (Tue, 03 Apr 2012) New Revision: 38655 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/OracleNGDataStoreFactory.java trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTest.java trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTestSetup.java trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java Log: [GEOT-4097] Add a geometry metadata table option to the oracle data store factory 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 2012-04-03 10:38:58 UTC (rev 38654) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleDialect.java 2012-04-03 10:49:34 UTC (rev 38655) @@ -141,6 +141,12 @@ * Remembers whether the USER_SDO_* views could be accessed or not */ Boolean canAccessUserViews; + + /** + * The direct geometry metadata table, if any + * @param dataStore + */ + String geometryMetadataTable; public OracleDialect(JDBCDataStore dataStore) { super(dataStore); @@ -205,88 +211,138 @@ final int TYPE_NAME = 6; String typeName = columnMetaData.getString(TYPE_NAME); if (typeName.equals("SDO_GEOMETRY")) { - String tableName = columnMetaData.getString(TABLE_NAME); - String columnName = columnMetaData.getString(COLUMN_NAME); - String schema = dataStore.getDatabaseSchema(); + String tableName = columnMetaData.getString(TABLE_NAME); + String columnName = columnMetaData.getString(COLUMN_NAME); + String schema = dataStore.getDatabaseSchema(); - if (canAccessUserViews(cx)) { - //we only try this block if we are able to access the - //user_sdo views + Class geometryClass = lookupGeometryOnMetadataTable(cx, tableName, columnName, schema); + if (geometryClass == null) { + lookupGeometryClassOnUserIndex(cx, tableName, columnName, schema); + } + if (geometryClass == null) { + geometryClass = lookupGeometryClassOnAllIndex(cx, tableName, columnName, schema); + } + if (geometryClass == null) { + geometryClass = Geometry.class; + } - //setup the sql to use for the USER_SDO table - String userSdoSqlStatement = "SELECT META.SDO_LAYER_GTYPE\n" + - "FROM ALL_INDEXES INFO\n" + - "INNER JOIN MDSYS.USER_SDO_INDEX_METADATA META\n" + - "ON INFO.INDEX_NAME = META.SDO_INDEX_NAME\n" + - "WHERE INFO.TABLE_NAME = '" + tableName + "'\n" + - "AND REPLACE(meta.sdo_column_name, '\"') = '" + columnName + "'\n"; + return geometryClass; + } else { + // if we know, return non null value, otherwise returning + // null will force the datatore to figure it out using + // jdbc metadata + return TYPES_TO_CLASSES.get(typeName); + } + } + + /** + * Tries to use the geometry metadata table, if available + * @param cx + * @param tableName + * @param columnName + * @param schema + * @return + * @throws SQLException + */ + private Class<?> lookupGeometryOnMetadataTable(Connection cx, String tableName, + String columnName, String schema) throws SQLException { + if(geometryMetadataTable == null) { + return null; + } + + // setup the sql to use for the ALL_SDO table + String metadataTableStatement = "SELECT TYPE FROM " + geometryMetadataTable + + " WHERE F_TABLE_NAME = '" + tableName + "'" + + " AND F_GEOMETRY_COLUMN = '" + columnName + "'"; - if(schema != null && !"".equals(schema)) { - userSdoSqlStatement += " AND INFO.TABLE_OWNER = '" + schema + "'"; - } + if(schema != null && !"".equals(schema)) { + metadataTableStatement += " AND F_TABLE_SCHEMA = '" + schema + "'"; + } + + return readGeometryClassFromStatement(cx, metadataTableStatement); + } - Statement userSdoStatement = null; - ResultSet userSdoResult = null; - try { - userSdoStatement = cx.createStatement(); - LOGGER.log(Level.FINE, "Geometry type check; {0} ", userSdoSqlStatement); - userSdoResult = userSdoStatement.executeQuery(userSdoSqlStatement); - if (userSdoResult.next()) { - String gType = userSdoResult.getString(1); - Class geometryClass = (Class) TT.GEOM_CLASSES.get(gType); - if(geometryClass == null) - geometryClass = Geometry.class; + /** + * Looks up the geometry type on the "ALL_*" metadata views + */ + private Class<?> lookupGeometryClassOnAllIndex(Connection cx, String tableName, + String columnName, String schema) throws SQLException { + // setup the sql to use for the ALL_SDO table + String allSdoSqlStatement = "SELECT META.SDO_LAYER_GTYPE\n" + + "FROM ALL_INDEXES INFO\n" + + "INNER JOIN MDSYS.ALL_SDO_INDEX_METADATA META\n" + + "ON INFO.INDEX_NAME = META.SDO_INDEX_NAME\n" + + "WHERE INFO.TABLE_NAME = '" + tableName + "'\n" + + "AND REPLACE(meta.sdo_column_name, '\"') = '" + columnName + "'\n"; - return geometryClass; - } - } finally { - dataStore.closeSafe(userSdoResult); - dataStore.closeSafe(userSdoStatement); - } - } + if(schema != null && !"".equals(schema)) { + allSdoSqlStatement += " AND INFO.TABLE_OWNER = '" + schema + "'"; + allSdoSqlStatement += " AND META.SDO_INDEX_OWNER = '" + schema + "'"; + } + + return readGeometryClassFromStatement(cx, allSdoSqlStatement); + } - Statement allSdoStatement = null; - ResultSet allSdoResult = null; - try { - //setup the sql to use for the ALL_SDO table - String allSdoSqlStatement = "SELECT META.SDO_LAYER_GTYPE\n" + - "FROM ALL_INDEXES INFO\n" + - "INNER JOIN MDSYS.ALL_SDO_INDEX_METADATA META\n" + - "ON INFO.INDEX_NAME = META.SDO_INDEX_NAME\n" + - "WHERE INFO.TABLE_NAME = '" + tableName + "'\n" + - "AND REPLACE(meta.sdo_column_name, '\"') = '" + columnName + "'\n"; + /** + * Looks up the geometry type on the "USER_*" metadata views + */ - if(schema != null && !"".equals(schema)) { - allSdoSqlStatement += " AND INFO.TABLE_OWNER = '" + schema + "'"; - allSdoSqlStatement += " AND META.SDO_INDEX_OWNER = '" + schema + "'"; - } + private Class lookupGeometryClassOnUserIndex(Connection cx, String tableName, String columnName, + String schema) throws SQLException { + // we only try this if we are able to access the + // user_sdo views + if (!canAccessUserViews(cx)) { + return null; + } + + //setup the sql to use for the USER_SDO table + String userSdoSqlStatement = "SELECT META.SDO_LAYER_GTYPE\n" + + "FROM ALL_INDEXES INFO\n" + + "INNER JOIN MDSYS.USER_SDO_INDEX_METADATA META\n" + + "ON INFO.INDEX_NAME = META.SDO_INDEX_NAME\n" + + "WHERE INFO.TABLE_NAME = '" + tableName + "'\n" + + "AND REPLACE(meta.sdo_column_name, '\"') = '" + columnName + "'\n"; - allSdoStatement = cx.createStatement(); - LOGGER.log(Level.FINE, "Geometry type check; {0} ", allSdoSqlStatement); - allSdoResult = allSdoStatement.executeQuery(allSdoSqlStatement); - if (allSdoResult.next()) { - String gType = allSdoResult.getString(1); - Class geometryClass = (Class) TT.GEOM_CLASSES.get(gType); - if(geometryClass == null) - geometryClass = Geometry.class; + if(schema != null && !"".equals(schema)) { + userSdoSqlStatement += " AND INFO.TABLE_OWNER = '" + schema + "'"; + } - return geometryClass; - } else { - //must default at this point, this is as far as we can go - return Geometry.class; - } + return readGeometryClassFromStatement(cx, userSdoSqlStatement); + } + + /** + * Reads the geometry type from the first column returned by executing the specified SQL statement + * @param cx + * @param sql + * @return + * @throws SQLException + */ + private Class readGeometryClassFromStatement(Connection cx, String sql) + throws SQLException { + Statement st = null; + ResultSet rs = null; + try { + st = cx.createStatement(); + LOGGER.log(Level.FINE, "Geometry type check; {0} ", sql); + rs = st.executeQuery(sql); + if (rs.next()) { + String gType = rs.getString(1); + Class geometryClass = (Class) TT.GEOM_CLASSES.get(gType); + if(geometryClass == null) { + // if there was a record but it's not a recognized geometry type fall back on + // geometry for backwards compatibility, but at least log the info + LOGGER.log(Level.WARNING, "Unrecognized geometry type " + gType + " falling back on generic 'GEOMETRY'"); + geometryClass = Geometry.class; + } - } finally { - dataStore.closeSafe(allSdoResult); - dataStore.closeSafe(allSdoStatement); - } - - } else { - // if we know, return non null value, otherwise returning - // null will force the datatore to figure it out using - // jdbc metadata - return TYPES_TO_CLASSES.get(typeName); - } + return geometryClass; + } + } finally { + dataStore.closeSafe(rs); + dataStore.closeSafe(st); + } + + return null; } @@ -515,56 +571,93 @@ public Integer getGeometrySRID(String schemaName, String tableName, String columnName, Connection cx) throws SQLException { - if (canAccessUserViews(cx)) { - StringBuffer userSdoSql = new StringBuffer("SELECT SRID FROM MDSYS.USER_SDO_GEOM_METADATA WHERE "); - userSdoSql.append( "TABLE_NAME='").append( tableName.toUpperCase() ).append("' AND "); - userSdoSql.append( "COLUMN_NAME='").append( columnName.toUpperCase() ).append( "'"); + Integer srid = lookupSRIDOnMetadataTable(schemaName, tableName, columnName, cx); + if(srid == null) { + srid = lookupSRIDFromUserViews(tableName, columnName, cx); + } + if(srid == null) { + srid = lookupSRIDFromAllViews(schemaName, tableName, columnName, cx); + } + return srid; + } - Statement userSdoStatement = null; - ResultSet userSdoResult = null; - try { - userSdoStatement = cx.createStatement(); - LOGGER.log(Level.FINE, "SRID check; {0} ", userSdoSql.toString()); - userSdoResult = userSdoStatement.executeQuery(userSdoSql.toString()); - if (userSdoResult.next()) { - Object srid = userSdoResult.getObject( 1 ); - if ( srid != null ) { - //return the SRID number if it was found in the USER_SDO - return ((Number) srid).intValue(); - } - } - } finally { - dataStore.closeSafe(userSdoResult); - dataStore.closeSafe(userSdoStatement); - } + /** + * Reads the SRID from the geometry metadata table, if available + */ + private Integer lookupSRIDOnMetadataTable(String schema, String tableName, String columnName, Connection cx) throws SQLException { + if(geometryMetadataTable == null) { + return null; } + + // setup the sql to use for the ALL_SDO table + String metadataTableStatement = "SELECT SRID FROM " + geometryMetadataTable + + " WHERE F_TABLE_NAME = '" + tableName + "'" + + " AND F_GEOMETRY_COLUMN = '" + columnName + "'"; + if(schema != null && !"".equals(schema)) { + metadataTableStatement += " AND F_TABLE_SCHEMA = '" + schema + "'"; + } + + return readSRIDFromStatement(cx, metadataTableStatement); + } + + /** + * Reads the SRID from the SDO_ALL* views + */ + private Integer lookupSRIDFromAllViews(String schemaName, String tableName, String columnName, + Connection cx) throws SQLException { StringBuffer allSdoSql = new StringBuffer("SELECT SRID FROM MDSYS.ALL_SDO_GEOM_METADATA WHERE "); allSdoSql.append( "TABLE_NAME='").append( tableName.toUpperCase() ).append("' AND "); allSdoSql.append( "COLUMN_NAME='").append( columnName.toUpperCase() ).append( "'"); - if(schemaName != null) + if(schemaName != null) { allSdoSql.append(" AND OWNER='" + schemaName + "'"); + } - Statement allSdoStatement = null; - ResultSet allSdoResult = null; + return readSRIDFromStatement(cx, allSdoSql.toString()); + } + + /** + * Reads the SRID from the SDO_USER* views + * @param tableName + * @param columnName + * @param cx + * @return + * @throws SQLException + */ + private Integer lookupSRIDFromUserViews(String tableName, String columnName, Connection cx) + throws SQLException { + // we run this only if we can access the user views + if (!canAccessUserViews(cx)) { + return null; + } + + StringBuffer userSdoSql = new StringBuffer("SELECT SRID FROM MDSYS.USER_SDO_GEOM_METADATA WHERE "); + userSdoSql.append( "TABLE_NAME='").append( tableName.toUpperCase() ).append("' AND "); + userSdoSql.append( "COLUMN_NAME='").append( columnName.toUpperCase() ).append( "'"); + + return readSRIDFromStatement(cx, userSdoSql.toString()); + } + + private Integer readSRIDFromStatement(Connection cx, String sql) throws SQLException { + Statement userSdoStatement = null; + ResultSet userSdoResult = null; try { - allSdoStatement = cx.createStatement(); - LOGGER.log(Level.FINE, "SRID check; {0} ", allSdoSql.toString()); - allSdoResult = allSdoStatement.executeQuery(allSdoSql.toString()); - if (allSdoResult.next()) { - Object srid = allSdoResult.getObject( 1 ); - if ( srid == null ) { - return null; + userSdoStatement = cx.createStatement(); + LOGGER.log(Level.FINE, "SRID check; {0} ", sql); + userSdoResult = userSdoStatement.executeQuery(sql); + if (userSdoResult.next()) { + Object srid = userSdoResult.getObject( 1 ); + if ( srid != null ) { + //return the SRID number if it was found in the USER_SDO + return ((Number) srid).intValue(); } - //return the SRID number if it was found in the ALL_SDO - return ((Number) srid).intValue(); - } else { - return null; } } finally { - dataStore.closeSafe(allSdoResult); - dataStore.closeSafe(allSdoStatement); + dataStore.closeSafe(userSdoResult); + dataStore.closeSafe(userSdoStatement); } + + return null; } @Override @@ -944,4 +1037,20 @@ } } + /** + * The geometry metadata table in use, if any + * @return + */ + public String getGeometryMetadataTable() { + return geometryMetadataTable; + } + + /** + * Sets the geometry metadata table + * @param geometryMetadataTable + */ + public void setGeometryMetadataTable(String geometryMetadataTable) { + this.geometryMetadataTable = geometryMetadataTable; + } + } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGDataStoreFactory.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGDataStoreFactory.java 2012-04-03 10:38:58 UTC (rev 38654) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGDataStoreFactory.java 2012-04-03 10:49:34 UTC (rev 38655) @@ -19,7 +19,6 @@ import java.io.IOException; import java.util.Map; -import org.geotools.data.DataAccessFactory.Param; import org.geotools.jdbc.JDBCDataStore; import org.geotools.jdbc.JDBCDataStoreFactory; import org.geotools.jdbc.SQLDialect; @@ -55,6 +54,10 @@ /** parameter for namespace of the datastore */ public static final Param LOOSEBBOX = new Param("Loose bbox", Boolean.class, "Perform only primary filter on bbox", false, Boolean.TRUE); + /** Metadata table providing information about primary keys **/ + public static final Param GEOMETRY_METADATA_TABLE = new Param("Geometry metadata table", String.class, + "The optional table containing geometry metadata (geometry type and srid). Can be expressed as 'schema.name' or just 'name'", false); + @Override protected SQLDialect createSQLDialect(JDBCDataStore dataStore) { return new OracleDialect(dataStore); @@ -104,8 +107,9 @@ throws IOException { // make the schema uppercase if it's not already - if(dataStore.getDatabaseSchema() != null) + if(dataStore.getDatabaseSchema() != null) { dataStore.setDatabaseSchema(dataStore.getDatabaseSchema().toUpperCase()); + } // setup loose bbox OracleDialect dialect = (OracleDialect) dataStore.getSQLDialect(); @@ -116,6 +120,10 @@ Boolean estimated = (Boolean) ESTIMATED_EXTENTS.lookUp(params); dialect.setEstimatedExtentsEnabled(estimated == null || Boolean.TRUE.equals(estimated)); + // check the geometry metadata table + String metadataTable = (String) GEOMETRY_METADATA_TABLE.lookUp(params); + dialect.setGeometryMetadataTable(metadataTable); + // setup proper fetch size dataStore.setFetchSize(200); @@ -151,10 +159,11 @@ parameters.put(HOST.key, HOST); parameters.put(DATABASE.key, DATABASE); parameters.put(DBTYPE.key, DBTYPE); + parameters.put(GEOMETRY_METADATA_TABLE.key, GEOMETRY_METADATA_TABLE); } @Override protected String getValidationQuery() { - return "select sysdate from dual"; + return "select 1 from dual"; } } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTest.java 2012-04-03 10:38:58 UTC (rev 38654) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTest.java 2012-04-03 10:49:34 UTC (rev 38655) @@ -19,11 +19,14 @@ import org.geotools.data.simple.SimpleFeatureIterator; import org.geotools.jdbc.JDBCGeometryTest; import org.geotools.jdbc.JDBCGeometryTestSetup; +import org.geotools.referencing.CRS; import org.opengis.feature.simple.SimpleFeature; +import org.opengis.feature.type.GeometryDescriptor; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LinearRing; +import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.io.WKTReader; /** @@ -32,10 +35,13 @@ * @source $URL$ */ public class OracleGeometryTest extends JDBCGeometryTest { + + OracleGeometryTestSetup testSetup; @Override protected JDBCGeometryTestSetup createTestSetup() { - return new OracleGeometryTestSetup(); + testSetup = new OracleGeometryTestSetup(); + return testSetup; } public void testLinearRing() throws Exception { @@ -51,4 +57,12 @@ assertTrue(expected.equalsTopo((Geometry) sf.getDefaultGeometry())); fi.close(); } + + public void testGeometryMetadataTable() throws Exception { + testSetup.setupGeometryColumns(dataStore); + + GeometryDescriptor gd = dataStore.getFeatureSource("GTMETA").getSchema().getGeometryDescriptor(); + assertEquals(Point.class, gd.getType().getBinding()); + assertEquals(4269, (int) CRS.lookupEpsgCode(gd.getCoordinateReferenceSystem(), false)); + } } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTestSetup.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTestSetup.java 2012-04-03 10:38:58 UTC (rev 38654) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleGeometryTestSetup.java 2012-04-03 10:49:34 UTC (rev 38655) @@ -16,6 +16,7 @@ */ package org.geotools.data.oracle; +import org.geotools.jdbc.JDBCDataStore; import org.geotools.jdbc.JDBCGeometryTestSetup; /** @@ -35,7 +36,10 @@ // clean up runSafe("DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'COLA_MARKETS_CS'" ); + runSafe("DELETE FROM USER_SDO_GEOM_METADATA WHERE TABLE_NAME = 'GTMETA'" ); runSafe("DROP TABLE COLA_MARKETS_CS PURGE"); + runSafe("DROP TABLE GTMETA PURGE"); + runSafe("DROP TABLE GEOMETRY_COLUMNS PURGE"); // create the cola markets table run("CREATE TABLE cola_markets_cs (" + @@ -75,6 +79,23 @@ " SDO_ORDINATE_ARRAY(6,6, 12,6, 9,8, 6,10, 12,10, 6,4, 12,12)" + " )" + ")"); + + String sql = "CREATE TABLE gtmeta (" + + "id INT, geometry MDSYS.SDO_GEOMETRY, intProperty INT, " + + "doubleProperty FLOAT, stringProperty VARCHAR(255))"; + run(sql); + + sql = "INSERT INTO USER_SDO_GEOM_METADATA (TABLE_NAME, COLUMN_NAME, DIMINFO, SRID ) " + + "VALUES ('GTMETA','GEOMETRY',MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X',-180,180,0.5), " + + "MDSYS.SDO_DIM_ELEMENT('Y',-90,90,0.5)), 4326)"; + run(sql); + + sql = "CREATE INDEX GTMETA_GEOMETRY_IDX ON GTMETA(GEOMETRY) INDEXTYPE IS MDSYS.SPATIAL_INDEX"; + run(sql); + + sql = "INSERT INTO GTMETA VALUES (0," + + "MDSYS.SDO_GEOMETRY(2001,4326,SDO_POINT_TYPE(0.0,0.0,NULL),NULL,NULL), 0, 0.0,'zero')"; + run(sql); } @Override @@ -84,4 +105,19 @@ + "'"); } + public void setupGeometryColumns(JDBCDataStore dataStore) throws Exception { + String schema = dataStore.getDatabaseSchema(); + + String sql = "CREATE TABLE GEOMETRY_COLUMNS(F_TABLE_SCHEMA VARCHAR(30), F_TABLE_NAME VARCHAR(30), " + + "F_GEOMETRY_COLUMN VARCHAR(30), COORD_DIMENSION INTEGER, SRID INTEGER, TYPE VARCHAR(30))"; + run(sql); + + // register it in the override table with a different srs, so that we're sure it's getting read + sql = "INSERT INTO GEOMETRY_COLUMNS (F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN, COORD_DIMENSION, SRID, TYPE) " + + "VALUES ('" + schema + "', 'GTMETA','GEOMETRY', 2, 4269, 'POINT')"; + run(sql); + + ((OracleDialect) dataStore.getSQLDialect()).setGeometryMetadataTable("GEOMETRY_COLUMNS"); + } + } Modified: trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java 2012-04-03 10:38:58 UTC (rev 38654) +++ trunk/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java 2012-04-03 10:49:34 UTC (rev 38655) @@ -16,12 +16,8 @@ */ package org.geotools.data.oracle; -import static org.geotools.jdbc.JDBCDataStoreFactory.DATABASE; -import static org.geotools.jdbc.JDBCDataStoreFactory.DBTYPE; -import static org.geotools.jdbc.JDBCDataStoreFactory.HOST; -import static org.geotools.jdbc.JDBCDataStoreFactory.PASSWD; -import static org.geotools.jdbc.JDBCDataStoreFactory.PORT; -import static org.geotools.jdbc.JDBCDataStoreFactory.USER; +import static org.geotools.data.oracle.OracleNGDataStoreFactory.GEOMETRY_METADATA_TABLE; +import static org.geotools.jdbc.JDBCDataStoreFactory.*; import java.io.IOException; import java.util.HashMap; @@ -31,6 +27,7 @@ import org.geotools.jdbc.JDBCDataStore; import org.geotools.jdbc.JDBCTestSetup; import org.geotools.jdbc.JDBCTestSupport; +import org.geotools.jdbc.SQLDialect; import org.geotools.test.FixtureUtilities; /** @@ -54,7 +51,33 @@ OracleNGDataStoreFactory factory = new OracleNGDataStoreFactory(); checkCreateConnection(factory, "oracle"); } + + public void testGeometryMetadata() throws IOException { + OracleNGDataStoreFactory factory = new OracleNGDataStoreFactory(); + Properties db = FixtureUtilities.loadFixture("oracle"); + Map<String, Object> params = new HashMap<String, Object>(); + params.put(HOST.key, db.getProperty(HOST.key)); + params.put(DATABASE.key, db.getProperty(DATABASE.key)); + params.put(PORT.key, db.getProperty(PORT.key)); + params.put(USER.key, db.getProperty(USER.key)); + params.put(PASSWD.key, db.getProperty("password")); + params.put(DBTYPE.key, "oracle"); + params.put(GEOMETRY_METADATA_TABLE.key, "geometry_columns_test"); + assertTrue(factory.canProcess(params)); + JDBCDataStore store = factory.createDataStore(params); + assertNotNull(store); + try { + // check dialect + OracleDialect dialect = (OracleDialect) store.getSQLDialect(); + + // check the metadata table has been set (other tests check it's actually working) + assertEquals("geometry_columns_test", dialect.getGeometryMetadataTable()); + } finally { + store.dispose(); + } + } + private void checkCreateConnection(OracleNGDataStoreFactory factory, String dbtype) throws IOException { Properties db = FixtureUtilities.loadFixture("oracle"); Map<String, Object> params = new HashMap<String, Object>(); @@ -63,7 +86,6 @@ params.put(PORT.key, db.getProperty(PORT.key)); params.put(USER.key, db.getProperty(USER.key)); params.put(PASSWD.key, db.getProperty("password")); - params.put(DBTYPE.key, dbtype); assertTrue(factory.canProcess(params)); @@ -78,5 +100,7 @@ store.dispose(); } } + + } |