You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/04/29 19:19:41 UTC

svn commit: r1477209 - in /jena/Experimental/jena-jdbc: jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaDriver.java jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointDriver.java

Author: rvesse
Date: Mon Apr 29 17:19:41 2013
New Revision: 1477209

URL: http://svn.apache.org/r1477209
Log:
Improve how connection parameters that allow multiple values are handled

Modified:
    jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaDriver.java
    jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointDriver.java

Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaDriver.java?rev=1477209&r1=1477208&r2=1477209&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaDriver.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/main/java/org/apache/jena/jdbc/JenaDriver.java Mon Apr 29 17:19:41 2013
@@ -19,7 +19,6 @@
 package org.apache.jena.jdbc;
 
 import java.io.File;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.sql.Connection;
 import java.sql.Driver;
@@ -112,7 +111,7 @@ import org.slf4j.LoggerFactory;
  * </p>
  */
 public abstract class JenaDriver implements Driver {
-    
+
     private static final Logger LOGGER = LoggerFactory.getLogger(JenaDriver.class);
 
     /**
@@ -172,7 +171,7 @@ public abstract class JenaDriver impleme
     /**
      * Constant for the special value used with the {@link #PARAM_LOGGING}
      * parameter to indicate that the user code will manage configuration of
-     * logging.  This is also the default value when that parameter is not set.
+     * logging. This is also the default value when that parameter is not set.
      */
     public static final String NO_AUTO_LOGGING_CONFIGURATION = "no-auto";
 
@@ -228,8 +227,9 @@ public abstract class JenaDriver impleme
         if (logConfig == null || logConfig.trim().length() == 0) {
             logConfig = NO_AUTO_LOGGING_CONFIGURATION;
         }
-        
-        // Unless set to no configuration (which is the default attempt to configure)
+
+        // Unless set to no configuration (which is the default attempt to
+        // configure)
         if (!logConfig.equals(NO_AUTO_LOGGING_CONFIGURATION)) {
             // Search file system first
             File logConfigFile = new File(logConfig);
@@ -239,12 +239,12 @@ public abstract class JenaDriver impleme
             } else {
                 // Otherwise try class path
                 URL logURL = this.getClass().getResource(logConfig);
-                if (logURL != null)
-                {
+                if (logURL != null) {
                     PropertyConfigurator.configure(logURL);
                     LOGGER.info("Successfully configured logging using class path resource " + logConfig);
                 } else {
-                    throw new SQLException("Unable to locate the specified log4j configuration file on either the file system or the class path");
+                    throw new SQLException(
+                            "Unable to locate the specified log4j configuration file on either the file system or the class path");
                 }
             }
         }
@@ -369,9 +369,10 @@ public abstract class JenaDriver impleme
      * @param props
      *            Properties
      * @return Effective Properties
+     * @throws SQLException Thrown if the properties are invalid
      */
     @SuppressWarnings("unchecked")
-    private Properties getEffectiveProperties(String url, Properties props) {
+    private Properties getEffectiveProperties(String url, Properties props) throws SQLException {
         // Create new empty properties
         Properties ps = new Properties();
 
@@ -402,7 +403,15 @@ public abstract class JenaDriver impleme
                 // Doesn't yet exist, add a string/list as appropriate
                 if (this.allowsMultipleValues(key)) {
                     List<String> values = new ArrayList<String>();
-                    values.add(value);
+                    if (value.contains(",")) {
+                        // Comma separated lists are usable for multiple value properties
+                        String[] vs = value.split(",");
+                        for (String v : vs) {
+                            values.add(v);
+                        }
+                    } else {
+                        values.add(value);
+                    }
                     ps.put(key, values);
                 } else {
                     ps.put(key, value);
@@ -412,14 +421,31 @@ public abstract class JenaDriver impleme
                 Object currValue = ps.get(key);
                 if (currValue instanceof List<?>) {
                     // Can just append to existing list
-                    ((List<Object>) currValue).add(value);
+                    if (value.contains(",")) {
+                        // Comma separated lists are usable for multiple value properties
+                        String[] vs = value.split(",");
+                        for (String v : vs) {
+                            ((List<Object>) currValue).add(v);
+                        }
+                    } else {
+                        ((List<Object>) currValue).add(value);
+                    }
                 } else {
                     // Convert to list
                     List<String> values = new ArrayList<String>();
                     values.add(currValue.toString());
-                    values.add(value);
+                    if (value.contains(",")) {
+                        String[] vs = value.split(",");
+                        for (String v : vs) {
+                            values.add(v);
+                        }
+                    } else {
+                        values.add(value);
+                    }
                     ps.put(key, values);
                 }
+            } else {
+                throw new SQLException("Invalid connection URL parameter " + kvp + " encountered, the parameter " + key + " may only be specified once");
             }
         }
 

Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointDriver.java?rev=1477209&r1=1477208&r2=1477209&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointDriver.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TestRemoteEndpointDriver.java Mon Apr 29 17:19:41 2013
@@ -18,12 +18,18 @@
 
 package org.apache.jena.jdbc.remote;
 
+import java.sql.SQLException;
+import java.util.Properties;
+
 import org.apache.jena.jdbc.AbstractJenaDriverTests;
 import org.apache.jena.jdbc.JenaDriver;
+import org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
  * Tests for the {@link RemoteEndpointDriver}
- *
+ * 
  */
 public class TestRemoteEndpointDriver extends AbstractJenaDriverTests {
 
@@ -34,11 +40,57 @@ public class TestRemoteEndpointDriver ex
 
     @Override
     protected String getConnectionUrl() {
-        return JenaDriver.DRIVER_PREFIX + RemoteEndpointDriver.REMOTE_DRIVER_PREFIX + RemoteEndpointDriver.PARAM_QUERY_ENDPOINT + "=http://example.org/query&" + RemoteEndpointDriver.PARAM_UPDATE_ENDPOINT + "=http://example.org/update";
+        return JenaDriver.DRIVER_PREFIX + RemoteEndpointDriver.REMOTE_DRIVER_PREFIX + RemoteEndpointDriver.PARAM_QUERY_ENDPOINT
+                + "=http://example.org/query&" + RemoteEndpointDriver.PARAM_UPDATE_ENDPOINT + "=http://example.org/update";
     }
 
     @Override
     protected String getBadConnectionUrl() {
         return JenaDriver.DRIVER_PREFIX + RemoteEndpointDriver.REMOTE_DRIVER_PREFIX;
     }
+
+    /**
+     * Tests the different ways of specifying multiple values for a parameter
+     * @throws SQLException 
+     */
+    @Test
+    public void remote_driver_graph_uris_01() throws SQLException {
+        // May specify key=value pairs multiple times
+        String url = JenaDriver.DRIVER_PREFIX + RemoteEndpointDriver.REMOTE_DRIVER_PREFIX + RemoteEndpointDriver.PARAM_QUERY_ENDPOINT + "=http://example.org/query&" + RemoteEndpointDriver.PARAM_DEFAULT_GRAPH_URI + "=http://graph/1&" + RemoteEndpointDriver.PARAM_DEFAULT_GRAPH_URI + "=http://graph/2";
+        RemoteEndpointDriver driver = (RemoteEndpointDriver)this.getDriver();
+        RemoteEndpointConnection conn = (RemoteEndpointConnection) driver.connect(url, new Properties());
+        
+        Assert.assertEquals(2, conn.getDefaultGraphURIs().size());
+        conn.close();
+    }
+    
+    /**
+     * Tests the different ways of specifying multiple values for a parameter
+     * @throws SQLException 
+     */
+    @Test
+    public void remote_driver_graph_uris_02() throws SQLException {
+        // May specify key=value,value as comma separated list
+        String url = JenaDriver.DRIVER_PREFIX + RemoteEndpointDriver.REMOTE_DRIVER_PREFIX + RemoteEndpointDriver.PARAM_QUERY_ENDPOINT + "=http://example.org/query&" + RemoteEndpointDriver.PARAM_DEFAULT_GRAPH_URI + "=http://graph/1,http://graph/2";
+        RemoteEndpointDriver driver = (RemoteEndpointDriver)this.getDriver();
+        RemoteEndpointConnection conn = (RemoteEndpointConnection) driver.connect(url, new Properties());
+        
+        Assert.assertEquals(2, conn.getDefaultGraphURIs().size());
+        conn.close();
+    }
+    
+    /**
+     * Tests the different ways of specifying multiple values for a parameter
+     * @throws SQLException 
+     */
+    @Test
+    public void remote_driver_graph_uris_03() throws SQLException {
+        // May specify combination of multiple key=value pairs and key=value,value comma separated list(s)
+        String url = JenaDriver.DRIVER_PREFIX + RemoteEndpointDriver.REMOTE_DRIVER_PREFIX + RemoteEndpointDriver.PARAM_QUERY_ENDPOINT + "=http://example.org/query&" + RemoteEndpointDriver.PARAM_DEFAULT_GRAPH_URI + "=http://graph/1,http://graph/2&" + RemoteEndpointDriver.PARAM_DEFAULT_GRAPH_URI + "=http://graph/3";
+        RemoteEndpointDriver driver = (RemoteEndpointDriver)this.getDriver();
+        RemoteEndpointConnection conn = (RemoteEndpointConnection) driver.connect(url, new Properties());
+        
+        Assert.assertEquals(3, conn.getDefaultGraphURIs().size());
+        conn.close();
+    }
 }