Path: blob/master/src/java.sql/share/classes/java/sql/ShardingKey.java
41153 views
/*1* Copyright (c) 2015, 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* Interface used to indicate that this object represents a Sharding Key. A28* {@code ShardingKey} instance is only guaranteed to be compatible with the29* data source instance that it was derived from. A {@code ShardingKey} is30* created using {@link ShardingKeyBuilder}.31* <p>32* The following example illustrates the use of {@link ShardingKeyBuilder} to33* create a {@code ShardingKey}:34* <pre>35* {@code36*37* DataSource ds = new MyDataSource();38* ShardingKey shardingKey = ds.createShardingKeyBuilder()39* .subkey("abc", JDBCType.VARCHAR)40* .subkey(94002, JDBCType.INTEGER)41* .build();42* }43* </pre>44* <p>45*46* A {@code ShardingKey} may also be used for specifying a47* {@code superShardingKey}. Databases that support composite Sharding may use a48* {@code superShardingKey} to specify a additional level of partitioning within49* the Shard.50* <p>51* The following example illustrates the use of {@link ShardingKeyBuilder} to52* create a {@code superShardingKey} for an eastern region with a53* {@code ShardingKey} specified for the Pittsburgh branch office:54* <pre>55* {@code56*57* DataSource ds = new MyDataSource();58* ShardingKey superShardingKey = ds.createShardingKeyBuilder()59* .subkey("EASTERN_REGION", JDBCType.VARCHAR)60* .build();61* ShardingKey shardingKey = ds.createShardingKeyBuilder()62* .subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR)63* .build();64* Connection con = ds.createConnectionBuilder()65* .superShardingKey(superShardingKey)66* .shardingKey(shardingKey)67* .build();68* }69* </pre>70*71* @since 972*/73public interface ShardingKey {7475}767778