You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/10/08 15:32:18 UTC
(shardingsphere) branch master updated: Refactor QueryContext.getUsedDatabase() (#36825)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9fc9cc75991 Refactor QueryContext.getUsedDatabase() (#36825)
9fc9cc75991 is described below
commit 9fc9cc7599181ba51254d9001033b3c308c52a9b
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Oct 8 23:32:12 2025 +0800
Refactor QueryContext.getUsedDatabase() (#36825)
---
.../org/apache/shardingsphere/infra/session/query/QueryContext.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java
index 41711a08719..f9326ac3c11 100644
--- a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java
+++ b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java
@@ -85,7 +85,8 @@ public final class QueryContext {
public ShardingSphereDatabase getUsedDatabase() {
ShardingSpherePreconditions.checkState(usedDatabaseNames.size() <= 1,
() -> new UnsupportedSQLOperationException(String.format("Can not support multiple logic databases [%s]", Joiner.on(", ").join(usedDatabaseNames))));
- String databaseName = usedDatabaseNames.isEmpty() ? connectionContext.getCurrentDatabaseName().orElseThrow(NoDatabaseSelectedException::new) : usedDatabaseNames.iterator().next();
+ ShardingSpherePreconditions.checkState(usedDatabaseNames.size() == 1, NoDatabaseSelectedException::new);
+ String databaseName = usedDatabaseNames.iterator().next();
ShardingSpherePreconditions.checkState(metaData.containsDatabase(databaseName), () -> new UnknownDatabaseException(databaseName));
return metaData.getDatabase(databaseName);
}