This is an automated email from the ASF dual-hosted git repository.

zhaojinchao 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 1c84f2d3fe3 Refactor ShardingSphereProxyVersion (#31937)
1c84f2d3fe3 is described below

commit 1c84f2d3fe3d0270de8531c8287c082a0b184ce3
Author: Raigor <[email protected]>
AuthorDate: Mon Jul 1 00:37:59 2024 +0800

    Refactor ShardingSphereProxyVersion (#31937)
---
 .../proxy/version/ShardingSphereProxyVersion.java            | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git 
a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
 
b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
index 653e46946e4..e1e62d1a8e7 100644
--- 
a/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
+++ 
b/proxy/bootstrap/src/main/java/org/apache/shardingsphere/proxy/version/ShardingSphereProxyVersion.java
@@ -24,9 +24,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.db.protocol.constant.CommonConstants;
 import 
org.apache.shardingsphere.db.protocol.constant.DatabaseProtocolServerInfo;
 import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.proxy.database.DatabaseServerInfo;
 
@@ -65,7 +63,7 @@ public final class ShardingSphereProxyVersion {
     }
     
     private static void setDatabaseVersion(final ShardingSphereDatabase 
database) {
-        Optional<DataSource> dataSource = 
findDataSourceByProtocolType(database.getResourceMetaData(), 
database.getProtocolType());
+        Optional<DataSource> dataSource = 
findDataSourceByProtocolType(database);
         if (!dataSource.isPresent()) {
             return;
         }
@@ -74,10 +72,10 @@ public final class ShardingSphereProxyVersion {
         DatabaseProtocolServerInfo.setProtocolVersion(database.getName(), 
databaseServerInfo.getDatabaseVersion());
     }
     
-    private static Optional<DataSource> findDataSourceByProtocolType(final 
ResourceMetaData resourceMetaData, final DatabaseType protocolType) {
-        Optional<String> dataSourceName = 
resourceMetaData.getStorageUnits().entrySet()
-                .stream().filter(entry -> 
entry.getValue().getStorageType().equals(protocolType)).map(Entry::getKey).findFirst();
-        Map<String, DataSource> dataSources = 
resourceMetaData.getStorageUnits().entrySet().stream()
+    private static Optional<DataSource> findDataSourceByProtocolType(final 
ShardingSphereDatabase database) {
+        Optional<String> dataSourceName = 
database.getResourceMetaData().getStorageUnits().entrySet()
+                .stream().filter(entry -> 
entry.getValue().getStorageType().equals(database.getProtocolType())).map(Entry::getKey).findFirst();
+        Map<String, DataSource> dataSources = 
database.getResourceMetaData().getStorageUnits().entrySet().stream()
                 .collect(Collectors.toMap(Entry::getKey, entry -> 
entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, 
LinkedHashMap::new));
         return dataSourceName.flatMap(optional -> 
Optional.ofNullable(dataSources.get(optional)));
     }

Reply via email to