This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 b445a51c973 Remove TableNamesMapper. (#30743)
b445a51c973 is described below
commit b445a51c973dfb2ea15a71a697718f9cff27ae2a
Author: Cong Hu <[email protected]>
AuthorDate: Wed Apr 3 15:37:58 2024 +0800
Remove TableNamesMapper. (#30743)
* Remove TableNamesMapper.
* CaseInsensitiveIdentifier support null identifier.
---
.../broadcast/rule/BroadcastRule.java | 6 +-
....java => BroadcastTableNamesRuleAttribute.java} | 25 ++++----
...a => BroadcastTableNamesRuleAttributeTest.java} | 10 +--
.../attribute/EncryptTableMapperRuleAttribute.java | 17 ++---
.../EncryptTableMapperRuleAttributeTest.java | 6 +-
.../query/EncryptCountResultRowBuilder.java | 2 +-
.../attribute/MaskTableMapperRuleAttribute.java | 19 +++---
.../MaskTableMapperRuleAttributeTest.java | 6 +-
.../handler/query/MaskCountResultRowBuilder.java | 2 +-
.../shardingsphere/sharding/rule/ShardingRule.java | 4 +-
...e.java => ShardingTableNamesRuleAttribute.java} | 42 ++++++------
...va => ShardingTableNamesRuleAttributeTest.java} | 14 ++--
.../statement/dml/SelectStatementContext.java | 2 +-
.../statement/dml/SelectStatementContextTest.java | 2 +-
.../caseinsensitive/CaseInsensitiveIdentifier.java | 5 +-
.../schema/builder/GenericSchemaBuilder.java | 2 +-
.../attribute/table/TableMapperRuleAttribute.java | 13 ++--
.../rule/attribute/table/TableNamesMapper.java | 68 --------------------
.../type/table/TableNamesMapperTest.java | 75 ----------------------
.../refresher/util/TableRefreshUtils.java | 2 +-
.../single/rule/SingleExportableRuleAttribute.java | 2 +-
.../rule/SingleMutableDataNodeRuleAttribute.java | 4 +-
.../rule/SingleTableMapperRuleAttribute.java | 19 +++---
.../single/util/SingleTableLoadUtils.java | 8 +--
.../datanode/SingleTableDataNodeLoaderTest.java | 2 +-
.../shardingsphere/single/rule/SingleRuleTest.java | 26 ++++----
.../rule/SingleTableMapperRuleAttributeTest.java | 6 +-
.../query/ShowUnloadedSingleTableExecutor.java | 2 +-
.../handler/query/SingleCountResultRowBuilder.java | 2 +-
.../handler/update/UnloadSingleTableExecutor.java | 4 +-
30 files changed, 132 insertions(+), 265 deletions(-)
diff --git
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
index aa9f95f7275..663fcc13ae9 100644
---
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
+++
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java
@@ -20,11 +20,11 @@ package org.apache.shardingsphere.broadcast.rule;
import lombok.Getter;
import
org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
import
org.apache.shardingsphere.broadcast.rule.attribute.BroadcastDataNodeRuleAttribute;
-import
org.apache.shardingsphere.broadcast.rule.attribute.BroadcastTableMapperRuleAttribute;
+import
org.apache.shardingsphere.broadcast.rule.attribute.BroadcastTableNamesRuleAttribute;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.rule.scope.DatabaseRule;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
import
org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute;
+import org.apache.shardingsphere.infra.rule.scope.DatabaseRule;
import javax.sql.DataSource;
import java.util.Collection;
@@ -56,7 +56,7 @@ public final class BroadcastRule implements DatabaseRule {
this.databaseName = databaseName;
dataSourceNames = getAggregatedDataSourceNames(dataSources,
builtRules);
tables = createBroadcastTables(config.getTables());
- attributes = new RuleAttributes(new
BroadcastDataNodeRuleAttribute(dataSourceNames, tables), new
BroadcastTableMapperRuleAttribute(tables));
+ attributes = new RuleAttributes(new
BroadcastDataNodeRuleAttribute(dataSourceNames, tables), new
BroadcastTableNamesRuleAttribute(tables));
}
private Collection<String> getAggregatedDataSourceNames(final Map<String,
DataSource> dataSources, final Collection<ShardingSphereRule> builtRules) {
diff --git
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableMapperRuleAttribute.java
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableNamesRuleAttribute.java
similarity index 62%
rename from
features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableMapperRuleAttribute.java
rename to
features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableNamesRuleAttribute.java
index c124d27264f..88522da25ce 100644
---
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableMapperRuleAttribute.java
+++
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableNamesRuleAttribute.java
@@ -17,35 +17,36 @@
package org.apache.shardingsphere.broadcast.rule.attribute;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
-import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper;
import java.util.Collection;
+import java.util.Collections;
/**
* Broadcast table mapper rule attribute.
*/
-public final class BroadcastTableMapperRuleAttribute implements
TableMapperRuleAttribute {
+public final class BroadcastTableNamesRuleAttribute implements
TableMapperRuleAttribute {
- private final TableNamesMapper logicalTableMapper;
+ private final CaseInsensitiveSet<String> logicalTableNames;
- public BroadcastTableMapperRuleAttribute(final Collection<String> tables) {
- logicalTableMapper = new TableNamesMapper();
- tables.forEach(logicalTableMapper::put);
+ public BroadcastTableNamesRuleAttribute(final Collection<String> tables) {
+ logicalTableNames = new CaseInsensitiveSet<>();
+ logicalTableNames.addAll(tables);
}
@Override
- public TableNamesMapper getLogicTableMapper() {
- return logicalTableMapper;
+ public Collection<String> getLogicTableNames() {
+ return logicalTableNames;
}
@Override
- public TableNamesMapper getDistributedTableMapper() {
- return logicalTableMapper;
+ public Collection<String> getDistributedTableNames() {
+ return logicalTableNames;
}
@Override
- public TableNamesMapper getEnhancedTableMapper() {
- return new TableNamesMapper();
+ public Collection<String> getEnhancedTableNames() {
+ return Collections.emptySet();
}
}
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableMapperRuleAttributeTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableNamesRuleAttributeTest.java
similarity index 75%
rename from
features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableMapperRuleAttributeTest.java
rename to
features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableNamesRuleAttributeTest.java
index 7c731618f61..fde65387d75 100644
---
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableMapperRuleAttributeTest.java
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastTableNamesRuleAttributeTest.java
@@ -25,22 +25,22 @@ import java.util.LinkedList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class BroadcastTableMapperRuleAttributeTest {
+class BroadcastTableNamesRuleAttributeTest {
- private final BroadcastTableMapperRuleAttribute ruleAttribute = new
BroadcastTableMapperRuleAttribute(Collections.singleton("foo_tbl"));
+ private final BroadcastTableNamesRuleAttribute ruleAttribute = new
BroadcastTableNamesRuleAttribute(Collections.singleton("foo_tbl"));
@Test
void assertGetLogicTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getLogicTableNames()),
is(Collections.singletonList("foo_tbl")));
}
@Test
void assertGetDistributedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getDistributedTableNames()),
is(Collections.singletonList("foo_tbl")));
}
@Test
void assertGetEnhancedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()),
is(Collections.emptyList()));
+ assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableNames()),
is(Collections.emptyList()));
}
}
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttribute.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttribute.java
index d736d2812f9..835400a8308 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttribute.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttribute.java
@@ -17,36 +17,37 @@
package org.apache.shardingsphere.encrypt.rule.attribute;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
-import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper;
import java.util.Collection;
+import java.util.Collections;
/**
* Encrypt table mapper rule attribute.
*/
public final class EncryptTableMapperRuleAttribute implements
TableMapperRuleAttribute {
- private final TableNamesMapper logicalTableMapper;
+ private final CaseInsensitiveSet<String> logicalTableMapper;
public EncryptTableMapperRuleAttribute(final
Collection<EncryptTableRuleConfiguration> tables) {
- logicalTableMapper = new TableNamesMapper();
-
tables.stream().map(EncryptTableRuleConfiguration::getName).forEach(logicalTableMapper::put);
+ logicalTableMapper = new CaseInsensitiveSet<>();
+
tables.stream().map(EncryptTableRuleConfiguration::getName).forEach(logicalTableMapper::add);
}
@Override
- public TableNamesMapper getLogicTableMapper() {
+ public Collection<String> getLogicTableNames() {
return logicalTableMapper;
}
@Override
- public TableNamesMapper getDistributedTableMapper() {
- return new TableNamesMapper();
+ public Collection<String> getDistributedTableNames() {
+ return Collections.emptySet();
}
@Override
- public TableNamesMapper getEnhancedTableMapper() {
+ public Collection<String> getEnhancedTableNames() {
return logicalTableMapper;
}
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttributeTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttributeTest.java
index 5096b75568d..b6aaf583978 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttributeTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/attribute/EncryptTableMapperRuleAttributeTest.java
@@ -32,16 +32,16 @@ class EncryptTableMapperRuleAttributeTest {
@Test
void assertGetLogicTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getLogicTableNames()),
is(Collections.singletonList("foo_tbl")));
}
@Test
void assertGetDistributedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()),
is(Collections.emptyList()));
+ assertThat(new LinkedList<>(ruleAttribute.getDistributedTableNames()),
is(Collections.emptyList()));
}
@Test
void assertGetEnhancedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableNames()),
is(Collections.singletonList("foo_tbl")));
}
}
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptCountResultRowBuilder.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptCountResultRowBuilder.java
index 1df4336476b..2ce092fe965 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptCountResultRowBuilder.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptCountResultRowBuilder.java
@@ -33,7 +33,7 @@ public final class EncryptCountResultRowBuilder implements
CountResultRowBuilder
@Override
public Collection<LocalDataQueryResultRow> generateRows(final EncryptRule
rule, final String databaseName) {
return Collections.singleton(
- new LocalDataQueryResultRow("encrypt", databaseName,
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames().size()));
+ new LocalDataQueryResultRow("encrypt", databaseName,
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().size()));
}
@Override
diff --git
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttribute.java
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttribute.java
index f9128320844..9f7813bae42 100644
---
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttribute.java
+++
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttribute.java
@@ -17,36 +17,37 @@
package org.apache.shardingsphere.mask.rule.attribute;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
-import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper;
import
org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import java.util.Collection;
+import java.util.Collections;
/**
* Mask table mapper rule attribute.
*/
public final class MaskTableMapperRuleAttribute implements
TableMapperRuleAttribute {
- private final TableNamesMapper logicalTableMapper;
+ private final CaseInsensitiveSet<String> logicalTableMapper;
public MaskTableMapperRuleAttribute(final
Collection<MaskTableRuleConfiguration> tables) {
- logicalTableMapper = new TableNamesMapper();
-
tables.stream().map(MaskTableRuleConfiguration::getName).forEach(logicalTableMapper::put);
+ logicalTableMapper = new CaseInsensitiveSet<>();
+
tables.stream().map(MaskTableRuleConfiguration::getName).forEach(logicalTableMapper::add);
}
@Override
- public TableNamesMapper getLogicTableMapper() {
+ public Collection<String> getLogicTableNames() {
return logicalTableMapper;
}
@Override
- public TableNamesMapper getDistributedTableMapper() {
- return new TableNamesMapper();
+ public Collection<String> getDistributedTableNames() {
+ return Collections.emptySet();
}
@Override
- public TableNamesMapper getEnhancedTableMapper() {
- return new TableNamesMapper();
+ public Collection<String> getEnhancedTableNames() {
+ return Collections.emptySet();
}
}
diff --git
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttributeTest.java
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttributeTest.java
index 907c2bc6a20..692dc24e170 100644
---
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttributeTest.java
+++
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/attribute/MaskTableMapperRuleAttributeTest.java
@@ -32,16 +32,16 @@ class MaskTableMapperRuleAttributeTest {
@Test
void assertGetLogicTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getLogicTableNames()),
is(Collections.singletonList("foo_tbl")));
}
@Test
void assertGetDistributedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()),
is(Collections.emptyList()));
+ assertThat(new LinkedList<>(ruleAttribute.getDistributedTableNames()),
is(Collections.emptyList()));
}
@Test
void assertGetEnhancedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()),
is(Collections.emptyList()));
+ assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableNames()),
is(Collections.emptyList()));
}
}
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/MaskCountResultRowBuilder.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/MaskCountResultRowBuilder.java
index 881f27d0869..d5c6244d3b0 100644
---
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/MaskCountResultRowBuilder.java
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/MaskCountResultRowBuilder.java
@@ -32,7 +32,7 @@ public final class MaskCountResultRowBuilder implements
CountResultRowBuilder<Ma
@Override
public Collection<LocalDataQueryResultRow> generateRows(final MaskRule
rule, final String databaseName) {
- return Collections.singleton(new LocalDataQueryResultRow("mask",
databaseName,
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames().size()));
+ return Collections.singleton(new LocalDataQueryResultRow("mask",
databaseName,
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().size()));
}
@Override
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index 37682624221..139d2bc1c08 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -53,7 +53,7 @@ import
org.apache.shardingsphere.sharding.exception.metadata.DuplicateSharingAct
import
org.apache.shardingsphere.sharding.exception.metadata.InvalidBindingTablesException;
import
org.apache.shardingsphere.sharding.exception.metadata.ShardingTableRuleNotFoundException;
import
org.apache.shardingsphere.sharding.rule.attribute.ShardingDataNodeRuleAttribute;
-import
org.apache.shardingsphere.sharding.rule.attribute.ShardingTableMapperRuleAttribute;
+import
org.apache.shardingsphere.sharding.rule.attribute.ShardingTableNamesRuleAttribute;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
import org.apache.shardingsphere.sharding.spi.ShardingAuditAlgorithm;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -142,7 +142,7 @@ public final class ShardingRule implements DatabaseRule {
((InstanceContextAware)
defaultKeyGenerateAlgorithm).setInstanceContext(instanceContext);
}
shardingCache = null == ruleConfig.getShardingCache() ? null : new
ShardingCache(ruleConfig.getShardingCache(), this);
- attributes = new RuleAttributes(new
ShardingDataNodeRuleAttribute(shardingTables), new
ShardingTableMapperRuleAttribute(shardingTables.values()));
+ attributes = new RuleAttributes(new
ShardingDataNodeRuleAttribute(shardingTables), new
ShardingTableNamesRuleAttribute(shardingTables.values()));
}
private void validateUniqueActualDataNodesInTableRules() {
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableMapperRuleAttribute.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableNamesRuleAttribute.java
similarity index 53%
rename from
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableMapperRuleAttribute.java
rename to
features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableNamesRuleAttribute.java
index edadc3399c7..535a3d848bf 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableMapperRuleAttribute.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableNamesRuleAttribute.java
@@ -17,9 +17,9 @@
package org.apache.shardingsphere.sharding.rule.attribute;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
-import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper;
import org.apache.shardingsphere.sharding.rule.ShardingTable;
import java.util.Collection;
@@ -27,46 +27,46 @@ import java.util.Collection;
/**
* Sharding table mapper rule attribute.
*/
-public final class ShardingTableMapperRuleAttribute implements
TableMapperRuleAttribute {
+public final class ShardingTableNamesRuleAttribute implements
TableMapperRuleAttribute {
- private final TableNamesMapper logicalTableMapper;
+ private final CaseInsensitiveSet<String> logicalTableNames;
- private final TableNamesMapper actualTableMapper;
+ private final CaseInsensitiveSet<String> actualTableNames;
- public ShardingTableMapperRuleAttribute(final Collection<ShardingTable>
shardingTables) {
- logicalTableMapper = createLogicalTableMapper(shardingTables);
- actualTableMapper = createActualTableMapper(shardingTables);
+ public ShardingTableNamesRuleAttribute(final Collection<ShardingTable>
shardingTables) {
+ logicalTableNames = createLogicalTableNames(shardingTables);
+ actualTableNames = createActualTableNames(shardingTables);
}
- private TableNamesMapper createLogicalTableMapper(final
Collection<ShardingTable> shardingTables) {
- TableNamesMapper result = new TableNamesMapper();
- shardingTables.forEach(each -> result.put(each.getLogicTable()));
+ private CaseInsensitiveSet<String> createLogicalTableNames(final
Collection<ShardingTable> shardingTables) {
+ CaseInsensitiveSet<String> result = new CaseInsensitiveSet<>();
+ shardingTables.forEach(each -> result.add(each.getLogicTable()));
return result;
}
- private TableNamesMapper createActualTableMapper(final
Collection<ShardingTable> shardingTables) {
- TableNamesMapper result = new TableNamesMapper();
- shardingTables.stream().flatMap(each ->
each.getActualDataNodes().stream()).map(DataNode::getTableName).forEach(result::put);
+ private CaseInsensitiveSet<String> createActualTableNames(final
Collection<ShardingTable> shardingTables) {
+ CaseInsensitiveSet<String> result = new CaseInsensitiveSet<>();
+ shardingTables.stream().flatMap(each ->
each.getActualDataNodes().stream()).map(DataNode::getTableName).forEach(result::add);
return result;
}
@Override
- public TableNamesMapper getLogicTableMapper() {
- return logicalTableMapper;
+ public Collection<String> getLogicTableNames() {
+ return logicalTableNames;
}
@Override
- public TableNamesMapper getActualTableMapper() {
- return actualTableMapper;
+ public Collection<String> getActualTableNames() {
+ return actualTableNames;
}
@Override
- public TableNamesMapper getDistributedTableMapper() {
- return logicalTableMapper;
+ public Collection<String> getDistributedTableNames() {
+ return logicalTableNames;
}
@Override
- public TableNamesMapper getEnhancedTableMapper() {
- return logicalTableMapper;
+ public Collection<String> getEnhancedTableNames() {
+ return logicalTableNames;
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableMapperRuleAttributeTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableNamesRuleAttributeTest.java
similarity index 78%
rename from
features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableMapperRuleAttributeTest.java
rename to
features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableNamesRuleAttributeTest.java
index c2ea672660e..d11f39d42bb 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableMapperRuleAttributeTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/attribute/ShardingTableNamesRuleAttributeTest.java
@@ -30,35 +30,35 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-class ShardingTableMapperRuleAttributeTest {
+class ShardingTableNamesRuleAttributeTest {
- private ShardingTableMapperRuleAttribute ruleAttribute;
+ private ShardingTableNamesRuleAttribute ruleAttribute;
@BeforeEach
void setUp() {
ShardingTable shardingTable = mock(ShardingTable.class);
when(shardingTable.getLogicTable()).thenReturn("foo_tbl");
when(shardingTable.getActualDataNodes()).thenReturn(Collections.singletonList(new
DataNode("foo_ds.foo_tbl_0")));
- ruleAttribute = new
ShardingTableMapperRuleAttribute(Collections.singleton(shardingTable));
+ ruleAttribute = new
ShardingTableNamesRuleAttribute(Collections.singleton(shardingTable));
}
@Test
void assertGetLogicTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getLogicTableNames()),
is(Collections.singletonList("foo_tbl")));
}
@Test
void assertGetActualTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getActualTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl_0")));
+ assertThat(new LinkedList<>(ruleAttribute.getActualTableNames()),
is(Collections.singletonList("foo_tbl_0")));
}
@Test
void assertGetDistributedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getDistributedTableNames()),
is(Collections.singletonList("foo_tbl")));
}
@Test
void assertGetEnhancedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableNames()),
is(Collections.singletonList("foo_tbl")));
}
}
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java
index 6ee546274dd..d1600b2bcd0 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java
@@ -130,7 +130,7 @@ public final class SelectStatementContext extends
CommonSQLStatementContext impl
private boolean isContainsEnhancedTable(final ShardingSphereMetaData
metaData, final String databaseName, final Collection<String> tableNames) {
for (TableMapperRuleAttribute each :
getTableMapperRuleAttributes(metaData, databaseName)) {
for (String tableName : tableNames) {
- if (each.getEnhancedTableMapper().contains(tableName)) {
+ if (each.getEnhancedTableNames().contains(tableName)) {
return true;
}
}
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java
index 756fd5d3b16..db56a65ea23 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java
@@ -121,7 +121,7 @@ class SelectStatementContextTest {
private ShardingSphereDatabase mockDatabase() {
ShardingSphereDatabase result = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
TableMapperRuleAttribute ruleAttribute =
mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS);
-
when(ruleAttribute.getEnhancedTableMapper().contains("t_order")).thenReturn(true);
+
when(ruleAttribute.getEnhancedTableNames().contains("t_order")).thenReturn(true);
when(result.getRuleMetaData().getAttributes(TableMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute));
return result;
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/caseinsensitive/CaseInsensitiveIdentifier.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/caseinsensitive/CaseInsensitiveIdentifier.java
index 3a5c448264a..c3b433434c6 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/caseinsensitive/CaseInsensitiveIdentifier.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/caseinsensitive/CaseInsensitiveIdentifier.java
@@ -30,11 +30,14 @@ public final class CaseInsensitiveIdentifier {
private final CaseInsensitiveString original;
public CaseInsensitiveIdentifier(final String identifier) {
- original = new CaseInsensitiveString(identifier);
+ original = null == identifier ? null : new
CaseInsensitiveString(identifier);
}
@Override
public String toString() {
+ if (null == original) {
+ return null;
+ }
return original.toString();
}
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java
index 6d314f5e6d4..1b706d06251 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilder.java
@@ -87,7 +87,7 @@ public final class GenericSchemaBuilder {
private static Collection<String> getAllTableNames(final
Collection<ShardingSphereRule> rules) {
Collection<String> result = new HashSet<>();
for (ShardingSphereRule each : rules) {
-
each.getAttributes().findAttribute(TableMapperRuleAttribute.class).ifPresent(mapperRule
-> result.addAll(mapperRule.getLogicTableMapper().getTableNames()));
+
each.getAttributes().findAttribute(TableMapperRuleAttribute.class).ifPresent(mapperRule
-> result.addAll(mapperRule.getLogicTableNames()));
}
return result;
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableMapperRuleAttribute.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableMapperRuleAttribute.java
index af9ccd8a80a..2c57f73f142 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableMapperRuleAttribute.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableMapperRuleAttribute.java
@@ -19,6 +19,9 @@ package org.apache.shardingsphere.infra.rule.attribute.table;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute;
+import java.util.Collection;
+import java.util.Collections;
+
/**
* Table mapper rule attribute.
*/
@@ -29,15 +32,15 @@ public interface TableMapperRuleAttribute extends
RuleAttribute {
*
* @return logic table mapper
*/
- TableNamesMapper getLogicTableMapper();
+ Collection<String> getLogicTableNames();
/**
* Get actual table mapper.
*
* @return actual table mapper
*/
- default TableNamesMapper getActualTableMapper() {
- return new TableNamesMapper();
+ default Collection<String> getActualTableNames() {
+ return Collections.emptySet();
}
/**
@@ -45,12 +48,12 @@ public interface TableMapperRuleAttribute extends
RuleAttribute {
*
* @return distributed table mapper
*/
- TableNamesMapper getDistributedTableMapper();
+ Collection<String> getDistributedTableNames();
/**
* Get enhanced table mapper.
*
* @return enhanced table mapper
*/
- TableNamesMapper getEnhancedTableMapper();
+ Collection<String> getEnhancedTableNames();
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableNamesMapper.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableNamesMapper.java
deleted file mode 100644
index 81a5b1b7c29..00000000000
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableNamesMapper.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.attribute.table;
-
-import com.cedarsoftware.util.CaseInsensitiveMap;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Table names mapper.
- */
-public final class TableNamesMapper {
-
- private final Map<String, String> lowerCaseTableNames = new
CaseInsensitiveMap<>();
-
- /**
- * Judge whether contains table or not.
- *
- * @param tableName table name
- * @return whether contains table or not
- */
- public boolean contains(final String tableName) {
- return lowerCaseTableNames.containsKey(tableName);
- }
-
- /**
- * Get original table names.
- *
- * @return original table names
- */
- public Collection<String> getTableNames() {
- return lowerCaseTableNames.values();
- }
-
- /**
- * Put.
- *
- * @param tableName table name
- */
- public void put(final String tableName) {
- lowerCaseTableNames.put(tableName, tableName);
- }
-
- /**
- * Remove.
- *
- * @param tableName table name
- */
- public void remove(final String tableName) {
- lowerCaseTableNames.remove(tableName);
- }
-}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableNamesMapperTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableNamesMapperTest.java
deleted file mode 100644
index 21ed27bb59c..00000000000
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableNamesMapperTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.rule.identifier.type.table;
-
-import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-class TableNamesMapperTest {
-
- private TableNamesMapper tableNamesMapper;
-
- @BeforeEach
- void setUp() {
- tableNamesMapper = new TableNamesMapper();
- }
-
- @Test
- void assertContainsTable() {
- tableNamesMapper.put("foo_table");
- tableNamesMapper.put("FoO_TaBlE_2");
- assertTrue(tableNamesMapper.contains("foo_table"));
- assertTrue(tableNamesMapper.contains("foo_table_2"));
- }
-
- @Test
- void assertGetTableNames() {
- tableNamesMapper.put("foo_table_1");
- tableNamesMapper.put("foo_table_2");
- Collection<String> actualTables = tableNamesMapper.getTableNames();
- assertThat(actualTables.size(), is(2));
- Iterator<String> iterator = actualTables.iterator();
- assertThat(iterator.next(), is("foo_table_1"));
- assertThat(iterator.next(), is("foo_table_2"));
- }
-
- @Test
- void assertRemove() {
- tableNamesMapper.put("foo_table_1");
- Collection<String> actualTables = tableNamesMapper.getTableNames();
- assertThat(actualTables.size(), is(1));
- tableNamesMapper.remove("foo_table_1");
- assertThat(actualTables.size(), is(0));
- }
-
- @Test
- void assertPut() {
- Collection<String> actualTables = tableNamesMapper.getTableNames();
- assertThat(actualTables.size(), is(0));
- tableNamesMapper.put("foo_table");
- assertThat(actualTables.size(), is(1));
- }
-}
diff --git
a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
index c5eee0ec321..048f25333e1 100644
---
a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
+++
b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/util/TableRefreshUtils.java
@@ -64,7 +64,7 @@ public final class TableRefreshUtils {
* @return whether single table
*/
public static boolean isSingleTable(final String tableName, final
ShardingSphereDatabase database) {
- return
database.getRuleMetaData().getAttributes(TableMapperRuleAttribute.class).stream().noneMatch(each
-> each.getDistributedTableMapper().contains(tableName));
+ return
database.getRuleMetaData().getAttributes(TableMapperRuleAttribute.class).stream().noneMatch(each
-> each.getDistributedTableNames().contains(tableName));
}
/**
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRuleAttribute.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRuleAttribute.java
index 97b312c7165..6cef0e2188e 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRuleAttribute.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRuleAttribute.java
@@ -34,6 +34,6 @@ public final class SingleExportableRuleAttribute implements
ExportableRuleAttrib
@Override
public Map<String, Object> getExportData() {
- return
Collections.singletonMap(ExportableConstants.EXPORT_SINGLE_TABLES,
tableMapperRuleAttribute.getLogicTableMapper().getTableNames());
+ return
Collections.singletonMap(ExportableConstants.EXPORT_SINGLE_TABLES,
tableMapperRuleAttribute.getLogicTableNames());
}
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRuleAttribute.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRuleAttribute.java
index 4ba2df409db..88988c45fcc 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRuleAttribute.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRuleAttribute.java
@@ -57,7 +57,7 @@ public final class SingleMutableDataNodeRuleAttribute
implements MutableDataNode
DataNode dataNode = new DataNode(dataSourceName, tableName);
dataNode.setSchemaName(schemaName);
dataNodes.add(dataNode);
- tableMapperRuleAttribute.getLogicTableMapper().put(tableName);
+ tableMapperRuleAttribute.getLogicTableNames().add(tableName);
addTableConfiguration(dataSourceName, schemaName, tableName);
}
}
@@ -95,7 +95,7 @@ public final class SingleMutableDataNodeRuleAttribute
implements MutableDataNode
}
if (dataNodes.isEmpty()) {
singleTableDataNodes.remove(tableName.toLowerCase());
- tableMapperRuleAttribute.getLogicTableMapper().remove(tableName);
+ tableMapperRuleAttribute.getLogicTableNames().remove(tableName);
}
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttribute.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttribute.java
index 2a4761f0f5b..9e9c5c30878 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttribute.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttribute.java
@@ -17,36 +17,37 @@
package org.apache.shardingsphere.single.rule;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
-import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper;
import java.util.Collection;
+import java.util.Collections;
/**
* Single table mapper rule attribute.
*/
public final class SingleTableMapperRuleAttribute implements
TableMapperRuleAttribute {
- private final TableNamesMapper logicTableMapper;
+ private final CaseInsensitiveSet<String> logicTableMapper;
public SingleTableMapperRuleAttribute(final
Collection<Collection<DataNode>> singleTableDataNodes) {
- logicTableMapper = new TableNamesMapper();
- singleTableDataNodes.forEach(each ->
logicTableMapper.put(each.iterator().next().getTableName()));
+ logicTableMapper = new CaseInsensitiveSet<>();
+ singleTableDataNodes.forEach(each ->
logicTableMapper.add(each.iterator().next().getTableName()));
}
@Override
- public TableNamesMapper getLogicTableMapper() {
+ public Collection<String> getLogicTableNames() {
return logicTableMapper;
}
@Override
- public TableNamesMapper getDistributedTableMapper() {
- return new TableNamesMapper();
+ public Collection<String> getDistributedTableNames() {
+ return Collections.emptySet();
}
@Override
- public TableNamesMapper getEnhancedTableMapper() {
- return new TableNamesMapper();
+ public Collection<String> getEnhancedTableNames() {
+ return Collections.emptySet();
}
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
index 7a1983582ca..dc0309e4570 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/util/SingleTableLoadUtils.java
@@ -88,8 +88,8 @@ public final class SingleTableLoadUtils {
for (ShardingSphereRule each : builtRules) {
Optional<TableMapperRuleAttribute> ruleAttribute =
each.getAttributes().findAttribute(TableMapperRuleAttribute.class);
if (ruleAttribute.isPresent()) {
-
result.addAll(ruleAttribute.get().getDistributedTableMapper().getTableNames());
-
result.addAll(ruleAttribute.get().getActualTableMapper().getTableNames());
+ result.addAll(ruleAttribute.get().getDistributedTableNames());
+ result.addAll(ruleAttribute.get().getActualTableNames());
}
}
return result;
@@ -108,10 +108,10 @@ public final class SingleTableLoadUtils {
if (!ruleAttribute.isPresent()) {
continue;
}
- if
(ruleAttribute.get().getEnhancedTableMapper().getTableNames().isEmpty() ||
!ruleAttribute.get().getDistributedTableMapper().getTableNames().isEmpty()) {
+ if (ruleAttribute.get().getEnhancedTableNames().isEmpty() ||
!ruleAttribute.get().getDistributedTableNames().isEmpty()) {
continue;
}
-
result.addAll(ruleAttribute.get().getEnhancedTableMapper().getTableNames());
+ result.addAll(ruleAttribute.get().getEnhancedTableNames());
}
return result;
}
diff --git
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
index e3fc84c690a..927baa2ac3d 100644
---
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
+++
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/datanode/SingleTableDataNodeLoaderTest.java
@@ -98,7 +98,7 @@ class SingleTableDataNodeLoaderTest {
void assertLoad() {
ShardingSphereRule builtRule = mock(ShardingSphereRule.class);
TableMapperRuleAttribute ruleAttribute =
mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS);
-
when(ruleAttribute.getDistributedTableMapper().getTableNames()).thenReturn(Arrays.asList("salary",
"employee", "student"));
+
when(ruleAttribute.getDistributedTableNames()).thenReturn(Arrays.asList("salary",
"employee", "student"));
when(builtRule.getAttributes()).thenReturn(new
RuleAttributes(ruleAttribute));
Map<String, Collection<DataNode>> actual =
SingleTableDataNodeLoader.load(DefaultDatabase.LOGIC_NAME, databaseType,
dataSourceMap, Collections.singleton(builtRule), configuredSingleTables);
assertFalse(actual.containsKey("employee"));
diff --git
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
index efca8756d5a..9d57e9c4335 100644
---
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
+++
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleRuleTest.java
@@ -24,9 +24,9 @@ import
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
import
org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute;
+import
org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute;
import
org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
@@ -104,8 +104,8 @@ class SingleRuleTest {
@Test
void assertGetSingleTableDataNodes() {
TableMapperRuleAttribute ruleAttribute =
mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS);
-
when(ruleAttribute.getDistributedTableMapper().getTableNames()).thenReturn(Collections.singletonList("t_order"));
-
when(ruleAttribute.getActualTableMapper().getTableNames()).thenReturn(Arrays.asList("t_order_0",
"t_order_1"));
+
when(ruleAttribute.getDistributedTableNames()).thenReturn(Collections.singletonList("t_order"));
+
when(ruleAttribute.getActualTableNames()).thenReturn(Arrays.asList("t_order_0",
"t_order_1"));
ShardingSphereRule builtRule = mock(ShardingSphereRule.class);
when(builtRule.getAttributes()).thenReturn(new
RuleAttributes(ruleAttribute));
SingleRule singleRule = new SingleRule(ruleConfig,
DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap,
Collections.singleton(builtRule));
@@ -119,8 +119,8 @@ class SingleRuleTest {
void assertGetSingleTableDataNodesWithUpperCase() {
ShardingSphereRule builtRule = mock(ShardingSphereRule.class);
TableMapperRuleAttribute ruleAttribute =
mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS);
-
when(ruleAttribute.getDistributedTableMapper().getTableNames()).thenReturn(Collections.singleton("T_ORDER"));
-
when(ruleAttribute.getActualTableMapper().getTableNames()).thenReturn(Arrays.asList("T_ORDER_0",
"T_ORDER_1"));
+
when(ruleAttribute.getDistributedTableNames()).thenReturn(Collections.singleton("T_ORDER"));
+
when(ruleAttribute.getActualTableNames()).thenReturn(Arrays.asList("T_ORDER_0",
"T_ORDER_1"));
when(builtRule.getAttributes()).thenReturn(new
RuleAttributes(ruleAttribute));
SingleRule singleRule = new SingleRule(ruleConfig,
DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap,
Collections.singleton(builtRule));
Map<String, Collection<DataNode>> actual =
singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes();
@@ -188,11 +188,11 @@ class SingleRuleTest {
tableNames.add(new QualifiedTable(DefaultDatabase.LOGIC_NAME,
"teacher"));
assertThat(singleRule.getSingleTables(tableNames).iterator().next().getSchemaName(),
is(DefaultDatabase.LOGIC_NAME));
assertThat(singleRule.getSingleTables(tableNames).iterator().next().getTableName(),
is("teacher"));
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("employee"));
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("student"));
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("t_order_0"));
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("t_order_1"));
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("teacher"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("employee"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("student"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("t_order_0"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("t_order_1"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("teacher"));
}
@Test
@@ -203,9 +203,9 @@ class SingleRuleTest {
Collection<QualifiedTable> tableNames = new LinkedList<>();
tableNames.add(new QualifiedTable(DefaultDatabase.LOGIC_NAME,
"employee"));
assertTrue(singleRule.getSingleTables(tableNames).isEmpty());
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("student"));
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("t_order_0"));
-
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().contains("t_order_1"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("student"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("t_order_0"));
+
assertTrue(singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().contains("t_order_1"));
}
@Test
diff --git
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttributeTest.java
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttributeTest.java
index 554611b4411..f4428af198f 100644
---
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttributeTest.java
+++
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttributeTest.java
@@ -32,16 +32,16 @@ class SingleTableMapperRuleAttributeTest {
@Test
void assertGetLogicTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()),
is(Collections.singletonList("foo_tbl")));
+ assertThat(new LinkedList<>(ruleAttribute.getLogicTableNames()),
is(Collections.singletonList("foo_tbl")));
}
@Test
void assertGetDistributedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()),
is(Collections.emptyList()));
+ assertThat(new LinkedList<>(ruleAttribute.getDistributedTableNames()),
is(Collections.emptyList()));
}
@Test
void assertGetEnhancedTableMapper() {
- assertThat(new
LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()),
is(Collections.emptyList()));
+ assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableNames()),
is(Collections.emptyList()));
}
}
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
index d1f9ccb3ff2..dde2bb2532e 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowUnloadedSingleTableExecutor.java
@@ -58,7 +58,7 @@ public final class ShowUnloadedSingleTableExecutor implements
DistSQLQueryExecut
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowUnloadedSingleTableStatement sqlStatement, final ContextManager
contextManager) {
Map<String, Collection<DataNode>> actualDataNodes =
getActualDataNodes(database);
- for (String each :
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames())
{
+ for (String each :
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames())
{
actualDataNodes.remove(each.toLowerCase());
}
return actualDataNodes.entrySet().stream().map(entry -> new
LocalDataQueryResultRow(entry.getKey(),
entry.getValue().iterator().next().getDataSourceName())).collect(Collectors.toList());
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/SingleCountResultRowBuilder.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/SingleCountResultRowBuilder.java
index 7588eb38c16..c809dcf6365 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/SingleCountResultRowBuilder.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/SingleCountResultRowBuilder.java
@@ -33,7 +33,7 @@ public final class SingleCountResultRowBuilder implements
CountResultRowBuilder<
@Override
public Collection<LocalDataQueryResultRow> generateRows(final SingleRule
rule, final String databaseName) {
return Collections.singleton(
- new LocalDataQueryResultRow("single", databaseName,
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames().size()));
+ new LocalDataQueryResultRow("single", databaseName,
rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames().size()));
}
@Override
diff --git
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
index 53a657b9b69..9af15441287 100644
---
a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
+++
b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
@@ -20,13 +20,13 @@ package
org.apache.shardingsphere.single.distsql.handler.update;
import com.google.common.base.Splitter;
import lombok.Setter;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.database.DatabaseRuleAlterExecutor;
-import
org.apache.shardingsphere.infra.exception.metadata.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.required.DistSQLExecutorCurrentRuleRequired;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException;
+import
org.apache.shardingsphere.infra.exception.metadata.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
import
org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute;
@@ -62,7 +62,7 @@ public final class UnloadSingleTableExecutor implements
DatabaseRuleAlterExecuto
}
Collection<String> allTables = getAllTableNames(database);
SingleRule singleRule =
database.getRuleMetaData().getSingleRule(SingleRule.class);
- Collection<String> singleTables =
singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames();
+ Collection<String> singleTables =
singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableNames();
for (String each : sqlStatement.getTables()) {
checkTableExist(allTables, each);
checkIsSingleTable(singleTables, each);