jdk/src/share/classes/javax/sql/DataSource.java
author lancea
Sat, 19 Jan 2013 10:53:14 -0500
changeset 15278 e081d3f73b75
parent 5506 202f599c92aa
child 18156 edb590d448c5
permissions -rw-r--r--
8005080: JDBC 4.2 Core changes Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2013, 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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.sql.SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.sql.Wrapper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <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
    34
 * {@code DataSource} object represents.  An alternative to the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    35
 * {@code DriverManager} facility, a {@code DataSource} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * 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
    37
 * the {@code DataSource} interface will typically be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * registered with a naming service based on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Java<sup><font size=-2>TM</font></sup> Naming and Directory (JNDI) API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <P>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    41
 * The {@code DataSource} interface is implemented by a driver vendor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * There are three types of implementations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <OL>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    44
 *   <LI>Basic implementation -- produces a standard {@code Connection}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *       object
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    46
 *   <LI>Connection pooling implementation -- produces a {@code Connection}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *       object that will automatically participate in connection pooling.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *       implementation works with a middle-tier connection pooling manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *   <LI>Distributed transaction implementation -- produces a
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    50
 *       {@code Connection} object that may be used for distributed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *       transactions and almost always participates in connection pooling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *       This implementation works with a middle-tier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *       transaction manager and almost always with a connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *       pooling manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <P>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    57
 * A {@code DataSource} object has properties that can be modified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * when necessary.  For example, if the data source is moved to a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * server, the property for the server can be changed.  The benefit is that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * because the data source's properties can be changed, any code accessing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * that data source does not need to be changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <P>
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    63
 * A driver that is accessed via a {@code DataSource} object does not
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    64
 * register itself with the {@code DriverManager}.  Rather, a
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    65
 * {@code DataSource} object is retrieved though a lookup operation
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    66
 * and then used to create a {@code Connection} object.  With a basic
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    67
 * implementation, the connection obtained through a {@code DataSource}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * object is identical to a connection obtained through the
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    69
 * {@code DriverManager} facility.
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    70
 * <p>
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    71
 * An implementation of {@code DataSource} must include a public no-arg
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    72
 * constructor.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    77
public interface DataSource  extends CommonDataSource, Wrapper {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
   * <p>Attempts to establish a connection with the data source that
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    81
   * this {@code DataSource} object represents.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
   * @return  a connection to the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   * @exception SQLException if a database access error occurs
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    85
   * @throws SQLTimeoutException  when the driver has determined that the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    86
   * timeout value specified by the {@code setLoginTimeout} method
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    87
   * has been exceeded and has at least tried to cancel the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    88
   * current database connection attempt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  Connection getConnection() throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
   * <p>Attempts to establish a connection with the data source that
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
    94
   * this {@code DataSource} object represents.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
   * @param username the database user on whose behalf the connection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
   *  being made
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
   * @param password the user's password
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   * @return  a connection to the data source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
   * @exception SQLException if a database access error occurs
15278
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
   101
   * @throws SQLTimeoutException  when the driver has determined that the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
   102
   * timeout value specified by the {@code setLoginTimeout} method
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
   103
   * has been exceeded and has at least tried to cancel the
e081d3f73b75 8005080: JDBC 4.2 Core changes
lancea
parents: 5506
diff changeset
   104
   * current database connection attempt
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  Connection getConnection(String username, String password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
}