From 0c38b28cba7f4d89954f8fef44853c633a43b97f Mon Sep 17 00:00:00 2001 From: zhangliang Date: Wed, 27 Sep 2023 23:09:24 +0800 Subject: [PATCH 1/3] Refactor StorageUnitNodeMapper --- .../database/resource/unit/StorageUnitNodeMapper.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java index cce0b4490bb6f..9c7840b66b125 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java @@ -44,14 +44,14 @@ public StorageUnitNodeMapper(final String name, final StorageNode storageNode, f @Override public boolean equals(final Object obj) { if (obj instanceof StorageUnitNodeMapper) { - StorageUnitNodeMapper storageUnitNodeMapper = (StorageUnitNodeMapper) obj; - return storageUnitNodeMapper.name.equalsIgnoreCase(name) && storageUnitNodeMapper.storageNode.equals(storageNode) && isSameCatalog(storageUnitNodeMapper); + StorageUnitNodeMapper mapper = (StorageUnitNodeMapper) obj; + return mapper.name.equalsIgnoreCase(name) && mapper.storageNode.equals(storageNode) && isSameCatalog(mapper); } return false; } - private boolean isSameCatalog(final StorageUnitNodeMapper storageUnitNodeMapper) { - return null == catalog ? null == storageUnitNodeMapper : catalog.equalsIgnoreCase(storageUnitNodeMapper.getCatalog()); + private boolean isSameCatalog(final StorageUnitNodeMapper mapper) { + return null != catalog && catalog.equalsIgnoreCase(mapper.getCatalog()); } @Override From 2fdab36fd901659fccbbb61f677650b76b90d537 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Wed, 27 Sep 2023 23:27:37 +0800 Subject: [PATCH 2/3] Refactor StorageUnitNodeMapper --- .../database/resource/unit/StorageUnitNodeMapper.java | 8 ++++---- .../resource/unit/StorageUnitNodeMapperUtils.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java index 9c7840b66b125..2bb51fe98fa7a 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java @@ -33,12 +33,12 @@ public final class StorageUnitNodeMapper { private final StorageNode storageNode; - private final String catalog; - private final String url; + private final String catalog; + public StorageUnitNodeMapper(final String name, final StorageNode storageNode, final String url) { - this(name, storageNode, null, url); + this(name, storageNode, url, null); } @Override @@ -51,7 +51,7 @@ public boolean equals(final Object obj) { } private boolean isSameCatalog(final StorageUnitNodeMapper mapper) { - return null != catalog && catalog.equalsIgnoreCase(mapper.getCatalog()); + return null == catalog && null == mapper.getCatalog() || null != catalog && catalog.equalsIgnoreCase(mapper.getCatalog()); } @Override 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 f016401f34ce0..14a7790a8885b 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 @@ -95,7 +95,7 @@ private static String generateStorageNodeName(final String hostname, final int p private static StorageUnitNodeMapper createStorageUnitNodeMapper(final StorageNode storageNode, final String storageUnitName, final String url, final boolean isInstanceConnectionAvailable) { return isInstanceConnectionAvailable - ? new StorageUnitNodeMapper(storageUnitName, storageNode, new StandardJdbcUrlParser().parse(url).getDatabase(), url) + ? new StorageUnitNodeMapper(storageUnitName, storageNode, url, new StandardJdbcUrlParser().parse(url).getDatabase()) : new StorageUnitNodeMapper(storageUnitName, storageNode, url); } From 62aa61cb3daaae22ab39c1d885d7f6c9fa582c1c Mon Sep 17 00:00:00 2001 From: zhangliang Date: Wed, 27 Sep 2023 23:31:54 +0800 Subject: [PATCH 3/3] Remove useless equals and hashcode on StorageUnitNodeMapper --- .../resource/unit/StorageUnitNodeMapper.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java index 2bb51fe98fa7a..97f6b4d6d3be9 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/resource/unit/StorageUnitNodeMapper.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.infra.metadata.database.resource.unit; -import com.google.common.base.Objects; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; @@ -40,22 +39,4 @@ public final class StorageUnitNodeMapper { public StorageUnitNodeMapper(final String name, final StorageNode storageNode, final String url) { this(name, storageNode, url, null); } - - @Override - public boolean equals(final Object obj) { - if (obj instanceof StorageUnitNodeMapper) { - StorageUnitNodeMapper mapper = (StorageUnitNodeMapper) obj; - return mapper.name.equalsIgnoreCase(name) && mapper.storageNode.equals(storageNode) && isSameCatalog(mapper); - } - return false; - } - - private boolean isSameCatalog(final StorageUnitNodeMapper mapper) { - return null == catalog && null == mapper.getCatalog() || null != catalog && catalog.equalsIgnoreCase(mapper.getCatalog()); - } - - @Override - public int hashCode() { - return Objects.hashCode(name.toUpperCase(), storageNode.getName().toUpperCase(), null == catalog ? null : catalog.toUpperCase()); - } }