This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 4d69c3e9225 Use ShardingSphereMetaDataIdentifier on
ShardingSphereSchema (#33847)
4d69c3e9225 is described below
commit 4d69c3e9225bca1ddde05a89c16e39c271dda9fc
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Nov 30 17:03:15 2024 +0800
Use ShardingSphereMetaDataIdentifier on ShardingSphereSchema (#33847)
* Refactor ShardingSphereSchema
* Use ShardingSphereMetaDataIdentifier on ShardingSphereSchema
---
.../schema/model/ShardingSphereSchema.java | 30 ++++++++++++----------
.../pipeline/cdc/util/CDCSchemaTableUtils.java | 4 +--
2 files changed, 18 insertions(+), 16 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java
index 5966c808059..36e21e16ccf 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/model/ShardingSphereSchema.java
@@ -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.
@@ -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) {
@@ -48,8 +50,8 @@ public final class ShardingSphereSchema {
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));
}
/**
@@ -58,7 +60,7 @@ public final class ShardingSphereSchema {
* @return all table names
*/
public Collection<String> getAllTableNames() {
- return tables.keySet();
+ return
tables.keySet().stream().map(ShardingSphereMetaDataIdentifier::getValue).collect(Collectors.toSet());
}
/**
@@ -77,7 +79,7 @@ public final class ShardingSphereSchema {
* @return contains table or not
*/
public boolean containsTable(final String tableName) {
- return tables.containsKey(tableName.toLowerCase());
+ return tables.containsKey(new
ShardingSphereMetaDataIdentifier(tableName));
}
/**
@@ -87,7 +89,7 @@ public final class ShardingSphereSchema {
* @return table
*/
public ShardingSphereTable getTable(final String tableName) {
- return tables.get(tableName.toLowerCase());
+ return tables.get(new ShardingSphereMetaDataIdentifier(tableName));
}
/**
@@ -96,7 +98,7 @@ public final class ShardingSphereSchema {
* @param table table
*/
public void putTable(final ShardingSphereTable table) {
- tables.put(table.getName().toLowerCase(), table);
+ tables.put(new ShardingSphereMetaDataIdentifier(table.getName()),
table);
}
/**
@@ -105,7 +107,7 @@ public final class ShardingSphereSchema {
* @param tableName table name
*/
public void removeTable(final String tableName) {
- tables.remove(tableName.toLowerCase());
+ tables.remove(new ShardingSphereMetaDataIdentifier(tableName));
}
/**
@@ -124,7 +126,7 @@ public final class ShardingSphereSchema {
* @return contains view or not
*/
public boolean containsView(final String viewName) {
- return views.containsKey(viewName.toLowerCase());
+ return views.containsKey(new
ShardingSphereMetaDataIdentifier(viewName));
}
/**
@@ -134,7 +136,7 @@ public final class ShardingSphereSchema {
* @return view
*/
public ShardingSphereView getView(final String viewName) {
- return views.get(viewName.toLowerCase());
+ return views.get(new ShardingSphereMetaDataIdentifier(viewName));
}
/**
@@ -143,7 +145,7 @@ public final class ShardingSphereSchema {
* @param view view
*/
public void putView(final ShardingSphereView view) {
- views.put(view.getName().toLowerCase(), view);
+ views.put(new ShardingSphereMetaDataIdentifier(view.getName()), view);
}
/**
@@ -152,7 +154,7 @@ public final class ShardingSphereSchema {
* @param viewName view name
*/
public void removeView(final String viewName) {
- views.remove(viewName.toLowerCase());
+ views.remove(new ShardingSphereMetaDataIdentifier(viewName));
}
/**
@@ -172,7 +174,7 @@ public final class ShardingSphereSchema {
* @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();
}
diff --git
a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
index be6fcb8150b..95bc0727ec5 100644
---
a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
+++
b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
@@ -80,7 +80,7 @@ public final class CDCSchemaTableUtils {
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));
}
}
@@ -91,7 +91,7 @@ public final class CDCSchemaTableUtils {
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));
}
}