Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CaseInsensitiveMap on ShardingSphereMetaData.databases #31408

Merged
merged 1 commit into from
May 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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