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 4b9ce641497 Refactor UnicastDatabaseProxyBackendHandler (#36805)
4b9ce641497 is described below
commit 4b9ce641497d0197b92ef7ac8e0af2f679a2fc6e
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Oct 7 14:11:29 2025 +0800
Refactor UnicastDatabaseProxyBackendHandler (#36805)
---
.../handler/data/impl/UnicastDatabaseProxyBackendHandler.java | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseProxyBackendHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseProxyBackendHandler.java
index e04b6a1bb12..0e3bc57a9d7 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseProxyBackendHandler.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseProxyBackendHandler.java
@@ -68,13 +68,11 @@ public final class UnicastDatabaseProxyBackendHandler
implements DatabaseProxyBa
private String getFirstDatabaseName() {
Collection<String> databaseNames =
ProxyContext.getInstance().getAllDatabaseNames();
- if (databaseNames.isEmpty()) {
- throw new NoDatabaseSelectedException();
- }
+ ShardingSpherePreconditions.checkNotEmpty(databaseNames,
NoDatabaseSelectedException::new);
AuthorityRule authorityRule =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(AuthorityRule.class);
Optional<ShardingSpherePrivileges> privileges =
authorityRule.findPrivileges(connectionSession.getConnectionContext().getGrantee());
- Stream<String> databaseStream = databaseNames.stream().filter(each ->
ProxyContext.getInstance().getContextManager().getDatabase(each).containsDataSource());
- Optional<String> result = privileges.map(optional ->
databaseStream.filter(optional::hasPrivileges).findFirst()).orElseGet(databaseStream::findFirst);
+ Stream<String> storageUnitContainedDatabaseNames =
databaseNames.stream().filter(each ->
ProxyContext.getInstance().getContextManager().getDatabase(each).containsDataSource());
+ Optional<String> result = privileges.map(optional ->
storageUnitContainedDatabaseNames.filter(optional::hasPrivileges).findFirst()).orElseGet(storageUnitContainedDatabaseNames::findFirst);
ShardingSpherePreconditions.checkState(result.isPresent(),
EmptyStorageUnitException::new);
return result.get();
}