svn - r33514 - in trunk/modules/plugin/arcsde/datastore/src: main/java/org/geotools/arcsde test/java/org/geotools/arcsde

1 message Options
Embed this post
Permalink
svn_geotools

svn - r33514 - in trunk/modules/plugin/arcsde/datastore/src: main/java/org/geotools/arcsde test/java/org/geotools/arcsde

Reply Threaded More More options
Print post
Permalink
Author: groldan
Date: 2009-07-07 13:07:40 -0400 (Tue, 07 Jul 2009)
New Revision: 33514

Modified:
   trunk/modules/plugin/arcsde/datastore/src/main/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactory.java
   trunk/modules/plugin/arcsde/datastore/src/test/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactoryTest.java
Log:
GEOT-2549, updated ArcSDEJNDIDataStoreFactoryTest

Modified: trunk/modules/plugin/arcsde/datastore/src/main/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactory.java
===================================================================
--- trunk/modules/plugin/arcsde/datastore/src/main/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactory.java 2009-07-07 16:58:07 UTC (rev 33513)
+++ trunk/modules/plugin/arcsde/datastore/src/main/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactory.java 2009-07-07 17:07:40 UTC (rev 33514)
@@ -28,7 +28,6 @@
 import java.util.logging.Logger;
 
 import javax.naming.Context;
-import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
 import org.geotools.arcsde.data.ArcSDEDataStore;
@@ -36,23 +35,23 @@
 import org.geotools.arcsde.jndi.ArcSDEConnectionFactory;
 import org.geotools.arcsde.session.ArcSDEConnectionConfig;
 import org.geotools.arcsde.session.ISessionPool;
-import org.geotools.arcsde.session.SessionPoolFactory;
 import org.geotools.data.DataSourceException;
 import org.geotools.data.DataStore;
 import org.geotools.data.DataStoreFactorySpi;
+import org.geotools.factory.GeoTools;
 import org.geotools.util.logging.Logging;
 
 /**
- * A GeoTools {@link DataStore} factory to access an ArcSDE database by grabbing either the
- * connection parameters or the connection pool from a JNDI reference.
+ * A GeoTools {@link DataStore} factory to access an ArcSDE database by grabbing the connection pool
+ * from a JNDI reference.
  * <p>
  * This DataStore factory expects the arcsde connection information to be given as a JNDI resource
  * path through the {@link #JNDI_REFNAME jndiRefName} parameter at {@link #createDataStore(Map)}.
  * The resource provided by the JNDI context at that location may be either:
  * <ul>
  * <li>a {@code java.util.Map<String, String>} with the connection parameters from
- * {@link ArcSDEConnectionConfig}</li>
- * <li>an {@link ArcSDEConnectionConfig} instance itself</li>
+ * {@link ArcSDEConnectionConfig}. If so, the {@link ISessionPool session pool} will be taken from
+ * {@link ArcSDEConnectionFactory#getInstance(Map)}</li>
  * <li>a {@link ISessionPool} instance</li>
  * </ul>
  * </p>
@@ -80,7 +79,7 @@
     public static final Param JNDI_REFNAME = new Param("jndiReferenceName", String.class,
             "JNDI context path", true, "java:comp/env/geotools/arcsde");
 
-    private static final String J2EERootContext = "java:comp/env/";
+    private static final String J2EE_ROOT_CONTEXT = "java:comp/env/";
 
     public ArcSDEJNDIDataStoreFactory() {
         this.delegateFactory = new ArcSDEDataStoreFactory();
@@ -128,14 +127,8 @@
 
         final ISessionPool sessionPool;
 
-        if (lookup instanceof ArcSDEConnectionConfig) {
+        if (lookup instanceof ISessionPool) {
 
-            LOGGER.info("Creating JNDI ArcSDE DataStore with own session pool for " + lookup);
-            final ArcSDEConnectionConfig connectionConfig = (ArcSDEConnectionConfig) lookup;
-            sessionPool = SessionPoolFactory.getInstance().createPool(connectionConfig);
-
-        } else if (lookup instanceof ISessionPool) {
-
             LOGGER.info("Creating JNDI ArcSDE DataStore with shared session pool for " + lookup);
             sessionPool = (ISessionPool) lookup;
 
@@ -182,8 +175,7 @@
         final Context ctx;
 
         try {
-            Context initialContext = new InitialContext();
-            ctx = (Context) initialContext.lookup("java:comp/env");
+            ctx = GeoTools.getInitialContext(GeoTools.getDefaultHints());
         } catch (NamingException e) {
             throw new RuntimeException(e);
         }
@@ -195,10 +187,10 @@
             // check if the user did not specify "java:comp/env"
             // and this code is running in a J2EE environment
             try {
-                if (jndiName.startsWith(J2EERootContext) == false) {
-                    lookup = ctx.lookup(J2EERootContext + jndiName);
+                if (jndiName.startsWith(J2EE_ROOT_CONTEXT) == false) {
+                    lookup = ctx.lookup(J2EE_ROOT_CONTEXT + jndiName);
                     // success --> issue a waring
-                    LOGGER.warning("Using " + J2EERootContext + jndiName + " instead of "
+                    LOGGER.warning("Using " + J2EE_ROOT_CONTEXT + jndiName + " instead of "
                             + jndiName + " would avoid an unnecessary JNDI lookup");
                 }
             } catch (NamingException e2) {
@@ -285,7 +277,7 @@
      */
     public boolean isAvailable() {
         try {
-            new InitialContext();
+            GeoTools.getInitialContext(GeoTools.getDefaultHints());
         } catch (NamingException e) {
             return false;
         }

Modified: trunk/modules/plugin/arcsde/datastore/src/test/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactoryTest.java
===================================================================
--- trunk/modules/plugin/arcsde/datastore/src/test/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactoryTest.java 2009-07-07 16:58:07 UTC (rev 33513)
+++ trunk/modules/plugin/arcsde/datastore/src/test/java/org/geotools/arcsde/ArcSDEJNDIDataStoreFactoryTest.java 2009-07-07 17:07:40 UTC (rev 33514)
@@ -1,5 +1,18 @@
-/**
- *
+/*
+ *    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.arcsde;
 
@@ -23,8 +36,8 @@
 
 import org.geotools.arcsde.data.ArcSDEDataStore;
 import org.geotools.arcsde.data.TestData;
-import org.geotools.arcsde.session.ArcSDEConnectionConfig;
 import org.geotools.arcsde.session.ISession;
+import org.geotools.arcsde.session.ISessionPool;
 import org.geotools.data.DataAccessFactory;
 import org.geotools.data.DataAccessFinder;
 import org.geotools.data.DataStoreFactorySpi;
@@ -37,8 +50,9 @@
 import org.junit.Test;
 
 /**
- * @author groldan
- *
+ * @author Gabriel Roldan (OpenGeo)
+ * @version $Id$
+ * @since 2.5.7
  */
 public class ArcSDEJNDIDataStoreFactoryTest {
 
@@ -94,15 +108,16 @@
      * @throws IOException
      */
     @Test
-    public void testCreateDataStore() throws IOException {
-        String jndiRef = "java:comp/env/MyArcSdeResource";
+    public void testCreateDataStore_MapParams() throws IOException {
+        String jndiRef = "MyArcSdeResource";
         Map<String, Serializable> params = new HashMap<String, Serializable>();
         params.put(ArcSDEJNDIDataStoreFactory.JNDI_REFNAME.key, jndiRef);
 
-        ArcSDEConnectionConfig config = testData.getConnectionPool().getConfig();
+        Map<String, String> config = testData.getConProps();
         try {
             InitialContext initialContext = GeoTools.getInitialContext(GeoTools.getDefaultHints());
-            initialContext.createSubcontext("java:comp/env").bind(jndiRef, config);
+            initialContext.bind(jndiRef, config);
+            assertNotNull(initialContext.lookup(jndiRef));
         } catch (NamingException e) {
             throw new RuntimeException(e);
         }
@@ -112,12 +127,34 @@
         ISession session = dataStore.getSession(Transaction.AUTO_COMMIT);
         assertNotNull(session);
         try {
-            assertEquals(config.getUserName().toUpperCase(), session.getUser().toUpperCase());
+            assertEquals(config.get("user").toUpperCase(), session.getUser().toUpperCase());
         } finally {
             session.dispose();
         }
     }
 
+    @Test
+    public void testCreateDataStore_SessionPool() throws IOException {
+        String jndiRef = "MyArcSdeResource_SessionPool";
+        Map<String, Serializable> params = new HashMap<String, Serializable>();
+        params.put(ArcSDEJNDIDataStoreFactory.JNDI_REFNAME.key, jndiRef);
+
+        ISessionPool pool = testData.getConnectionPool();
+        try {
+            InitialContext initialContext = GeoTools.getInitialContext(GeoTools.getDefaultHints());
+            initialContext.bind(jndiRef, pool);
+            assertNotNull(initialContext.lookup(jndiRef));
+        } catch (NamingException e) {
+            throw new RuntimeException(e);
+        }
+
+        ArcSDEDataStore dataStore = (ArcSDEDataStore) factory.createDataStore(params);
+        assertNotNull(dataStore);
+        ISession session = dataStore.getSession(Transaction.AUTO_COMMIT);
+        assertNotNull(session);
+        session.dispose();
+    }
+
     /**
      * Test method for {@link ArcSDEJNDIDataStoreFactory#canProcess(java.util.Map)}.
      */


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/blackberry
_______________________________________________
GeoTools-commits mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-commits