author | naoto |
Tue, 12 Nov 2019 14:05:18 -0800 | |
changeset 59043 | 1a79b4bfc85a |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
35277 | 2 |
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.sql; |
|
27 |
||
28 |
import java.sql.Connection; |
|
34338 | 29 |
import java.sql.ConnectionBuilder; |
2 | 30 |
import java.sql.SQLException; |
34338 | 31 |
import java.sql.SQLFeatureNotSupportedException; |
2 | 32 |
import java.sql.Wrapper; |
33 |
||
34 |
/** |
|
35 |
* <p>A factory for connections to the physical data source that this |
|
15278 | 36 |
* {@code DataSource} object represents. An alternative to the |
37 |
* {@code DriverManager} facility, a {@code DataSource} object |
|
2 | 38 |
* is the preferred means of getting a connection. An object that implements |
15278 | 39 |
* the {@code DataSource} interface will typically be |
2 | 40 |
* registered with a naming service based on the |
18564 | 41 |
* Java™ Naming and Directory (JNDI) API. |
2 | 42 |
* <P> |
15278 | 43 |
* The {@code DataSource} interface is implemented by a driver vendor. |
2 | 44 |
* There are three types of implementations: |
45 |
* <OL> |
|
15278 | 46 |
* <LI>Basic implementation -- produces a standard {@code Connection} |
2 | 47 |
* object |
15278 | 48 |
* <LI>Connection pooling implementation -- produces a {@code Connection} |
2 | 49 |
* object that will automatically participate in connection pooling. This |
50 |
* implementation works with a middle-tier connection pooling manager. |
|
51 |
* <LI>Distributed transaction implementation -- produces a |
|
15278 | 52 |
* {@code Connection} object that may be used for distributed |
2 | 53 |
* transactions and almost always participates in connection pooling. |
54 |
* This implementation works with a middle-tier |
|
55 |
* transaction manager and almost always with a connection |
|
56 |
* pooling manager. |
|
57 |
* </OL> |
|
58 |
* <P> |
|
15278 | 59 |
* A {@code DataSource} object has properties that can be modified |
2 | 60 |
* when necessary. For example, if the data source is moved to a different |
61 |
* server, the property for the server can be changed. The benefit is that |
|
62 |
* because the data source's properties can be changed, any code accessing |
|
63 |
* that data source does not need to be changed. |
|
64 |
* <P> |
|
15278 | 65 |
* A driver that is accessed via a {@code DataSource} object does not |
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 | 68 |
* and then used to create a {@code Connection} object. With a basic |
69 |
* implementation, the connection obtained through a {@code DataSource} |
|
2 | 70 |
* object is identical to a connection obtained through the |
15278 | 71 |
* {@code DriverManager} facility. |
72 |
* <p> |
|
73 |
* An implementation of {@code DataSource} must include a public no-arg |
|
74 |
* constructor. |
|
2 | 75 |
* |
76 |
* @since 1.4 |
|
77 |
*/ |
|
78 |
||
15278 | 79 |
public interface DataSource extends CommonDataSource, Wrapper { |
2 | 80 |
|
81 |
/** |
|
82 |
* <p>Attempts to establish a connection with the data source that |
|
15278 | 83 |
* this {@code DataSource} object represents. |
2 | 84 |
* |
85 |
* @return a connection to the data source |
|
86 |
* @exception SQLException if a database access error occurs |
|
18156 | 87 |
* @throws java.sql.SQLTimeoutException when the driver has determined that the |
15278 | 88 |
* timeout value specified by the {@code setLoginTimeout} method |
89 |
* has been exceeded and has at least tried to cancel the |
|
90 |
* current database connection attempt |
|
2 | 91 |
*/ |
92 |
Connection getConnection() throws SQLException; |
|
93 |
||
94 |
/** |
|
95 |
* <p>Attempts to establish a connection with the data source that |
|
15278 | 96 |
* this {@code DataSource} object represents. |
2 | 97 |
* |
98 |
* @param username the database user on whose behalf the connection is |
|
99 |
* being made |
|
100 |
* @param password the user's password |
|
101 |
* @return a connection to the data source |
|
102 |
* @exception SQLException if a database access error occurs |
|
18156 | 103 |
* @throws java.sql.SQLTimeoutException when the driver has determined that the |
15278 | 104 |
* timeout value specified by the {@code setLoginTimeout} method |
105 |
* has been exceeded and has at least tried to cancel the |
|
106 |
* current database connection attempt |
|
2 | 107 |
* @since 1.4 |
108 |
*/ |
|
109 |
Connection getConnection(String username, String password) |
|
110 |
throws SQLException; |
|
34338 | 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 | 140 |
// JDBC 4.3 |
141 |
||
142 |
/** |
|
143 |
* Create a new {@code ConnectionBuilder} instance |
|
144 |
* @implSpec |
|
145 |
* The default implementation will throw a {@code SQLFeatureNotSupportedException} |
|
146 |
* @return The ConnectionBuilder instance that was created |
|
147 |
* @throws SQLException if an error occurs creating the builder |
|
148 |
* @throws SQLFeatureNotSupportedException if the driver does not support sharding |
|
35277 | 149 |
* @since 9 |
150 |
* @see ConnectionBuilder |
|
34338 | 151 |
*/ |
152 |
default ConnectionBuilder createConnectionBuilder() throws SQLException { |
|
153 |
throw new SQLFeatureNotSupportedException("createConnectionBuilder not implemented"); |
|
154 |
}; |
|
155 |
||
2 | 156 |
} |