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 <[email protected]>
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);
     }

Reply via email to