Top Description Methods
org.springframework.jdbc.datasource

public Interface ShardingKeyProvider

Imports
java.sql.SQLException, .ShardingKey, org.springframework.lang.Nullable

Strategy interface for determining sharding keys which are used to establish direct shard connections in the context of sharded databases. This is used as a callback for providing the current sharding key (plus optionally a super sharding key) in org.springframework.jdbc.datasource.ShardingKeyDataSourceAdapter.

Can be used as a functional interface (e.g. with a lambda expression) for a simple sharding key, or as a two-method interface when including a super sharding key as well.

Authors
Mohamed Lahyane (Anir), Juergen Hoeller
Since
6.1.2
See Also
ShardingKeyDataSourceAdapter#setShardingKeyProvider

Method Summary

Modifier and TypeMethod and Description
public ShardingKey

Returns:

the sharding key, or null if it is not available or cannot be determined
getShardingKey
()

Determine the sharding key.

public default ShardingKey

Returns:

the super sharding key, or null if it is not available or cannot be determined (the default)
getSuperShardingKey
()

Determine the super sharding key, if any.

Method Detail

getShardingKeyback to summary
public ShardingKey getShardingKey() throws SQLException

Determine the sharding key. This method returns the sharding key relevant to the current context which will be used to obtain a direct shard connection.

Returns:ShardingKey

the sharding key, or null if it is not available or cannot be determined

Annotations
@Nullable
Exceptions
SQLException:
if an error occurs while obtaining the sharding key
getSuperShardingKeyback to summary
public default ShardingKey getSuperShardingKey() throws SQLException

Determine the super sharding key, if any. This method returns the super sharding key relevant to the current context which will be used to obtain a direct shard connection.

Returns:ShardingKey

the super sharding key, or null if it is not available or cannot be determined (the default)

Annotations
@Nullable
Exceptions
SQLException:
if an error occurs while obtaining the super sharding key