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

yx9o 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 c693db840a0 Refactor StorageNodeName (#28613)
c693db840a0 is described below

commit c693db840a0e58244ab7c1e0c435689ee07357a4
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Thu Sep 28 12:21:57 2023 +0800

    Refactor StorageNodeName (#28613)
    
    * Rename StorageNodeIdentifier
    
    * Refactor StorageNode
    
    * Refactor StorageNodeName
    
    * Refactor StorageNodeName
    
    * Refactor StorageNodeName
---
 .../metadata/database/resource/node/StorageNode.java  | 10 +++-------
 .../database/resource/node/StorageNodeName.java       |  4 ++++
 .../resource/unit/StorageUnitNodeMapperUtils.java     | 19 ++++++++-----------
 3 files changed, 15 insertions(+), 18 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java
index 98e0b033729..fa836f44b44 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNode.java
@@ -18,10 +18,12 @@
 package org.apache.shardingsphere.infra.metadata.database.resource.node;
 
 import lombok.Getter;
+import lombok.RequiredArgsConstructor;
 
 /**
  * Storage node.
  */
+@RequiredArgsConstructor
 @Getter
 public final class StorageNode {
     
@@ -31,13 +33,7 @@ public final class StorageNode {
     
     private final String catalog;
     
-    public StorageNode(final String name, final String url) {
+    public StorageNode(final StorageNodeName name, final String url) {
         this(name, url, null);
     }
-    
-    public StorageNode(final String name, final String url, final String 
catalog) {
-        this.name = new StorageNodeName(name);
-        this.url = url;
-        this.catalog = catalog;
-    }
 }
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeName.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeName.java
index ec6941710ba..3ec99ec0e1a 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeName.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/node/StorageNodeName.java
@@ -30,6 +30,10 @@ public final class StorageNodeName {
     
     private final String name;
     
+    public StorageNodeName(final String hostname, final int port, final String 
username) {
+        name = String.format("%s_%s_%s", hostname, port, username);
+    }
+    
     @Override
     public boolean equals(final Object obj) {
         return obj instanceof StorageNodeName && ((StorageNodeName) 
obj).name.equalsIgnoreCase(name);
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java
index e5c6144e3f9..2bb78e1275e 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapperUtils.java
@@ -55,7 +55,7 @@ public final class StorageUnitNodeMapperUtils {
     private static StorageUnitNodeMapper fromDataSource(final String 
storageUnitName, final DataSource dataSource) {
         DataSourcePoolProperties props = 
DataSourcePoolPropertiesCreator.create(dataSource);
         String url = 
props.getConnectionPropertySynonyms().getStandardProperties().get("url").toString();
-        return new StorageUnitNodeMapper(storageUnitName, new 
StorageNode(storageUnitName, url));
+        return new StorageUnitNodeMapper(storageUnitName, new StorageNode(new 
StorageNodeName(storageUnitName), url));
     }
     
     /**
@@ -77,24 +77,21 @@ public final class StorageUnitNodeMapperUtils {
         Map<String, Object> standardProps = 
props.getConnectionPropertySynonyms().getStandardProperties();
         String url = standardProps.get("url").toString();
         boolean isInstanceConnectionAvailable = new 
DatabaseTypeRegistry(DatabaseTypeFactory.get(url)).getDialectDatabaseMetaData().isInstanceConnectionAvailable();
-        String storageNodeName = getStorageNodeName(storageUnitName, url, 
standardProps.get("username").toString(), isInstanceConnectionAvailable);
+        StorageNodeName storageNodeName = getStorageNodeName(storageUnitName, 
url, standardProps.get("username").toString(), isInstanceConnectionAvailable);
         return createStorageUnitNodeMapper(storageNodeName, storageUnitName, 
url, isInstanceConnectionAvailable);
     }
     
-    private static String getStorageNodeName(final String dataSourceName, 
final String url, final String username, final boolean 
isInstanceConnectionAvailable) {
+    private static StorageNodeName getStorageNodeName(final String 
dataSourceName, final String url, final String username, final boolean 
isInstanceConnectionAvailable) {
         try {
             JdbcUrl jdbcUrl = new StandardJdbcUrlParser().parse(url);
-            return isInstanceConnectionAvailable ? 
generateStorageNodeName(jdbcUrl.getHostname(), jdbcUrl.getPort(), username) : 
dataSourceName;
+            return isInstanceConnectionAvailable ? new 
StorageNodeName(jdbcUrl.getHostname(), jdbcUrl.getPort(), username) : new 
StorageNodeName(dataSourceName);
         } catch (final UnrecognizedDatabaseURLException ex) {
-            return dataSourceName;
+            return new StorageNodeName(dataSourceName);
         }
     }
     
-    private static String generateStorageNodeName(final String hostname, final 
int port, final String username) {
-        return String.format("%s_%s_%s", hostname, port, username);
-    }
-    
-    private static StorageUnitNodeMapper createStorageUnitNodeMapper(final 
String storageNodeName, final String storageUnitName, final String url, final 
boolean isInstanceConnectionAvailable) {
+    private static StorageUnitNodeMapper createStorageUnitNodeMapper(final 
StorageNodeName storageNodeName,
+                                                                     final 
String storageUnitName, final String url, final boolean 
isInstanceConnectionAvailable) {
         return isInstanceConnectionAvailable
                 ? new StorageUnitNodeMapper(storageUnitName, new 
StorageNode(storageNodeName, url, new 
StandardJdbcUrlParser().parse(url).getDatabase()))
                 : new StorageUnitNodeMapper(storageUnitName, new 
StorageNode(storageNodeName, url));
@@ -112,7 +109,7 @@ public final class StorageUnitNodeMapperUtils {
             Map<String, Object> standardProps = 
entry.getValue().getConnectionPropertySynonyms().getStandardProperties();
             String url = standardProps.get("url").toString();
             boolean isInstanceConnectionAvailable = new 
DatabaseTypeRegistry(DatabaseTypeFactory.get(url)).getDialectDatabaseMetaData().isInstanceConnectionAvailable();
-            StorageNodeName storageNodeName = new 
StorageNodeName(getStorageNodeName(entry.getKey(), url, 
standardProps.get("username").toString(), isInstanceConnectionAvailable));
+            StorageNodeName storageNodeName = 
getStorageNodeName(entry.getKey(), url, 
standardProps.get("username").toString(), isInstanceConnectionAvailable);
             result.putIfAbsent(storageNodeName, entry.getValue());
         }
         return result;

Reply via email to