svn - r34247 - trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2

1 message Options
Embed this post
Permalink
svn_geotools

svn - r34247 - trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2

Reply Threaded More More options
Print post
Permalink
Author: jdeolive
Date: 2009-10-26 04:25:25 -0400 (Mon, 26 Oct 2009)
New Revision: 34247

Modified:
   trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DataStoreFactory.java
Log:
GEOT-2802, allowing username and password to be set via datastore parameters

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 2009-10-26 08:21:32 UTC (rev 34246)
+++ trunk/modules/plugin/jdbc/jdbc-h2/src/main/java/org/geotools/data/h2/H2DataStoreFactory.java 2009-10-26 08:25:25 UTC (rev 34247)
@@ -47,6 +47,10 @@
     public static final Param ASSOCIATIONS = new Param("Associations", Boolean.class,
             "Associations", false, Boolean.FALSE);
 
+    /** optional user parameter */
+    public static final Param USER = new Param(JDBCDataStoreFactory.USER.key, JDBCDataStoreFactory.USER.type,
+            JDBCDataStoreFactory.USER.description, false, JDBCDataStoreFactory.USER.sample);
+    
     /**
      * base location to store h2 database files
      */
@@ -74,10 +78,16 @@
         //remove unneccessary parameters
         parameters.remove(HOST.key);
         parameters.remove(PORT.key);
-        parameters.remove(SCHEMA.key);
-        parameters.remove(USER.key);
+        
+        //remove user and password temporarily in order to make username optional
+        parameters.remove(JDBCDataStoreFactory.USER.key);
         parameters.remove(PASSWD.key);
-
+        
+        
+        parameters.put(USER.key, USER);
+        parameters.put(PASSWD.key, PASSWD);
+        
+        //add user
         //add additional parameters
         parameters.put(ASSOCIATIONS.key, ASSOCIATIONS);
         parameters.put(DBTYPE.key, DBTYPE);
@@ -116,7 +126,16 @@
             String location = new File(baseDirectory, database).getAbsolutePath();
             dataSource.setUrl("jdbc:h2:file:" + location);
         }
-
+        
+        String username = (String) USER.lookUp(params);
+        if (username != null) {
+            dataSource.setUsername(username);
+        }
+        String password = (String) PASSWD.lookUp(params);
+        if (password != null) {
+            dataSource.setPassword(password);
+        }
+        
         dataSource.setDriverClassName("org.h2.Driver");
         dataSource.setPoolPreparedStatements(false);
 


------------------------------------------------------------------------------
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