jdk/src/java.sql/share/classes/java/sql/DriverManager.java
author serb
Tue, 29 Mar 2016 17:03:18 +0300
changeset 36787 402e5e40f6e5
parent 35302 e4d2275861c3
child 37363 329dba26ffd2
permissions -rw-r--r--
7179078: Remove @beaninfo processing from the makefiles Reviewed-by: erikj, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
     2
 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
    28
import java.util.ArrayList;
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
    29
import java.util.Collections;
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
    30
import java.util.Enumeration;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
    32
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.ServiceLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PrivilegedAction;
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    36
import java.util.concurrent.CopyOnWriteArrayList;
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
    37
import java.util.stream.Stream;
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
    38
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
    39
import sun.reflect.CallerSensitive;
12885
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
    40
import sun.reflect.Reflection;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <P>The basic service for managing a set of JDBC drivers.<br>
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 17199
diff changeset
    45
 * <B>NOTE:</B> The {@link javax.sql.DataSource} interface, new in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * JDBC 2.0 API, provides another way to connect to a data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The use of a <code>DataSource</code> object is the preferred means of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * connecting to a data source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <P>As part of its initialization, the <code>DriverManager</code> class will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * attempt to load the driver classes referenced in the "jdbc.drivers"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * system property. This allows a user to customize the JDBC Drivers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * used by their applications. For example in your
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * ~/.hotjava/properties file you might specify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <CODE>jdbc.drivers=foo.bah.Driver:wombat.sql.Driver:bad.taste.ourDriver</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *<P> The <code>DriverManager</code> methods <code>getConnection</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <code>getDrivers</code> have been enhanced to support the Java Standard Edition
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <a href="../../../technotes/guides/jar/jar.html#Service%20Provider">Service Provider</a> mechanism. JDBC 4.0 Drivers must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * include the file <code>META-INF/services/java.sql.Driver</code>. This file contains the name of the JDBC drivers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * implementation of <code>java.sql.Driver</code>.  For example, to load the <code>my.sql.Driver</code> class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * the <code>META-INF/services/java.sql.Driver</code> file would contain the entry:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>my.sql.Driver</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 19858
diff changeset
    68
 * <P>Applications no longer need to explicitly load JDBC drivers using <code>Class.forName()</code>. Existing programs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * which currently load JDBC drivers using <code>Class.forName()</code> will continue to work without
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * modification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <P>When the method <code>getConnection</code> is called,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * the <code>DriverManager</code> will attempt to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * locate a suitable driver from amongst those loaded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * initialization and those loaded explicitly using the same classloader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * as the current applet or application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Starting with the Java 2 SDK, Standard Edition, version 1.3, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * logging stream can be set only if the proper
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * permission has been granted.  Normally this will be done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * the tool PolicyTool, which can be used to grant <code>permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * java.sql.SQLPermission "setLog"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see Driver
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @see Connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public class DriverManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    90
    // List of registered JDBC drivers
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
    91
    private final static CopyOnWriteArrayList<DriverInfo> registeredDrivers = new CopyOnWriteArrayList<>();
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    92
    private static volatile int loginTimeout = 0;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    93
    private static volatile java.io.PrintWriter logWriter = null;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    94
    private static volatile java.io.PrintStream logStream = null;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
    95
    // Used in println() to synchronize logWriter
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
    96
    private final static Object logSync = new Object();
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
    97
    // Used in ensureDriversInitialized() to synchronize driversInitialized
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
    98
    private final static Object lockForInitDrivers = new Object();
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
    99
    private static volatile boolean driversInitialized;
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   100
    private static final String JDBC_DRIVERS_PROPERTY = "jdbc.drivers";
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   101
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   102
    /* Prevent the DriverManager class from being instantiated. */
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   103
    private DriverManager(){}
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   104
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * The <code>SQLPermission</code> constant that allows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * setting of the logging stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    final static SQLPermission SET_LOG_PERMISSION =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        new SQLPermission("setLog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   113
    /**
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   114
     * The {@code SQLPermission} constant that allows the
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   115
     * un-register a registered JDBC driver.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   116
     * @since 1.8
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   117
     */
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   118
    final static SQLPermission DEREGISTER_DRIVER_PERMISSION =
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   119
        new SQLPermission("deregisterDriver");
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   120
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    //--------------------------JDBC 2.0-----------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Retrieves the log writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * The <code>getLogWriter</code> and <code>setLogWriter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * methods should be used instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * of the <code>get/setlogStream</code> methods, which are deprecated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @return a <code>java.io.PrintWriter</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @see #setLogWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static java.io.PrintWriter getLogWriter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            return logWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Sets the logging/tracing <code>PrintWriter</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * that is used by the <code>DriverManager</code> and all drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * There is a minor versioning problem created by the introduction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * of the method <code>setLogWriter</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * method <code>setLogWriter</code> cannot create a <code>PrintStream</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * that will be returned by <code>getLogStream</code>---the Java platform does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * not provide a backward conversion.  As a result, a new application
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * that uses <code>setLogWriter</code> and also uses a JDBC 1.0 driver that uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <code>getLogStream</code> will likely not see debugging information written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * by that driver.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Starting with the Java 2 SDK, Standard Edition, version 1.3 release, this method checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * to see that there is an <code>SQLPermission</code> object before setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * the logging stream.  If a <code>SecurityManager</code> exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <code>checkPermission</code> method denies setting the log writer, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * method throws a <code>java.lang.SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param out the new logging/tracing <code>PrintStream</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *      <code>null</code> to disable logging and tracing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *    if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *    <code>checkPermission</code> method denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *    setting the log writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see #getLogWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public static void setLogWriter(java.io.PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        SecurityManager sec = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (sec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            sec.checkPermission(SET_LOG_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            logStream = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            logWriter = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    //---------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Attempts to establish a connection to the given database URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * the set of registered JDBC drivers.
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   184
     *<p>
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   185
     * <B>Note:</B> If a property is specified as part of the {@code url} and
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   186
     * is also specified in the {@code Properties} object, it is
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   187
     * implementation-defined as to which value will take precedence.
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   188
     * For maximum portability, an application should only specify a
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   189
     * property once.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param url a database url of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param info a list of arbitrary string tag/value pairs as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * connection arguments; normally at least a "user" and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * "password" property should be included
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @return a Connection to the URL
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   197
     * @exception SQLException if a database access error occurs or the url is
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   198
     * {@code null}
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   199
     * @throws SQLTimeoutException  when the driver has determined that the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   200
     * timeout value specified by the {@code setLoginTimeout} method
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   201
     * has been exceeded and has at least tried to cancel the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   202
     * current database connection attempt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   204
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public static Connection getConnection(String url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        java.util.Properties info) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   208
        return (getConnection(url, info, Reflection.getCallerClass()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Attempts to establish a connection to the given database URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * the set of registered JDBC drivers.
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   215
     *<p>
21950
db3c826749f7 8029417: JDBC 4.2 javadoc updates
lancea
parents: 21278
diff changeset
   216
     * <B>Note:</B> If the {@code user} or {@code password} property are
db3c826749f7 8029417: JDBC 4.2 javadoc updates
lancea
parents: 21278
diff changeset
   217
     * also specified as part of the {@code url}, it is
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   218
     * implementation-defined as to which value will take precedence.
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   219
     * For maximum portability, an application should only specify a
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   220
     * property once.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param url a database url of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param user the database user on whose behalf the connection is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *   made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param password the user's password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return a connection to the URL
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   228
     * @exception SQLException if a database access error occurs or the url is
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   229
     * {@code null}
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   230
     * @throws SQLTimeoutException  when the driver has determined that the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   231
     * timeout value specified by the {@code setLoginTimeout} method
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   232
     * has been exceeded and has at least tried to cancel the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   233
     * current database connection attempt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   235
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public static Connection getConnection(String url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        String user, String password) throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        java.util.Properties info = new java.util.Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (user != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            info.put("user", user);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (password != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            info.put("password", password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   247
        return (getConnection(url, info, Reflection.getCallerClass()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Attempts to establish a connection to the given database URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * the set of registered JDBC drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param url a database url of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *  <code> jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @return a connection to the URL
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   258
     * @exception SQLException if a database access error occurs or the url is
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   259
     * {@code null}
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   260
     * @throws SQLTimeoutException  when the driver has determined that the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   261
     * timeout value specified by the {@code setLoginTimeout} method
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   262
     * has been exceeded and has at least tried to cancel the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   263
     * current database connection attempt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   265
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public static Connection getConnection(String url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        java.util.Properties info = new java.util.Properties();
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   270
        return (getConnection(url, info, Reflection.getCallerClass()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Attempts to locate a driver that understands the given URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * The <code>DriverManager</code> attempts to select an appropriate driver from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * the set of registered JDBC drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param url a database URL of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *     <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return a <code>Driver</code> object representing a driver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * that can connect to the given URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @exception SQLException if a database access error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   284
    @CallerSensitive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public static Driver getDriver(String url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        throws SQLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        println("DriverManager.getDriver(\"" + url + "\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   290
        ensureDriversInitialized();
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   291
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   292
        Class<?> callerClass = Reflection.getCallerClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   294
        // Walk through the loaded registeredDrivers attempting to locate someone
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        // who understands the given URL.
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   296
        for (DriverInfo aDriver : registeredDrivers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            // If the caller does not have permission to load the driver then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            // skip it.
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   299
            if (isDriverAllowed(aDriver.driver, callerClass)) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   300
                try {
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   301
                    if (aDriver.driver.acceptsURL(url)) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   302
                        // Success!
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   303
                        println("getDriver returning " + aDriver.driver.getClass().getName());
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   304
                    return (aDriver.driver);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   305
                    }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   306
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   307
                } catch(SQLException sqe) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   308
                    // Drop through and try the next driver.
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   309
                }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   310
            } else {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   311
                println("    skipping: " + aDriver.driver.getClass().getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   313
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        println("getDriver: no suitable driver");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        throw new SQLException("No suitable driver", "08001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   322
     * Registers the given driver with the {@code DriverManager}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * A newly-loaded driver class should call
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   324
     * the method {@code registerDriver} to make itself
21950
db3c826749f7 8029417: JDBC 4.2 javadoc updates
lancea
parents: 21278
diff changeset
   325
     * known to the {@code DriverManager}. If the driver is currently
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   326
     * registered, no action is taken.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @param driver the new JDBC Driver that is to be registered with the
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   329
     *               {@code DriverManager}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @exception SQLException if a database access error occurs
19858
7c37f6ac403b 8014967: EBehavior of DriverManager.registerDriver(dr) is unspecified if driver is null
lancea
parents: 18156
diff changeset
   331
     * @exception NullPointerException if {@code driver} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   333
    public static void registerDriver(java.sql.Driver driver)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        throws SQLException {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   335
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   336
        registerDriver(driver, null);
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   337
    }
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   338
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   339
    /**
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   340
     * Registers the given driver with the {@code DriverManager}.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   341
     * A newly-loaded driver class should call
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   342
     * the method {@code registerDriver} to make itself
21950
db3c826749f7 8029417: JDBC 4.2 javadoc updates
lancea
parents: 21278
diff changeset
   343
     * known to the {@code DriverManager}. If the driver is currently
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   344
     * registered, no action is taken.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   345
     *
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   346
     * @param driver the new JDBC Driver that is to be registered with the
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   347
     *               {@code DriverManager}
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   348
     * @param da     the {@code DriverAction} implementation to be used when
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   349
     *               {@code DriverManager#deregisterDriver} is called
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   350
     * @exception SQLException if a database access error occurs
19858
7c37f6ac403b 8014967: EBehavior of DriverManager.registerDriver(dr) is unspecified if driver is null
lancea
parents: 18156
diff changeset
   351
     * @exception NullPointerException if {@code driver} is null
21950
db3c826749f7 8029417: JDBC 4.2 javadoc updates
lancea
parents: 21278
diff changeset
   352
     * @since 1.8
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   353
     */
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   354
    public static void registerDriver(java.sql.Driver driver,
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   355
            DriverAction da)
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   356
        throws SQLException {
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   357
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   358
        /* Register the driver if it has not already been added to our list */
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   359
        if (driver != null) {
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   360
            registeredDrivers.addIfAbsent(new DriverInfo(driver, da));
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   361
        } else {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   362
            // This is for compatibility with the original DriverManager
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   363
            throw new NullPointerException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   366
        println("registerDriver: " + driver);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   371
     * Removes the specified driver from the {@code DriverManager}'s list of
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   372
     * registered drivers.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   373
     * <p>
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   374
     * If a {@code null} value is specified for the driver to be removed, then no
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   375
     * action is taken.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   376
     * <p>
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   377
     * If a security manager exists and its {@code checkPermission} denies
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   378
     * permission, then a {@code SecurityException} will be thrown.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   379
     * <p>
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   380
     * If the specified driver is not found in the list of registered drivers,
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   381
     * then no action is taken.  If the driver was found, it will be removed
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   382
     * from the list of registered drivers.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   383
     * <p>
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   384
     * If a {@code DriverAction} instance was specified when the JDBC driver was
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   385
     * registered, its deregister method will be called
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   386
     * prior to the driver being removed from the list of registered drivers.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   388
     * @param driver the JDBC Driver to remove
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @exception SQLException if a database access error occurs
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   390
     * @throws SecurityException if a security manager exists and its
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   391
     * {@code checkPermission} method denies permission to deregister a driver.
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   392
     *
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   393
     * @see SecurityManager#checkPermission
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   395
    @CallerSensitive
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   396
    public static void deregisterDriver(Driver driver) throws SQLException {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   397
        if (driver == null) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   398
            return;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   399
        }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   400
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   401
        SecurityManager sec = System.getSecurityManager();
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   402
        if (sec != null) {
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   403
            sec.checkPermission(DEREGISTER_DRIVER_PERMISSION);
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   404
        }
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   405
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        println("DriverManager.deregisterDriver: " + driver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   408
        DriverInfo aDriver = new DriverInfo(driver, null);
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   409
        synchronized (lockForInitDrivers) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   410
            if (registeredDrivers.contains(aDriver)) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   411
                if (isDriverAllowed(driver, Reflection.getCallerClass())) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   412
                    DriverInfo di = registeredDrivers.get(registeredDrivers.indexOf(aDriver));
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   413
                     // If a DriverAction was specified, Call it to notify the
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   414
                     // driver that it has been deregistered
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   415
                     if (di.action() != null) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   416
                         di.action().deregister();
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   417
                     }
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   418
                     registeredDrivers.remove(aDriver);
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   419
                } else {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   420
                    // If the caller does not have permission to load the driver then
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   421
                    // throw a SecurityException.
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   422
                    throw new SecurityException();
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   423
                }
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   424
            } else {
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   425
                println("    couldn't find driver to unload");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * Retrieves an Enumeration with all of the currently loaded JDBC drivers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * to which the current caller has access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * <P><B>Note:</B> The classname of a driver can be found using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * <CODE>d.getClass().getName()</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @return the list of JDBC Drivers loaded by the caller's class loader
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   438
     * @see #drivers()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   440
    @CallerSensitive
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   441
    public static Enumeration<Driver> getDrivers() {
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   442
        ensureDriversInitialized();
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   443
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   444
        return Collections.enumeration(getDrivers(Reflection.getCallerClass()));
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   445
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   447
    /**
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   448
     * Retrieves a Stream with all of the currently loaded JDBC drivers
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   449
     * to which the current caller has access.
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   450
     *
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   451
     * @return the stream of JDBC Drivers loaded by the caller's class loader
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 31469
diff changeset
   452
     * @since 9
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   453
     */
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   454
    @CallerSensitive
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   455
    public static Stream<Driver> drivers() {
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   456
        ensureDriversInitialized();
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   457
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   458
        return getDrivers(Reflection.getCallerClass()).stream();
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   459
    }
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   460
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   461
    private static List<Driver> getDrivers(Class<?> callerClass) {
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   462
        List<Driver> result = new ArrayList<>();
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   463
        // Walk through the loaded registeredDrivers.
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   464
        for (DriverInfo aDriver : registeredDrivers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            // If the caller does not have permission to load the driver then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            // skip it.
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   467
            if (isDriverAllowed(aDriver.driver, callerClass)) {
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   468
                result.add(aDriver.driver);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   469
            } else {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   470
                println("    skipping: " + aDriver.getClass().getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
31469
92cc72d2a11a 8081678: Add Stream returning methods to classes where there currently exist only Enumeration returning methods
psandoz
parents: 28117
diff changeset
   473
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Sets the maximum time in seconds that a driver will wait
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   478
     * while attempting to connect to a database once the driver has
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 14174
diff changeset
   479
     * been identified.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @param seconds the login time limit in seconds; zero means there is no limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @see #getLoginTimeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public static void setLoginTimeout(int seconds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        loginTimeout = seconds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Gets the maximum time in seconds that a driver can wait
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * when attempting to log in to a database.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @return the driver login time limit in seconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @see #setLoginTimeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public static int getLoginTimeout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return (loginTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Sets the logging/tracing PrintStream that is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * by the <code>DriverManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * and all drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *<P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * In the Java 2 SDK, Standard Edition, version 1.3 release, this method checks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * to see that there is an <code>SQLPermission</code> object before setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * the logging stream.  If a <code>SecurityManager</code> exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * <code>checkPermission</code> method denies setting the log writer, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * method throws a <code>java.lang.SecurityException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @param out the new logging/tracing PrintStream; to disable, set to <code>null</code>
14174
74a7d8795c22 8000687: Correct javadoc typo for getLogWriter and setLogWriter
lancea
parents: 14171
diff changeset
   511
     * @deprecated Use {@code setLogWriter}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @throws SecurityException if a security manager exists and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *    <code>checkPermission</code> method denies setting the log stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @see SecurityManager#checkPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @see #getLogStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
14171
94eb36844bd7 7197395: Add @Deprecated to all deprecated methods to eliminate compiler warnings in JDBC
lancea
parents: 13660
diff changeset
   518
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public static void setLogStream(java.io.PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        SecurityManager sec = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (sec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            sec.checkPermission(SET_LOG_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        logStream = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if ( out != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            logWriter = new java.io.PrintWriter(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            logWriter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Retrieves the logging/tracing PrintStream that is used by the <code>DriverManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * and all drivers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @return the logging/tracing PrintStream; if disabled, is <code>null</code>
14174
74a7d8795c22 8000687: Correct javadoc typo for getLogWriter and setLogWriter
lancea
parents: 14171
diff changeset
   538
     * @deprecated  Use {@code getLogWriter}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see #setLogStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
14171
94eb36844bd7 7197395: Add @Deprecated to all deprecated methods to eliminate compiler warnings in JDBC
lancea
parents: 13660
diff changeset
   541
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public static java.io.PrintStream getLogStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return logStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * Prints a message to the current JDBC log stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @param message a log or tracing message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public static void println(String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        synchronized (logSync) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if (logWriter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                logWriter.println(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                // automatic flushing is never enabled, so we must do it ourselves
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                logWriter.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   564
    // Indicates whether the class object that would be created if the code calling
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   565
    // DriverManager is accessible.
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   566
    private static boolean isDriverAllowed(Driver driver, Class<?> caller) {
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   567
        ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   568
        return isDriverAllowed(driver, callerCL);
12885
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   569
    }
30a5ef357cf1 7172551: Remove Native calls from DriverManager for jigsaw
lancea
parents: 11129
diff changeset
   570
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   571
    private static boolean isDriverAllowed(Driver driver, ClassLoader classLoader) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   572
        boolean result = false;
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   573
        if (driver != null) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   574
            Class<?> aClass = null;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   575
            try {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   576
                aClass =  Class.forName(driver.getClass().getName(), true, classLoader);
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   577
            } catch (Exception ex) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   578
                result = false;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   579
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   581
             result = ( aClass == driver.getClass() ) ? true : false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   584
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   587
    /*
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   588
     * Load the initial JDBC drivers by checking the System property
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   589
     * jdbc.drivers and then use the {@code ServiceLoader} mechanism
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   590
     */
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   591
    private static void ensureDriversInitialized() {
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   592
        if (driversInitialized) {
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   593
            return;
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   594
        }
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   595
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   596
        synchronized (lockForInitDrivers) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   597
            if (driversInitialized) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   598
                return;
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   599
            }
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   600
            String drivers;
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   601
            try {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   602
                drivers = AccessController.doPrivileged(new PrivilegedAction<String>() {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   603
                    public String run() {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   604
                        return System.getProperty(JDBC_DRIVERS_PROPERTY);
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   605
                    }
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   606
                });
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   607
            } catch (Exception ex) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   608
                drivers = null;
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   609
            }
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   610
            // If the driver is packaged as a Service Provider, load it.
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   611
            // Get all the drivers through the classloader
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   612
            // exposed as a java.sql.Driver.class service.
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   613
            // ServiceLoader.load() replaces the sun.misc.Providers()
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   614
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   615
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   616
                public Void run() {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   617
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   618
                    ServiceLoader<Driver> loadedDrivers = ServiceLoader.load(Driver.class);
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   619
                    Iterator<Driver> driversIterator = loadedDrivers.iterator();
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   620
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   621
                    /* Load these drivers, so that they can be instantiated.
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   622
                     * It may be the case that the driver class may not be there
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   623
                     * i.e. there may be a packaged driver with the service class
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   624
                     * as implementation of java.sql.Driver but the actual class
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   625
                     * may be missing. In that case a java.util.ServiceConfigurationError
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   626
                     * will be thrown at runtime by the VM trying to locate
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   627
                     * and load the service.
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   628
                     *
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   629
                     * Adding a try catch block to catch those runtime errors
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   630
                     * if driver not available in classpath but it's
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   631
                     * packaged as service and that service is there in classpath.
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   632
                     */
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   633
                    try {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   634
                        while (driversIterator.hasNext()) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   635
                            driversIterator.next();
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   636
                        }
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   637
                    } catch (Throwable t) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   638
                        // Do nothing
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   639
                    }
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   640
                    return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   644
            println("DriverManager.initialize: jdbc.drivers = " + drivers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   646
            if (drivers != null && !drivers.equals("")) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   647
                String[] driversList = drivers.split(":");
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   648
                println("number of Drivers:" + driversList.length);
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   649
                for (String aDriver : driversList) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   650
                    try {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   651
                        println("DriverManager.Initialize: loading " + aDriver);
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   652
                        Class.forName(aDriver, true,
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   653
                                ClassLoader.getSystemClassLoader());
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   654
                    } catch (Exception ex) {
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   655
                        println("DriverManager.Initialize: load failed: " + ex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   660
            driversInitialized = true;
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   661
            println("JDBC DriverManager initialized");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    //  Worker method called by the public getConnection() methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    private static Connection getConnection(
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   668
        String url, java.util.Properties info, Class<?> caller) throws SQLException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
         * When callerCl is null, we should check the application's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
         * (which is invoking this class indirectly)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
         * classloader, so that the JDBC driver class outside rt.jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
         * can be loaded from here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
         */
16906
44dfee24cb71 8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents: 16887
diff changeset
   675
        ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   676
        if (callerCL == null) {
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   677
            callerCL = Thread.currentThread().getContextClassLoader();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   680
        if (url == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            throw new SQLException("The url cannot be null", "08001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        println("DriverManager.getConnection(\"" + url + "\")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   686
        ensureDriversInitialized();
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   687
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   688
        // Walk through the loaded registeredDrivers attempting to make a connection.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // Remember the first exception that gets raised so we can reraise it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        SQLException reason = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
28117
8da4af46db02 8067904: Additional DriverManager clean-up from 8060068
lancea
parents: 27801
diff changeset
   692
        for (DriverInfo aDriver : registeredDrivers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            // If the caller does not have permission to load the driver then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            // skip it.
27801
2b1b7e235693 8060068: Possible Deadlock scenario with DriverManager.loadInitialDrivers
lancea
parents: 25859
diff changeset
   695
            if (isDriverAllowed(aDriver.driver, callerCL)) {
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   696
                try {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   697
                    println("    trying " + aDriver.driver.getClass().getName());
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   698
                    Connection con = aDriver.driver.connect(url, info);
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   699
                    if (con != null) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   700
                        // Success!
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   701
                        println("getConnection returning " + aDriver.driver.getClass().getName());
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   702
                        return (con);
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   703
                    }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   704
                } catch (SQLException ex) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   705
                    if (reason == null) {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   706
                        reason = ex;
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   707
                    }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   708
                }
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   709
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   710
            } else {
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   711
                println("    skipping: " + aDriver.getClass().getName());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
8797
e8507464a69d 7026898: DriverManager to now use CopyOnWriteArrayList
lancea
parents: 7803
diff changeset
   713
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        // if we got here nobody could connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (reason != null)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            println("getConnection failed: " + reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            throw reason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        println("getConnection: no suitable driver found for "+ url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        throw new SQLException("No suitable driver found for "+ url, "08001");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
}
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   728
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   729
/*
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   730
 * Wrapper class for registered Drivers in order to not expose Driver.equals()
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   731
 * to avoid the capture of the Driver it being compared to as it might not
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   732
 * normally have access.
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   733
 */
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   734
class DriverInfo {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   735
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   736
    final Driver driver;
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   737
    DriverAction da;
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   738
    DriverInfo(Driver driver, DriverAction action) {
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   739
        this.driver = driver;
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   740
        da = action;
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   741
    }
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   742
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
   743
    @Override
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   744
    public boolean equals(Object other) {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   745
        return (other instanceof DriverInfo)
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   746
                && this.driver == ((DriverInfo) other).driver;
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   747
    }
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   748
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
   749
    @Override
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   750
    public int hashCode() {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   751
        return driver.hashCode();
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   752
    }
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   753
11129
f9ad1aadf3fa 7116445: Miscellaneous warnings in the JDBC/RowSet classes
lancea
parents: 9243
diff changeset
   754
    @Override
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   755
    public String toString() {
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   756
        return ("driver[className="  + driver + "]");
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   757
    }
17199
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   758
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   759
    DriverAction action() {
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   760
        return da;
28853592ce2b 8010416: Add a way for java.sql.Driver to be notified when it is deregistered
lancea
parents: 16906
diff changeset
   761
    }
9239
f4bedba1a211 7034471: Wrap registeredDrivers in DriverManager
lancea
parents: 8797
diff changeset
   762
}