commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1711371 - in /commons/proper/dbcp/trunk/src: changes/ main/java/org/apache/commons/dbcp2/ test/java/org/apache/commons/dbcp2/
Date Thu, 29 Oct 2015 22:00:04 GMT
Author: ggregory
Date: Thu Oct 29 22:00:04 2015
New Revision: 1711371

URL: http://svn.apache.org/viewvc?rev=1711371&view=rev
Log:
[DBCP-451] Add constructor DriverManagerConnectionFactory(String).

Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterDriver.java

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1711371&r1=1711370&r2=1711371&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Thu Oct 29 22:00:04 2015
@@ -67,6 +67,9 @@ The <action> type attribute can be add,u
       <action dev="ggregory" type="fix" issue="DBCP-449" due-to="Grzegorz D.">
         Cannot use DBCP on Google App Engine.
       </action>
+      <action dev="ggregory" type="add" issue="DBCP-451">
+        Add constructor DriverManagerConnectionFactory(String).
+      </action>
     </release>
     <release version="2.1.1" date="6 Aug 2015" description=
 "This is a patch release, including bug fixes only.">

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java?rev=1711371&r1=1711370&r2=1711371&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
(original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DriverManagerConnectionFactory.java
Thu Oct 29 22:00:04 2015
@@ -46,6 +46,17 @@ public class DriverManagerConnectionFact
      * Constructor for DriverManagerConnectionFactory.
      * @param connectUri a database url of the form
      * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
+     * @since 2.1.2
+     */
+    public DriverManagerConnectionFactory(String connectUri) {
+        _connectUri = connectUri;
+        _props = new Properties();
+    }
+
+    /**
+     * Constructor for DriverManagerConnectionFactory.
+     * @param connectUri a database url of the form
+     * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
      * @param props a list of arbitrary string tag/value pairs as
      * connection arguments; normally at least a "user" and "password"
      * property should be included.

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java?rev=1711371&r1=1711370&r2=1711371&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
(original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
Thu Oct 29 22:00:04 2015
@@ -26,6 +26,8 @@ import javax.sql.DataSource;
 
 import org.apache.commons.pool2.impl.GenericObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -37,6 +39,25 @@ import org.junit.Test;
  */
 public class TestDriverManagerConnectionFactory {
 
+    private static final String KEY_JDBC_DRIVERS = "jdbc.drivers";
+
+    @BeforeClass 
+    public static void beforeClass() {
+        System.setProperty(KEY_JDBC_DRIVERS, "org.apache.commons.dbcp2.TesterDriver");
+    }
+    
+    @AfterClass
+    public static void afterClass() {
+        System.clearProperty(KEY_JDBC_DRIVERS);
+    }
+    
+    @Test
+    public void testDriverManagerInitWithEmptyProperties() throws Exception {
+        final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
+                "jdbc:apache:commons:testdriver;user=foo;password=bar");
+        connectionFactory.createConnection();
+    }
+
     @Test
     public void testDriverManagerInitWithProperties() throws Exception {
         testDriverManagerInit(true);
@@ -48,8 +69,6 @@ public class TestDriverManagerConnection
     }
 
     public void testDriverManagerInit(final boolean withProperties) throws Exception {
-        System.setProperty("jdbc.drivers",
-                "org.apache.commons.dbcp2.TesterDriver");
         GenericObjectPoolConfig config = new GenericObjectPoolConfig();
         config.setMaxTotal(10);
         config.setMaxIdle(0);

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterDriver.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterDriver.java?rev=1711371&r1=1711370&r2=1711371&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterDriver.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterDriver.java Thu
Oct 29 22:00:04 2015
@@ -67,7 +67,7 @@ public class TesterDriver implements Dri
 
     @Override
     public boolean acceptsURL(String url) throws SQLException {
-        return CONNECT_STRING.startsWith(url);
+        return url != null && url.startsWith(CONNECT_STRING);
     }
 
     private void assertValidUserPassword(String user, String password) 
@@ -99,6 +99,13 @@ public class TesterDriver implements Dri
             {
                 username = info.getProperty("user");
                 password = info.getProperty("password");
+                if (username == null) {
+                    String[] parts = url.split(";");
+                    username = parts[1];
+                    username = username.split("=")[1];
+                    password = parts[2];
+                    password = password.split("=")[1];
+                }
                 assertValidUserPassword(username, password);
             }
             conn = new TesterConnection(username, password);



Mime
View raw message