Path: blob/master/src/java.sql/share/classes/javax/sql/PooledConnectionBuilder.java
41152 views
/*1* Copyright (c) 2016, 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 javax.sql;2526import java.sql.SQLException;27import java.sql.ShardingKey;2829/**30* A builder created from a {@code ConnectionPoolDataSource} object,31* used to establish a connection to the database that the32* {@code data source} object represents. The connection33* properties that were specified for the {@code data source} are used as the34* default values by the {@code PooledConnectionBuilder}.35* <p>The following example illustrates the use of {@code PooledConnectionBuilder}36* to create a {@link XAConnection}:37*38* <pre>{@code39* ConnectionPoolDataSource ds = new MyConnectionPoolDataSource();40* ShardingKey superShardingKey = ds.createShardingKeyBuilder()41* .subkey("EASTERN_REGION", JDBCType.VARCHAR)42* .build();43* ShardingKey shardingKey = ds.createShardingKeyBuilder()44* .subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR)45* .build();46* PooledConnection con = ds.createPooledConnectionBuilder()47* .user("rafa")48* .password("tennis")49* .shardingKey(shardingKey)50* .superShardingKey(superShardingKey)51* .build();52* }</pre>53*54* @since 955*56*/57public interface PooledConnectionBuilder {5859/**60* Specifies the username to be used when creating a connection61*62* @param username the database user on whose behalf the connection is being63* made64* @return the same {@code PooledConnectionBuilder} instance65*/66PooledConnectionBuilder user(String username);6768/**69* Specifies the password to be used when creating a connection70*71* @param password the password to use for this connection. May be {@code null}72* @return the same {@code PooledConnectionBuilder} instance73*/74PooledConnectionBuilder password(String password);7576/**77* Specifies a {@code shardingKey} to be used when creating a connection78*79* @param shardingKey the ShardingKey. May be {@code null}80* @return the same {@code PooledConnectionBuilder} instance81* @see java.sql.ShardingKey82* @see java.sql.ShardingKeyBuilder83*/84PooledConnectionBuilder shardingKey(ShardingKey shardingKey);8586/**87* Specifies a {@code superShardingKey} to be used when creating a connection88*89* @param superShardingKey the SuperShardingKey. May be {@code null}90* @return the same {@code PooledConnectionBuilder} instance91* @see java.sql.ShardingKey92* @see java.sql.ShardingKeyBuilder93*/94PooledConnectionBuilder superShardingKey(ShardingKey superShardingKey);9596/**97* Returns an instance of the object defined by this builder.98*99* @return The built object100* @throws java.sql.SQLException If an error occurs building the object101*/102PooledConnection build() throws SQLException;103104}105106107