src/java.sql/share/classes/java/sql/ConnectionBuilder.java
author darcy
Thu, 01 Nov 2018 20:37:45 -0700
changeset 52380 6b31efbf833e
parent 47216 71c04702a3d5
child 55448 0f141453b9e0
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:
34338
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     1
/*
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     4
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    10
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    15
 * accompanied this code).
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    16
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    20
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    23
 * questions.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    24
 */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    25
package java.sql;
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    26
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    27
/**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    28
 * A builder created from a {@code DataSource} object,
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    29
 * used to establish a connection to the database that the
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    30
 * {@code data source} object represents.  The connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    31
 * properties that were specified for the {@code data source} are used as the
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    32
 * default values by the {@code ConnectionBuilder}.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    33
 * <p>The following example illustrates the use of {@code ConnectionBuilder}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    34
 * to create a {@link Connection}:
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    35
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    36
 * <pre>{@code
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    37
 *     DataSource ds = new MyDataSource();
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    38
 *     ShardingKey superShardingKey = ds.createShardingKeyBuilder()
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    39
 *                           .subkey("EASTERN_REGION", JDBCType.VARCHAR)
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    40
 *                           .build();
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    41
 *     ShardingKey shardingKey = ds.createShardingKeyBuilder()
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    42
 *                           .subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR)
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    43
 *                           .build();
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    44
 *     Connection con = ds.createConnectionBuilder()
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    45
 *                       .user("rafa")
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    46
 *                       .password("tennis")
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    47
 *                       .setShardingKey(shardingKey)
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    48
 *                       .setSuperShardingKey(superShardingKey)
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    49
 *                       .build();
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    50
 * }</pre>
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    51
 *
35302
e4d2275861c3 8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents: 34338
diff changeset
    52
 * @since 9
34338
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    53
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    54
 */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    55
public interface ConnectionBuilder  {
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    56
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    57
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    58
     * Specifies the username to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    59
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    60
     * @param username the database user on whose behalf the connection is being
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    61
     * made
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    62
     * @return the same {@code ConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    63
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    64
    ConnectionBuilder user(String username);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    65
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    66
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    67
     * Specifies the password to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    68
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    69
     * @param password the password to use for this connection. May be {@code null}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    70
     * @return the same {@code ConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    71
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    72
    ConnectionBuilder password(String password);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    73
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    74
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    75
     * Specifies a {@code shardingKey} to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    76
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    77
     * @param shardingKey the ShardingKey. May be {@code null}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    78
     * @return the same {@code ConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    79
     * @see ShardingKey
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    80
     * @see ShardingKeyBuilder
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    81
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    82
    ConnectionBuilder shardingKey(ShardingKey shardingKey);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    83
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    84
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    85
     * Specifies a {@code superShardingKey} to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    86
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    87
     * @param superShardingKey the SuperShardingKey. May be {@code null}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    88
     * @return the same {@code ConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    89
     * @see ShardingKey
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    90
     * @see ShardingKeyBuilder
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    91
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    92
    ConnectionBuilder superShardingKey(ShardingKey superShardingKey);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    93
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    94
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    95
     * Returns an instance of the object defined by this builder.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    96
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    97
     * @return The built object
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    98
     * @throws java.sql.SQLException If an error occurs building the object
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    99
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   100
    Connection build() throws SQLException;
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   101
}