This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 9a2061ae73a Use CaseInsensitiveMap on ShardingSphereMetaData.databases
(#31408)
9a2061ae73a is described below
commit 9a2061ae73a6f585a73ea5595ce8b6f88b961f85
Author: Liang Zhang <[email protected]>
AuthorDate: Mon May 27 02:21:16 2024 +0800
Use CaseInsensitiveMap on ShardingSphereMetaData.databases (#31408)
---
.../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 c8e9ec52c10..8914271ab83 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;
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<String, ShardingSphereDatabase>
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 final class ShardingSphereMetaData {
* @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 final class ShardingSphereMetaData {
* @return meta data database
*/
public ShardingSphereDatabase getDatabase(final String databaseName) {
- return databases.get(databaseName.toLowerCase());
+ return databases.get(databaseName);
}
/**
@@ -97,7 +97,7 @@ public final class ShardingSphereMetaData {
*/
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 final class ShardingSphereMetaData {
* @param databaseName database name
*/
public void dropDatabase(final String databaseName) {
- cleanResources(databases.remove(databaseName.toLowerCase()));
+ cleanResources(databases.remove(databaseName));
}
@SneakyThrows(Exception.class)