|
|
|
svn_geotools
|
Author: jdeolive
Date: 2009-10-24 22:51:54 -0400 (Sat, 24 Oct 2009) New Revision: 34219 Added: branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/resources/org/geotools/data/oracle/factory.properties Modified: branches/2.6.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java branches/2.6.x/modules/plugin/jdbc/jdbc-db2/src/main/java/org/geotools/data/db2/DB2NGDataStoreFactory.java branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGDataStoreFactory.java branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGDataStoreFactory.java branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisNGDataStoreFactoryTest.java Log: GEOT-2598, having ng datastores recognize old dbtypes Modified: branches/2.6.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java =================================================================== --- branches/2.6.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java 2009-10-25 02:51:42 UTC (rev 34218) +++ branches/2.6.x/modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStoreFactory.java 2009-10-25 02:51:54 UTC (rev 34219) @@ -106,12 +106,20 @@ return false; // was not in agreement with getParametersInfo } + return checkDBType(params); + } + + protected boolean checkDBType(Map params) { + return checkDBType(params, getDatabaseID()); + } + + protected final boolean checkDBType(Map params, String dbtype) { String type; try { type = (String) DBTYPE.lookUp(params); - if (getDatabaseID().equals(type)) { + if (dbtype.equals(type)) { return true; } Modified: branches/2.6.x/modules/plugin/jdbc/jdbc-db2/src/main/java/org/geotools/data/db2/DB2NGDataStoreFactory.java =================================================================== --- branches/2.6.x/modules/plugin/jdbc/jdbc-db2/src/main/java/org/geotools/data/db2/DB2NGDataStoreFactory.java 2009-10-25 02:51:42 UTC (rev 34218) +++ branches/2.6.x/modules/plugin/jdbc/jdbc-db2/src/main/java/org/geotools/data/db2/DB2NGDataStoreFactory.java 2009-10-25 02:51:54 UTC (rev 34219) @@ -68,6 +68,29 @@ } @Override + protected boolean checkDBType(Map params) { + if (super.checkDBType(params)) { + return true; + } + + //check also for "DB2" which is the old db type, but only when the old + // factory is not on the classpath + if (checkDBType(params, "DB2")) { + try { + Class.forName("org.geotools.data.db2.DB2DataStoreFactory"); + + //old factory is around, let it handle the connection + return false; + } + catch (ClassNotFoundException e) { + return true; + } + } + + return false; + } + + @Override protected String getJDBCUrl(Map params) throws IOException { // jdbc url String host=null; Modified: branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGDataStoreFactory.java =================================================================== --- branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGDataStoreFactory.java 2009-10-25 02:51:42 UTC (rev 34218) +++ branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/main/java/org/geotools/data/oracle/OracleNGDataStoreFactory.java 2009-10-25 02:51:54 UTC (rev 34219) @@ -35,7 +35,7 @@ private static final String JDBC_PATH = "jdbc:oracle:thin:@"; /** parameter for database type */ - public static final Param DBTYPE = new Param("dbtype", String.class, "Type", true, "Oracle"); + public static final Param DBTYPE = new Param("dbtype", String.class, "Type", true, "oracle"); /** parameter for database port */ public static final Param PORT = new Param("port", Integer.class, "Port", true, 1521); @@ -67,6 +67,27 @@ return "oracle.jdbc.driver.OracleDriver"; } + @Override + protected boolean checkDBType(Map params) { + if (super.checkDBType(params)) { + try { + //check for old factory + Class.forName("org.geotools.data.oracle.OracleDataStoreFactory"); + + //it is around, let it handle this connection + return false; + } + catch(ClassNotFoundException e) { + //old factory not around, pick up the connection + return true; + } + } + else { + //check for the old id + return checkDBType(params, "Oracle"); + } + } + protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map params) throws IOException { Added: branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java =================================================================== --- branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java (rev 0) +++ branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java 2009-10-25 02:51:54 UTC (rev 34219) @@ -0,0 +1,72 @@ +/* + * GeoTools - The Open Source Java GIS Toolkit + * http://geotools.org + * + * (C) 2002-2009, Open Source Geospatial Foundation (OSGeo) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ +package org.geotools.data.oracle; + +import static org.geotools.jdbc.JDBCDataStoreFactory.*; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.geotools.jdbc.JDBCDataStore; +import org.geotools.jdbc.JDBCTestSetup; +import org.geotools.jdbc.JDBCTestSupport; + +public class OracleNGDataStoreFactoryTest extends JDBCTestSupport { + + @Override + protected JDBCTestSetup createTestSetup() { + return new OracleTestSetup(); + } + + public void testCreateConnection() throws Exception { + OracleNGDataStoreFactory factory = new OracleNGDataStoreFactory(); + checkCreateConnection(factory, factory.getDatabaseID()); + } + + public void testCaptureOldDatastoreConfig() throws Exception { + OracleNGDataStoreFactory factory = new OracleNGDataStoreFactory(); + checkCreateConnection(factory, "oracle"); + } + + private void checkCreateConnection(OracleNGDataStoreFactory factory, String dbtype) throws IOException { + Properties db = new Properties(); + db.load(getClass().getResourceAsStream("factory.properties")); + 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(PASSWD.key)); + + params.put(DBTYPE.key, dbtype); + + assertTrue(factory.canProcess(params)); + JDBCDataStore store = factory.createDataStore(params); + assertNotNull(store); + try { + // check dialect + assertTrue(store.getSQLDialect() instanceof OracleDialect); + // force connection usage + assertNotNull(store.getSchema(tname("ft1"))); + } finally { + store.dispose(); + } + } + +} Property changes on: branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/java/org/geotools/data/oracle/OracleNGDataStoreFactoryTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Added: branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/resources/org/geotools/data/oracle/factory.properties =================================================================== --- branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/resources/org/geotools/data/oracle/factory.properties (rev 0) +++ branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/resources/org/geotools/data/oracle/factory.properties 2009-10-25 02:51:54 UTC (rev 34219) @@ -0,0 +1,7 @@ +driver=oracle.jdbc.driver.OracleDriver +host=192.168.1.200 +port=1521 +database=xe +user=geoserver +passwd=postgis +dbtype=Oracle Property changes on: branches/2.6.x/modules/plugin/jdbc/jdbc-oracle/src/test/resources/org/geotools/data/oracle/factory.properties ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Id Added: svn:eol-style + native Modified: branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGDataStoreFactory.java =================================================================== --- branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGDataStoreFactory.java 2009-10-25 02:51:42 UTC (rev 34218) +++ branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/main/java/org/geotools/data/postgis/PostgisNGDataStoreFactory.java 2009-10-25 02:51:54 UTC (rev 34219) @@ -27,7 +27,7 @@ public class PostgisNGDataStoreFactory extends JDBCDataStoreFactory { /** parameter for database type */ - public static final Param DBTYPE = new Param("dbtype", String.class, "Type", true, "postgisng"); + public static final Param DBTYPE = new Param("dbtype", String.class, "Type", true, "postgis"); /** 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); @@ -67,6 +67,27 @@ return "org.postgresql.Driver"; } + @Override + protected boolean checkDBType(Map params) { + if (super.checkDBType(params)) { + //check for old factory + try { + Class.forName("org.geotools.data.postgis.PostgisDataStoreFactory"); + + //old factory is around, let it handle the connection + return false; + } + catch(ClassNotFoundException e) { + //old factory is not around, handle this connection + return true; + } + } + else { + //check for postgisng as well + return checkDBType(params, "postgisng"); + } + } + protected JDBCDataStore createDataStoreInternal(JDBCDataStore dataStore, Map params) throws IOException { Modified: branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisNGDataStoreFactoryTest.java =================================================================== --- branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisNGDataStoreFactoryTest.java 2009-10-25 02:51:42 UTC (rev 34218) +++ branches/2.6.x/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisNGDataStoreFactoryTest.java 2009-10-25 02:51:54 UTC (rev 34219) @@ -23,6 +23,7 @@ import static org.geotools.jdbc.JDBCDataStoreFactory.PASSWD; import static org.geotools.jdbc.JDBCDataStoreFactory.USER; +import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -40,7 +41,15 @@ public void testCreateConnection() throws Exception { PostgisNGDataStoreFactory factory = new PostgisNGDataStoreFactory(); - + checkCreateConnection(factory, factory.getDatabaseID()); + } + + public void testCreateConnectionWithOldId() throws Exception { + PostgisNGDataStoreFactory factory = new PostgisNGDataStoreFactory(); + checkCreateConnection(factory, "postgis"); + } + + private void checkCreateConnection(PostgisNGDataStoreFactory factory, String dbtype) throws IOException { Properties db = new Properties(); db.load(getClass().getResourceAsStream("factory.properties")); Map<String, Object> params = new HashMap<String, Object>(); @@ -50,7 +59,7 @@ params.put(USER.key, db.getProperty(USER.key)); params.put(PASSWD.key, db.getProperty(PASSWD.key)); - params.put(DBTYPE.key, factory.getDatabaseID()); + params.put(DBTYPE.key, dbtype); assertTrue(factory.canProcess(params)); JDBCDataStore store = factory.createDataStore(params); ------------------------------------------------------------------------------ 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 |