Skip to content

Commit

Permalink
Use CaseInsensitiveMap on ShardingSphereMetaData.databases (#31408)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored May 26, 2024
1 parent ed15cf9 commit 9a2061a
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -75,7 +75,7 @@ public ShardingSphereMetaData(final Map<String, ShardingSphereDatabase> database
* @return contains database from meta data or not
*/
public boolean containsDatabase(final String databaseName) {
return databases.containsKey(databaseName.toLowerCase());
return databases.containsKey(databaseName);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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));
}

Expand All @@ -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)
Expand Down

0 comments on commit 9a2061a

Please sign in to comment.