Path: blob/master/src/java.sql/share/classes/java/sql/ConnectionBuilder.java
41153 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package java.sql;2526/**27* A builder created from a {@code DataSource} object,28* used to establish a connection to the database that the29* {@code data source} object represents. The connection30* properties that were specified for the {@code data source} are used as the31* default values by the {@code ConnectionBuilder}.32* <p>The following example illustrates the use of {@code ConnectionBuilder}33* to create a {@link Connection}:34*35* <pre>{@code36* DataSource ds = new MyDataSource();37* ShardingKey superShardingKey = ds.createShardingKeyBuilder()38* .subkey("EASTERN_REGION", JDBCType.VARCHAR)39* .build();40* ShardingKey shardingKey = ds.createShardingKeyBuilder()41* .subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR)42* .build();43* Connection con = ds.createConnectionBuilder()44* .user("rafa")45* .password("tennis")46* .shardingKey(shardingKey)47* .superShardingKey(superShardingKey)48* .build();49* }</pre>50*51* @since 952*53*/54public interface ConnectionBuilder {5556/**57* Specifies the username to be used when creating a connection58*59* @param username the database user on whose behalf the connection is being60* made61* @return the same {@code ConnectionBuilder} instance62*/63ConnectionBuilder user(String username);6465/**66* Specifies the password to be used when creating a connection67*68* @param password the password to use for this connection. May be {@code null}69* @return the same {@code ConnectionBuilder} instance70*/71ConnectionBuilder password(String password);7273/**74* Specifies a {@code shardingKey} to be used when creating a connection75*76* @param shardingKey the ShardingKey. May be {@code null}77* @return the same {@code ConnectionBuilder} instance78* @see ShardingKey79* @see ShardingKeyBuilder80*/81ConnectionBuilder shardingKey(ShardingKey shardingKey);8283/**84* Specifies a {@code superShardingKey} to be used when creating a connection85*86* @param superShardingKey the SuperShardingKey. May be {@code null}87* @return the same {@code ConnectionBuilder} instance88* @see ShardingKey89* @see ShardingKeyBuilder90*/91ConnectionBuilder superShardingKey(ShardingKey superShardingKey);9293/**94* Returns an instance of the object defined by this builder.95*96* @return The built object97* @throws java.sql.SQLException If an error occurs building the object98*/99Connection build() throws SQLException;100}101102103