Interface ShardingKey
public interfaceShardingKey
Interface used to indicate that this object represents a Sharding Key. A
ShardingKey instance is only guaranteed to be compatible with the data source instance that it was derived from. AShardingKey is created usingShardingKeyBuilder. The following example illustrates the use ofShardingKeyBuilder to create aShardingKey:
DataSource ds = new MyDataSource(); ShardingKey shardingKey = ds.createShardingKeyBuilder() .subkey("abc", JDBCType.VARCHAR) .subkey(94002, JDBCType.INTEGER) .build(); AShardingKey may also be used for specifying asuperShardingKey. Databases that support composite Sharding may use asuperShardingKey to specify a additional level of partitioning within the Shard.
The following example illustrates the use ofShardingKeyBuilder to create asuperShardingKey for an eastern region with aShardingKey specified for the Pittsburgh branch office:
DataSource ds = new MyDataSource(); ShardingKey superShardingKey = ds.createShardingKeyBuilder() .subkey("EASTERN_REGION", JDBCType.VARCHAR) .build(); ShardingKey shardingKey = ds.createShardingKeyBuilder() .subkey("PITTSBURGH_BRANCH", JDBCType.VARCHAR) .build(); Connection con = ds.createConnectionBuilder() .superShardingKey(superShardingKey) .shardingKey(shardingKey) .build();- Since:
- 9