From 42b5c419917191c4120eb35d8c0dad64ff82a95a Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 27 May 2024 01:21:23 +0800 Subject: [PATCH] Use CaseInsensitiveMap on ShardingSphereMetaData.databases --- .../infra/metadata/ShardingSphereMetaData.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java index c8e9ec52c10f2..8914271ab839b 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.infra.metadata; +import com.cedarsoftware.util.CaseInsensitiveMap; import lombok.Getter; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; @@ -32,7 +33,6 @@ import org.apache.shardingsphere.infra.rule.scope.GlobalRule.GlobalRuleChangedType; import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -55,13 +55,13 @@ public final class ShardingSphereMetaData { private final TemporaryConfigurationProperties temporaryProps; public ShardingSphereMetaData() { - this(new HashMap<>(), new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new Properties())); + this(new CaseInsensitiveMap<>(Collections.emptyMap(), new ConcurrentHashMap<>()), + new ResourceMetaData(Collections.emptyMap()), new RuleMetaData(Collections.emptyList()), new ConfigurationProperties(new Properties())); } public ShardingSphereMetaData(final Map databases, final ResourceMetaData globalResourceMetaData, final RuleMetaData globalRuleMetaData, final ConfigurationProperties props) { - this.databases = new ConcurrentHashMap<>(databases.size(), 1F); - databases.forEach((key, value) -> this.databases.put(key.toLowerCase(), value)); + this.databases = new CaseInsensitiveMap<>(Collections.emptyMap(), new ConcurrentHashMap<>(databases)); this.globalResourceMetaData = globalResourceMetaData; this.globalRuleMetaData = globalRuleMetaData; this.props = props; @@ -75,7 +75,7 @@ public ShardingSphereMetaData(final Map database * @return contains database from meta data or not */ public boolean containsDatabase(final String databaseName) { - return databases.containsKey(databaseName.toLowerCase()); + return databases.containsKey(databaseName); } /** @@ -85,7 +85,7 @@ public boolean containsDatabase(final String databaseName) { * @return meta data database */ public ShardingSphereDatabase getDatabase(final String databaseName) { - return databases.get(databaseName.toLowerCase()); + return databases.get(databaseName); } /** @@ -97,7 +97,7 @@ public ShardingSphereDatabase getDatabase(final String databaseName) { */ public void addDatabase(final String databaseName, final DatabaseType protocolType, final ConfigurationProperties props) { ShardingSphereDatabase database = ShardingSphereDatabase.create(databaseName, protocolType, props); - databases.put(database.getName().toLowerCase(), database); + databases.put(database.getName(), database); globalRuleMetaData.getRules().forEach(each -> ((GlobalRule) each).refresh(databases, GlobalRuleChangedType.DATABASE_CHANGED)); } @@ -107,7 +107,7 @@ public void addDatabase(final String databaseName, final DatabaseType protocolTy * @param databaseName database name */ public void dropDatabase(final String databaseName) { - cleanResources(databases.remove(databaseName.toLowerCase())); + cleanResources(databases.remove(databaseName)); } @SneakyThrows(Exception.class)