Skip to content

Commit 4d69c3e

Browse files
authored
Use ShardingSphereMetaDataIdentifier on ShardingSphereSchema (#33847)
* Refactor ShardingSphereSchema * Use ShardingSphereMetaDataIdentifier on ShardingSphereSchema
1 parent 9c757d1 commit 4d69c3e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

Diff for: infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
package org.apache.shardingsphere.infra.metadata.database.schema.model;
1919

2020
import lombok.Getter;
21+
import org.apache.shardingsphere.infra.metadata.identifier.ShardingSphereMetaDataIdentifier;
2122

2223
import java.util.Collection;
2324
import java.util.Collections;
2425
import java.util.List;
2526
import java.util.Map;
2627
import java.util.concurrent.ConcurrentHashMap;
28+
import java.util.stream.Collectors;
2729

2830
/**
2931
* ShardingSphere schema.
@@ -33,9 +35,9 @@ public final class ShardingSphereSchema {
3335
@Getter
3436
private final String name;
3537

36-
private final Map<String, ShardingSphereTable> tables;
38+
private final Map<ShardingSphereMetaDataIdentifier, ShardingSphereTable> tables;
3739

38-
private final Map<String, ShardingSphereView> views;
40+
private final Map<ShardingSphereMetaDataIdentifier, ShardingSphereView> views;
3941

4042
@SuppressWarnings("CollectionWithoutInitialCapacity")
4143
public ShardingSphereSchema(final String name) {
@@ -48,8 +50,8 @@ public ShardingSphereSchema(final String name, final Collection<ShardingSphereTa
4850
this.name = name;
4951
this.tables = new ConcurrentHashMap<>(tables.size(), 1F);
5052
this.views = new ConcurrentHashMap<>(views.size(), 1F);
51-
tables.forEach(each -> this.tables.put(each.getName().toLowerCase(), each));
52-
views.forEach(each -> this.views.put(each.getName().toLowerCase(), each));
53+
tables.forEach(each -> this.tables.put(new ShardingSphereMetaDataIdentifier(each.getName()), each));
54+
views.forEach(each -> this.views.put(new ShardingSphereMetaDataIdentifier(each.getName()), each));
5355
}
5456

5557
/**
@@ -58,7 +60,7 @@ public ShardingSphereSchema(final String name, final Collection<ShardingSphereTa
5860
* @return all table names
5961
*/
6062
public Collection<String> getAllTableNames() {
61-
return tables.keySet();
63+
return tables.keySet().stream().map(ShardingSphereMetaDataIdentifier::getValue).collect(Collectors.toSet());
6264
}
6365

6466
/**
@@ -77,7 +79,7 @@ public Collection<ShardingSphereTable> getAllTables() {
7779
* @return contains table or not
7880
*/
7981
public boolean containsTable(final String tableName) {
80-
return tables.containsKey(tableName.toLowerCase());
82+
return tables.containsKey(new ShardingSphereMetaDataIdentifier(tableName));
8183
}
8284

8385
/**
@@ -87,7 +89,7 @@ public boolean containsTable(final String tableName) {
8789
* @return table
8890
*/
8991
public ShardingSphereTable getTable(final String tableName) {
90-
return tables.get(tableName.toLowerCase());
92+
return tables.get(new ShardingSphereMetaDataIdentifier(tableName));
9193
}
9294

9395
/**
@@ -96,7 +98,7 @@ public ShardingSphereTable getTable(final String tableName) {
9698
* @param table table
9799
*/
98100
public void putTable(final ShardingSphereTable table) {
99-
tables.put(table.getName().toLowerCase(), table);
101+
tables.put(new ShardingSphereMetaDataIdentifier(table.getName()), table);
100102
}
101103

102104
/**
@@ -105,7 +107,7 @@ public void putTable(final ShardingSphereTable table) {
105107
* @param tableName table name
106108
*/
107109
public void removeTable(final String tableName) {
108-
tables.remove(tableName.toLowerCase());
110+
tables.remove(new ShardingSphereMetaDataIdentifier(tableName));
109111
}
110112

111113
/**
@@ -124,7 +126,7 @@ public Collection<ShardingSphereView> getAllViews() {
124126
* @return contains view or not
125127
*/
126128
public boolean containsView(final String viewName) {
127-
return views.containsKey(viewName.toLowerCase());
129+
return views.containsKey(new ShardingSphereMetaDataIdentifier(viewName));
128130
}
129131

130132
/**
@@ -134,7 +136,7 @@ public boolean containsView(final String viewName) {
134136
* @return view
135137
*/
136138
public ShardingSphereView getView(final String viewName) {
137-
return views.get(viewName.toLowerCase());
139+
return views.get(new ShardingSphereMetaDataIdentifier(viewName));
138140
}
139141

140142
/**
@@ -143,7 +145,7 @@ public ShardingSphereView getView(final String viewName) {
143145
* @param view view
144146
*/
145147
public void putView(final ShardingSphereView view) {
146-
views.put(view.getName().toLowerCase(), view);
148+
views.put(new ShardingSphereMetaDataIdentifier(view.getName()), view);
147149
}
148150

149151
/**
@@ -152,7 +154,7 @@ public void putView(final ShardingSphereView view) {
152154
* @param viewName view name
153155
*/
154156
public void removeView(final String viewName) {
155-
views.remove(viewName.toLowerCase());
157+
views.remove(new ShardingSphereMetaDataIdentifier(viewName));
156158
}
157159

158160
/**
@@ -172,7 +174,7 @@ public boolean containsIndex(final String tableName, final String indexName) {
172174
* @param tableName table name
173175
* @return column names
174176
*/
175-
public List<String> getAllColumnNames(final String tableName) {
177+
public Collection<String> getAllColumnNames(final String tableName) {
176178
return containsTable(tableName) ? getTable(tableName).getColumnNames() : Collections.emptyList();
177179
}
178180

Diff for: kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java

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

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

0 commit comments

Comments
 (0)