Skip to content

Commit

Permalink
Use ShardingSphereMetaDataIdentifier on ShardingSphereSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Nov 30, 2024
1 parent 6e0d74e commit eff4700
Showing 1 changed file with 15 additions and 13 deletions.
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 Down

0 comments on commit eff4700

Please sign in to comment.