src/java.sql/share/classes/javax/sql/DataSource.java
author darcy
Thu, 01 Nov 2018 20:37:45 -0700
changeset 52380 6b31efbf833e
parent 47216 71c04702a3d5
permissions -rw-r--r--
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods Reviewed-by: vromero, plevart, briangoetz, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
35277
eb4794f43d20 8146803: Enhance and update Sharding API
lancea
parents: 34338
diff changeset
     2
 * Copyright (c) 2000, 2016, 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 javax.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.sql.Connection;
34338
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
    29
import java.sql.ConnectionBuilder;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.sql.SQLException;
34338
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
    31
import java.sql.SQLFeatureNotSupportedException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.sql.Wrapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>A factory for connections to the physical data source that this
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    36
 * {@code DataSource} object represents.  An alternative to the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    37
 * {@code DriverManager} facility, a {@code DataSource} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * is the preferred means of getting a connection. An object that implements
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    39
 * the {@code DataSource} interface will typically be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * registered with a naming service based on the
18564
f9db68ff2cbb 8017471: Fix JDBC -Xdoclint public errors
lancea
parents: 18156
diff changeset
    41
 * Java&trade; Naming and Directory (JNDI) API.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <P>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    43
 * The {@code DataSource} interface is implemented by a driver vendor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * There are three types of implementations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <OL>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    46
 *   <LI>Basic implementation -- produces a standard {@code Connection}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *       object
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    48
 *   <LI>Connection pooling implementation -- produces a {@code Connection}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *       object that will automatically participate in connection pooling.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       implementation works with a middle-tier connection pooling manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   <LI>Distributed transaction implementation -- produces a
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    52
 *       {@code Connection} object that may be used for distributed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *       transactions and almost always participates in connection pooling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *       This implementation works with a middle-tier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *       transaction manager and almost always with a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *       pooling manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <P>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    59
 * A {@code DataSource} object has properties that can be modified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * when necessary.  For example, if the data source is moved to a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * server, the property for the server can be changed.  The benefit is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * because the data source's properties can be changed, any code accessing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * that data source does not need to be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <P>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    65
 * A driver that is accessed via a {@code DataSource} object does not
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    66
 * register itself with the {@code DriverManager}.  Rather, a
40409
564ea8deef3c 8138661: Minor correction in Java API doc for DataSource
lancea
parents: 35277
diff changeset
    67
 * {@code DataSource} object is retrieved through a lookup operation
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    68
 * and then used to create a {@code Connection} object.  With a basic
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    69
 * implementation, the connection obtained through a {@code DataSource}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * object is identical to a connection obtained through the
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    71
 * {@code DriverManager} facility.
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    72
 * <p>
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    73
 * An implementation of {@code DataSource} must include a public no-arg
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    74
 * constructor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    79
public interface DataSource  extends CommonDataSource, Wrapper {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   * <p>Attempts to establish a connection with the data source that
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    83
   * this {@code DataSource} object represents.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
   * @return  a connection to the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   * @exception SQLException if a database access error occurs
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15278
diff changeset
    87
   * @throws java.sql.SQLTimeoutException  when the driver has determined that the
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    88
   * timeout value specified by the {@code setLoginTimeout} method
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    89
   * has been exceeded and has at least tried to cancel the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    90
   * current database connection attempt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  Connection getConnection() throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   * <p>Attempts to establish a connection with the data source that
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    96
   * this {@code DataSource} object represents.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
   * @param username the database user on whose behalf the connection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   *  being made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
   * @param password the user's password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
   * @return  a connection to the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   * @exception SQLException if a database access error occurs
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 15278
diff changeset
   103
   * @throws java.sql.SQLTimeoutException  when the driver has determined that the
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
   104
   * timeout value specified by the {@code setLoginTimeout} method
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
   105
   * has been exceeded and has at least tried to cancel the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
   106
   * current database connection attempt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  Connection getConnection(String username, String password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    throws SQLException;
34338
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   111
40533
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   112
  /**
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   113
   * {@inheritDoc}
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   114
   * @since 1.4
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   115
   */
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   116
  @Override
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   117
  java.io.PrintWriter getLogWriter() throws SQLException;
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   118
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   119
  /**
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   120
   * {@inheritDoc}
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   121
   * @since 1.4
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   122
   */
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   123
  @Override
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   124
  void setLogWriter(java.io.PrintWriter out) throws SQLException;
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   125
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   126
  /**
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   127
   * {@inheritDoc}
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   128
   * @since 1.4
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   129
   */
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   130
  @Override
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   131
  void setLoginTimeout(int seconds) throws SQLException;
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   132
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   133
  /**
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   134
   * {@inheritDoc}
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   135
   * @since 1.4
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   136
   */
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   137
  @Override
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   138
  int getLoginTimeout() throws SQLException;
ec047f91988e 8164061: Fix @since for javax.sql.rowset.BaseRowSet and javax.sql.CommonDataSource
lancea
parents: 40409
diff changeset
   139
34338
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   140
  // JDBC 4.3
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   141
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   142
  /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   143
   * Create a new {@code ConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   144
   * @implSpec
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   145
   * The default implementation will throw a {@code SQLFeatureNotSupportedException}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   146
   * @return The ConnectionBuilder instance that was created
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   147
   * @throws SQLException if an error occurs creating the builder
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   148
   * @throws SQLFeatureNotSupportedException if the driver does not support sharding
35277
eb4794f43d20 8146803: Enhance and update Sharding API
lancea
parents: 34338
diff changeset
   149
   * @since 9
eb4794f43d20 8146803: Enhance and update Sharding API
lancea
parents: 34338
diff changeset
   150
   * @see ConnectionBuilder
34338
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   151
   */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   152
  default ConnectionBuilder createConnectionBuilder() throws SQLException {
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   153
        throw new SQLFeatureNotSupportedException("createConnectionBuilder not implemented");
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   154
  };
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents: 25859
diff changeset
   155
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
}