Interface ShardingKeyProvider


public interface ShardingKeyProvider
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 ShardingKeyDataSourceAdapter.

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

Since:
6.1.2
Author:
Mohamed Lahyane (Anir), Juergen Hoeller
See Also:
  • Method Details

    • getShardingKey

      @Nullable 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:
      the sharding key, or null if it is not available or cannot be determined
      Throws:
      SQLException - if an error occurs while obtaining the sharding key
    • getSuperShardingKey

      @Nullable 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:
      the super sharding key, or null if it is not available or cannot be determined (the default)
      Throws:
      SQLException - if an error occurs while obtaining the super sharding key