jdk/src/java.sql/share/classes/javax/sql/XAConnectionBuilder.java
author lancea
Wed, 25 Nov 2015 15:36:03 -0500
changeset 34338 67d0e5867568
child 35277 eb4794f43d20
permissions -rw-r--r--
8085984: Add JDBC Sharding API Reviewed-by: ulfzibis, joehw
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 javax.sql;
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    26
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    27
import java.sql.SQLException;
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    28
import java.sql.ShardingKey;
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    29
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    30
/**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    31
 * A builder created from a {@code XADataSource} object,
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    32
 * used to establish a connection to the database that the
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    33
 * {@code data source} object represents.  The connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    34
 * properties that were specified for the {@code data source} are used as the
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    35
 * default values by the {@code XAConnectionBuilder}.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    36
 * <p>The following example illustrates the use of {@code XAConnectionBuilder}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    37
 * to create a {@link XAConnection}:
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    38
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    39
 * <pre>{@code
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    40
 *     DataSource ds = new MyDataSource();
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    41
 *     ShardingKey superShardingKey = ds.createShardingKeyBuilder()
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    42
 *                           .subkey("EASTERN_REGION", 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
 *     ShardingKey shardingKey = ds.createShardingKeyBuilder()
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    45
 *                           .subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR)
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    46
 *                           .build();
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    47
 *     XAConnection con = ds.createXAConnectionBuilder()
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    48
 *                       .user("rafa")
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    49
 *                       .password("tennis")
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    50
 *                       .setShardingKey(shardingKey)
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    51
 *                       .setSuperShardingKey(superShardingKey)
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    52
 *                       .build();
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    53
 * }</pre>
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    54
 *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    55
 * @since 1.9
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
public interface XAConnectionBuilder  {
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    59
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    60
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    61
     * Specifies the username to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    62
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    63
     * @param username the database user on whose behalf the connection is being
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    64
     * made
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    65
     * @return the same {@code XAConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    66
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    67
    XAConnectionBuilder user(String username);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    68
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    69
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    70
     * Specifies the password to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    71
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    72
     * @param password the password to use for this connection. May be {@code null}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    73
     * @return the same {@code XAConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    74
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    75
    XAConnectionBuilder password(String password);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    76
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    77
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    78
     * Specifies a {@code shardingKey} to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    79
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    80
     * @param shardingKey the ShardingKey. May be {@code null}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    81
     * @return the same {@code XAConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    82
     * @see java.sql.ShardingKey
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    83
     * @see java.sql.ShardingKeyBuilder
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    84
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    85
    XAConnectionBuilder shardingKey(ShardingKey shardingKey);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    86
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    87
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    88
     * Specifies a {@code superShardingKey} to be used when creating a connection
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    89
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    90
     * @param superShardingKey the SuperShardingKey. May be {@code null}
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    91
     * @return the same {@code XAConnectionBuilder} instance
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    92
     * @see java.sql.ShardingKey
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    93
     * @see java.sql.ShardingKeyBuilder
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    94
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    95
    XAConnectionBuilder superShardingKey(ShardingKey superShardingKey);
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    96
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    97
    /**
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    98
     * Returns an instance of the object defined by this builder.
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
    99
     *
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   100
     * @return The built object
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   101
     * @throws java.sql.SQLException If an error occurs building the object
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   102
     */
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   103
    XAConnection build() throws SQLException;
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   104
67d0e5867568 8085984: Add JDBC Sharding API
lancea
parents:
diff changeset
   105
}