-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegation support for JDBC 4.3 ConnectionBuilder and ShardingKeyBuilder
Also moves ShardingKeyProvider to datasource package and declares getSuperShardingKey as default method. Closes gh-31795 See gh-31506
- Loading branch information
Showing
7 changed files
with
209 additions
and
152 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
spring-jdbc/src/main/java/org/springframework/jdbc/core/ShardingKeyProvider.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2002-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.jdbc.datasource; | ||
|
||
import java.sql.SQLException; | ||
import java.sql.ShardingKey; | ||
|
||
import 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 | ||
* {@link org.springframework.jdbc.datasource.ShardingKeyDataSourceAdapter}. | ||
* | ||
* <p>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. | ||
* | ||
* @author Mohamed Lahyane (Anir) | ||
* @author Juergen Hoeller | ||
* @since 6.1.2 | ||
* @see ShardingKeyDataSourceAdapter#setShardingKeyProvider | ||
*/ | ||
public interface ShardingKeyProvider { | ||
|
||
/** | ||
* 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. | ||
* @return the sharding key, or {@code null} if it is not available or cannot be determined | ||
* @throws SQLException if an error occurs while obtaining the sharding key | ||
*/ | ||
@Nullable | ||
ShardingKey getShardingKey() 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. | ||
* @return the super sharding key, or {@code null} if it is not available or cannot be | ||
* determined (the default) | ||
* @throws SQLException if an error occurs while obtaining the super sharding key | ||
*/ | ||
@Nullable | ||
default ShardingKey getSuperShardingKey() throws SQLException { | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.