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 ShardingSphereMetaDataIdentifier on ShardingSphereSchema #33847

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
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 @@ -18,12 +18,14 @@
package org.apache.shardingsphere.infra.metadata.database.schema.model;

import lombok.Getter;
import org.apache.shardingsphere.infra.metadata.identifier.ShardingSphereMetaDataIdentifier;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
* ShardingSphere schema.
Expand All @@ -33,9 +35,9 @@ public final class ShardingSphereSchema {
@Getter
private final String name;

private final Map<String, ShardingSphereTable> tables;
private final Map<ShardingSphereMetaDataIdentifier, ShardingSphereTable> tables;

private final Map<String, ShardingSphereView> views;
private final Map<ShardingSphereMetaDataIdentifier, ShardingSphereView> views;

@SuppressWarnings("CollectionWithoutInitialCapacity")
public ShardingSphereSchema(final String name) {
Expand All @@ -48,8 +50,8 @@ public ShardingSphereSchema(final String name, final Collection<ShardingSphereTa
this.name = name;
this.tables = new ConcurrentHashMap<>(tables.size(), 1F);
this.views = new ConcurrentHashMap<>(views.size(), 1F);
tables.forEach(each -> this.tables.put(each.getName().toLowerCase(), each));
views.forEach(each -> this.views.put(each.getName().toLowerCase(), each));
tables.forEach(each -> this.tables.put(new ShardingSphereMetaDataIdentifier(each.getName()), each));
views.forEach(each -> this.views.put(new ShardingSphereMetaDataIdentifier(each.getName()), each));
}

/**
Expand All @@ -58,7 +60,7 @@ public ShardingSphereSchema(final String name, final Collection<ShardingSphereTa
* @return all table names
*/
public Collection<String> getAllTableNames() {
return tables.keySet();
return tables.keySet().stream().map(ShardingSphereMetaDataIdentifier::getValue).collect(Collectors.toSet());
}

/**
Expand All @@ -77,7 +79,7 @@ public Collection<ShardingSphereTable> getAllTables() {
* @return contains table or not
*/
public boolean containsTable(final String tableName) {
return tables.containsKey(tableName.toLowerCase());
return tables.containsKey(new ShardingSphereMetaDataIdentifier(tableName));
}

/**
Expand All @@ -87,7 +89,7 @@ public boolean containsTable(final String tableName) {
* @return table
*/
public ShardingSphereTable getTable(final String tableName) {
return tables.get(tableName.toLowerCase());
return tables.get(new ShardingSphereMetaDataIdentifier(tableName));
}

/**
Expand All @@ -96,7 +98,7 @@ public ShardingSphereTable getTable(final String tableName) {
* @param table table
*/
public void putTable(final ShardingSphereTable table) {
tables.put(table.getName().toLowerCase(), table);
tables.put(new ShardingSphereMetaDataIdentifier(table.getName()), table);
}

/**
Expand All @@ -105,7 +107,7 @@ public void putTable(final ShardingSphereTable table) {
* @param tableName table name
*/
public void removeTable(final String tableName) {
tables.remove(tableName.toLowerCase());
tables.remove(new ShardingSphereMetaDataIdentifier(tableName));
}

/**
Expand All @@ -124,7 +126,7 @@ public Collection<ShardingSphereView> getAllViews() {
* @return contains view or not
*/
public boolean containsView(final String viewName) {
return views.containsKey(viewName.toLowerCase());
return views.containsKey(new ShardingSphereMetaDataIdentifier(viewName));
}

/**
Expand All @@ -134,7 +136,7 @@ public boolean containsView(final String viewName) {
* @return view
*/
public ShardingSphereView getView(final String viewName) {
return views.get(viewName.toLowerCase());
return views.get(new ShardingSphereMetaDataIdentifier(viewName));
}

/**
Expand All @@ -143,7 +145,7 @@ public ShardingSphereView getView(final String viewName) {
* @param view view
*/
public void putView(final ShardingSphereView view) {
views.put(view.getName().toLowerCase(), view);
views.put(new ShardingSphereMetaDataIdentifier(view.getName()), view);
}

/**
Expand All @@ -152,7 +154,7 @@ public void putView(final ShardingSphereView view) {
* @param viewName view name
*/
public void removeView(final String viewName) {
views.remove(viewName.toLowerCase());
views.remove(new ShardingSphereMetaDataIdentifier(viewName));
}

/**
Expand All @@ -172,7 +174,7 @@ public boolean containsIndex(final String tableName, final String indexName) {
* @param tableName table name
* @return column names
*/
public List<String> getAllColumnNames(final String tableName) {
public Collection<String> getAllColumnNames(final String tableName) {
return containsTable(tableName) ? getTable(tableName).getColumnNames() : Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static Map<String, Set<String>> parseTableExpressionWithAllTables(final
Map<String, Set<String>> result = new HashMap<>(database.getSchemas().size(), 1F);
for (Entry<String, ShardingSphereSchema> entry : database.getSchemas().entrySet()) {
if (!systemSchemas.contains(entry.getKey())) {
entry.getValue().getAllTableNames().forEach(tableName -> result.computeIfAbsent(entry.getKey(), ignored -> new HashSet<>()).add(tableName));
entry.getValue().getAllTableNames().forEach(each -> result.computeIfAbsent(entry.getKey(), ignored -> new HashSet<>()).add(each));
}

}
Expand All @@ -91,7 +91,7 @@ private static Map<String, Set<String>> parseTableExpressionWithAllSchema(final
Map<String, Set<String>> result = new HashMap<>(database.getSchemas().size(), 1F);
for (Entry<String, ShardingSphereSchema> entry : database.getSchemas().entrySet()) {
if (!systemSchemas.contains(entry.getKey())) {
entry.getValue().getAllTableNames().stream().filter(tableName -> tableName.equals(table.getTable())).findFirst()
entry.getValue().getAllTableNames().stream().filter(each -> each.equals(table.getTable())).findFirst()
.ifPresent(optional -> result.computeIfAbsent(entry.getKey(), ignored -> new HashSet<>()).add(optional));
}
}
Expand Down
Loading