changeset 51972:67619141f027

8211295: DriverManager.getConnection fails when called from com.sun.rowset.JdbcRowSetImpl Reviewed-by: mchung, alanb
author lancea
date Mon, 01 Oct 2018 13:05:51 -0400
parents 26810c5fe290
children 2f1698b6db15
files src/java.sql/share/classes/java/sql/DriverManager.java test/jdk/java/sql/testng/util/StubConnection.java test/jdk/javax/sql/testng/test/rowset/jdbcrowset/JdbcRowSetDriverManagerTest.java
diffstat 3 files changed, 85 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.sql/share/classes/java/sql/DriverManager.java	Mon Oct 01 12:30:33 2018 -0400
+++ b/src/java.sql/share/classes/java/sql/DriverManager.java	Mon Oct 01 13:05:51 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -652,7 +652,7 @@
          * can be loaded from here.
          */
         ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;
-        if (callerCL == null) {
+        if (callerCL == null || callerCL == ClassLoader.getPlatformClassLoader()) {
             callerCL = Thread.currentThread().getContextClassLoader();
         }
 
--- a/test/jdk/java/sql/testng/util/StubConnection.java	Mon Oct 01 12:30:33 2018 -0400
+++ b/test/jdk/java/sql/testng/util/StubConnection.java	Mon Oct 01 13:05:51 2018 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,8 @@
 
 public class StubConnection implements Connection {
 
+    private boolean autoCommit = false;
+
     @Override
     public Statement createStatement() throws SQLException {
         throw new UnsupportedOperationException("Not supported yet.");
@@ -65,12 +67,14 @@
 
     @Override
     public void setAutoCommit(boolean autoCommit) throws SQLException {
-        throw new UnsupportedOperationException("Not supported yet.");
+        System.out.println("**** in StubConnection.setAutoCommit");
+        this.autoCommit = autoCommit;
     }
 
     @Override
     public boolean getAutoCommit() throws SQLException {
-        throw new UnsupportedOperationException("Not supported yet.");
+        System.out.println("*** in StubConnection.getAutoCommit");
+        return autoCommit;
     }
 
     @Override
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sql/testng/test/rowset/jdbcrowset/JdbcRowSetDriverManagerTest.java	Mon Oct 01 13:05:51 2018 -0400
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code 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 General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package test.rowset.jdbcrowset;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import javax.sql.rowset.JdbcRowSet;
+import javax.sql.rowset.RowSetFactory;
+import javax.sql.rowset.RowSetProvider;
+import org.testng.annotations.Test;
+import util.BaseTest;
+import util.StubDriver;
+
+public class JdbcRowSetDriverManagerTest extends BaseTest {
+
+    // URL that the StubDriver recognizes
+    private final static String StubDriverURL = "jdbc:tennis:boy";
+
+    /**
+     * Validate that JDBCRowSetImpl can connect to a JDBC driver that is
+     * register by DriverManager.
+     */
+    @Test(enabled = true)
+    public void test0000() throws SQLException {
+
+        DriverManager.registerDriver(new StubDriver());
+
+        // Show that the StubDriver is loaded and then call setAutoCommit on
+        // the returned Connection
+        dumpRegisteredDrivers();
+        Connection con = DriverManager.getConnection(StubDriverURL, "userid", "password");
+        con.setAutoCommit(true);
+
+        // Have com.sun.rowset.JdbcRowSetImpl create a Connection and
+        // then call setAutoCommit
+        RowSetFactory rsf = RowSetProvider.newFactory();
+        JdbcRowSet jrs = rsf.createJdbcRowSet();
+        jrs.setUrl(StubDriverURL);
+        jrs.setUsername("userid");
+        jrs.setPassword("password");
+
+        jrs.setAutoCommit(true);
+    }
+
+    private static void dumpRegisteredDrivers() {
+        System.out.println("+++ Loaded Drivers +++");
+        System.out.println("++++++++++++++++++++++++");
+        DriverManager.drivers()
+                .forEach(d
+                        -> System.out.println("+++ Driver:" + d + " "
+                        + d.getClass().getClassLoader()));
+        System.out.println("++++++++++++++++++++++++");
+
+    }
+}