diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastDataNodeRule.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastDataNodeRuleAttribute.java similarity index 90% rename from features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastDataNodeRule.java rename to features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastDataNodeRuleAttribute.java index 508068d293ceb..2f8c0c551783f 100644 --- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastDataNodeRule.java +++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastDataNodeRuleAttribute.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.broadcast.rule; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.util.Collection; import java.util.Collections; @@ -27,15 +27,15 @@ import java.util.stream.Collectors; /** - * Broadcast data node rule. + * Broadcast data node rule attribute. */ -public final class BroadcastDataNodeRule implements DataNodeRule { +public final class BroadcastDataNodeRuleAttribute implements DataNodeRuleAttribute { private final Collection tables; private final Map> tableDataNodes; - public BroadcastDataNodeRule(final Collection dataSourceNames, final Collection tables) { + public BroadcastDataNodeRuleAttribute(final Collection dataSourceNames, final Collection tables) { this.tables = tables; tableDataNodes = tables.stream().collect(Collectors.toMap(String::toLowerCase, each -> generateDataNodes(each, dataSourceNames))); } 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 03551f1d9c4ba..c007efd936397 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,9 +20,9 @@ import lombok.Getter; import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +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 javax.sql.DataSource; import java.util.Collection; @@ -47,30 +47,30 @@ public final class BroadcastRule implements DatabaseRule { private final Collection dataSourceNames; - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public BroadcastRule(final BroadcastRuleConfiguration config, final String databaseName, final Map dataSources, final Collection builtRules) { configuration = config; this.databaseName = databaseName; dataSourceNames = getAggregatedDataSourceNames(dataSources, builtRules); tables = createBroadcastTables(config.getTables()); - ruleIdentifiers = new RuleIdentifiers(new BroadcastDataNodeRule(dataSourceNames, tables), new BroadcastTableMapperRule(tables)); + attributes = new RuleAttributes(new BroadcastDataNodeRuleAttribute(dataSourceNames, tables), new BroadcastTableMapperRuleAttribute(tables)); } private Collection getAggregatedDataSourceNames(final Map dataSources, final Collection builtRules) { Collection result = new LinkedList<>(dataSources.keySet()); for (ShardingSphereRule each : builtRules) { - Optional dataSourceMapperRule = each.getRuleIdentifiers().findIdentifier(DataSourceMapperRule.class); - if (dataSourceMapperRule.isPresent()) { - result = getAggregatedDataSourceNames(result, dataSourceMapperRule.get()); + Optional ruleAttribute = each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class); + if (ruleAttribute.isPresent()) { + result = getAggregatedDataSourceNames(result, ruleAttribute.get()); } } return result; } - private Collection getAggregatedDataSourceNames(final Collection dataSourceNames, final DataSourceMapperRule dataSourceMapperRule) { + private Collection getAggregatedDataSourceNames(final Collection dataSourceNames, final DataSourceMapperRuleAttribute ruleAttribute) { Collection result = new LinkedList<>(); - for (Entry> entry : dataSourceMapperRule.getDataSourceMapper().entrySet()) { + for (Entry> entry : ruleAttribute.getDataSourceMapper().entrySet()) { for (String each : entry.getValue()) { if (dataSourceNames.contains(each)) { dataSourceNames.remove(each); diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRule.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleAttribute.java similarity index 78% rename from features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRule.java rename to features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleAttribute.java index 1f6f0e3012517..b857755b87128 100644 --- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRule.java +++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleAttribute.java @@ -17,19 +17,19 @@ package org.apache.shardingsphere.broadcast.rule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableNamesMapper; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper; import java.util.Collection; /** - * Broadcast table mapper rule. + * Broadcast table mapper rule attribute. */ -public final class BroadcastTableMapperRule implements TableMapperRule { +public final class BroadcastTableMapperRuleAttribute implements TableMapperRuleAttribute { private final TableNamesMapper logicalTableMapper; - public BroadcastTableMapperRule(final Collection tables) { + public BroadcastTableMapperRuleAttribute(final Collection tables) { logicalTableMapper = new TableNamesMapper(); tables.forEach(logicalTableMapper::put); } diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java index 064f81b6716a8..c268e2d387fd9 100644 --- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java +++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java @@ -35,7 +35,7 @@ import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; @@ -90,7 +90,7 @@ void assertCreateBroadcastRouteContextWithSingleDataSource() throws SQLException BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class); when(currentConfig.getTables()).thenReturn(Collections.singleton("t_order")); BroadcastRule broadcastRule = new BroadcastRule(currentConfig, DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tmp_ds", new MockedDataSource(mockConnection())), Collections.emptyList()); - broadcastRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().put("t_order", Collections.singletonList(createDataNode("tmp_ds"))); + broadcastRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().put("t_order", Collections.singletonList(createDataNode("tmp_ds"))); ShardingSphereDatabase database = mockSingleDatabase(); RouteContext routeContext = new BroadcastSQLRouter().createRouteContext( createQueryContext(), mock(RuleMetaData.class), database, broadcastRule, new ConfigurationProperties(new Properties()), new ConnectionContext()); diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleAttributeTest.java similarity index 68% rename from features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleTest.java rename to features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleAttributeTest.java index cf5931b49b270..8e77614299fcc 100644 --- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleTest.java +++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/BroadcastTableMapperRuleAttributeTest.java @@ -25,22 +25,22 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class BroadcastTableMapperRuleTest { +class BroadcastTableMapperRuleAttributeTest { - private final BroadcastTableMapperRule tableMapperRule = new BroadcastTableMapperRule(Collections.singleton("foo_tbl")); + private final BroadcastTableMapperRuleAttribute ruleAttribute = new BroadcastTableMapperRuleAttribute(Collections.singleton("foo_tbl")); @Test void assertGetLogicTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } @Test void assertGetDistributedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getDistributedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } @Test void assertGetEnhancedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getEnhancedTableMapper().getTableNames()), is(Collections.emptyList())); + assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()), is(Collections.emptyList())); } } diff --git a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastImportRuleConfigurationProvider.java b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastImportRuleConfigurationProvider.java index e11ab484b9f6d..c3521156cbb88 100644 --- a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastImportRuleConfigurationProvider.java +++ b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/provider/BroadcastImportRuleConfigurationProvider.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; import java.util.LinkedHashMap; import java.util.Map.Entry; diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java index 3316e8dd1a59f..28ab77b167e20 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptRule.java @@ -26,8 +26,8 @@ import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import java.util.LinkedHashMap; @@ -48,7 +48,7 @@ public final class EncryptRule implements DatabaseRule { private final Map tables; @Getter - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public EncryptRule(final String databaseName, final EncryptRuleConfiguration ruleConfig) { this.databaseName = databaseName; @@ -59,7 +59,7 @@ public EncryptRule(final String databaseName, final EncryptRuleConfiguration rul each.getColumns().forEach(columnRuleConfig -> checkEncryptorType(columnRuleConfig, encryptors)); tables.put(each.getName().toLowerCase(), new EncryptTable(each, encryptors)); } - ruleIdentifiers = new RuleIdentifiers(new EncryptTableMapperRule(ruleConfig.getTables())); + attributes = new RuleAttributes(new EncryptTableMapperRuleAttribute(ruleConfig.getTables())); } private Map createEncryptors(final EncryptRuleConfiguration ruleConfig) { diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRule.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleAttribute.java similarity index 79% rename from features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRule.java rename to features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleAttribute.java index fc50d70d55ec3..5803d5efca640 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRule.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleAttribute.java @@ -18,19 +18,19 @@ package org.apache.shardingsphere.encrypt.rule; import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableNamesMapper; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper; import java.util.Collection; /** - * Encrypt table mapper rule. + * Encrypt table mapper rule attribute. */ -public final class EncryptTableMapperRule implements TableMapperRule { +public final class EncryptTableMapperRuleAttribute implements TableMapperRuleAttribute { private final TableNamesMapper logicalTableMapper; - public EncryptTableMapperRule(final Collection tables) { + public EncryptTableMapperRuleAttribute(final Collection tables) { logicalTableMapper = new TableNamesMapper(); tables.stream().map(EncryptTableRuleConfiguration::getName).forEach(logicalTableMapper::put); } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleAttributeTest.java similarity index 67% rename from features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleTest.java rename to features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleAttributeTest.java index d63310d4496a1..a56126eaf7ce4 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/EncryptTableMapperRuleAttributeTest.java @@ -26,22 +26,22 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class EncryptTableMapperRuleTest { +class EncryptTableMapperRuleAttributeTest { - private final EncryptTableMapperRule tableMapperRule = new EncryptTableMapperRule(Collections.singleton(new EncryptTableRuleConfiguration("foo_tbl", Collections.emptyList()))); + private final EncryptTableMapperRuleAttribute ruleAttribute = new EncryptTableMapperRuleAttribute(Collections.singleton(new EncryptTableRuleConfiguration("foo_tbl", Collections.emptyList()))); @Test void assertGetLogicTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } @Test void assertGetDistributedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getDistributedTableMapper().getTableNames()), is(Collections.emptyList())); + assertThat(new LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()), is(Collections.emptyList())); } @Test void assertGetEnhancedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getEnhancedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } } diff --git a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptImportRuleConfigurationProvider.java b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptImportRuleConfigurationProvider.java index 6f8efb580cf57..e23348acca6f8 100644 --- a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptImportRuleConfigurationProvider.java +++ b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptImportRuleConfigurationProvider.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import java.util.Collection; 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 ef9dd45f12727..1df4336476bff 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 @@ -20,7 +20,7 @@ import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; import org.apache.shardingsphere.encrypt.rule.EncryptRule; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import java.util.Collection; import java.util.Collections; @@ -33,7 +33,7 @@ public final class EncryptCountResultRowBuilder implements CountResultRowBuilder @Override public Collection generateRows(final EncryptRule rule, final String databaseName) { return Collections.singleton( - new LocalDataQueryResultRow("encrypt", databaseName, rule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().getTableNames().size())); + new LocalDataQueryResultRow("encrypt", databaseName, rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames().size())); } @Override diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java index 0969019e81312..0843fff0aa54e 100644 --- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java +++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskRule.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.mask.rule; import lombok.Getter; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration; import org.apache.shardingsphere.mask.spi.MaskAlgorithm; @@ -42,13 +42,13 @@ public final class MaskRule implements DatabaseRule { private final Map tables = new LinkedHashMap<>(); @Getter - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public MaskRule(final MaskRuleConfiguration ruleConfig) { configuration = ruleConfig; ruleConfig.getMaskAlgorithms().forEach((key, value) -> maskAlgorithms.put(key, TypedSPILoader.getService(MaskAlgorithm.class, value.getType(), value.getProps()))); ruleConfig.getTables().forEach(each -> tables.put(each.getName().toLowerCase(), new MaskTable(each))); - ruleIdentifiers = new RuleIdentifiers(new MaskTableMapperRule(ruleConfig.getTables())); + attributes = new RuleAttributes(new MaskTableMapperRuleAttribute(ruleConfig.getTables())); } /** diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRule.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleAttribute.java similarity index 80% rename from features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRule.java rename to features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleAttribute.java index 4e86c31a0ca18..9d9db290ab47a 100644 --- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRule.java +++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleAttribute.java @@ -17,20 +17,20 @@ package org.apache.shardingsphere.mask.rule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableNamesMapper; +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; /** - * Mask table mapper rule. + * Mask table mapper rule attribute. */ -public final class MaskTableMapperRule implements TableMapperRule { +public final class MaskTableMapperRuleAttribute implements TableMapperRuleAttribute { private final TableNamesMapper logicalTableMapper; - public MaskTableMapperRule(final Collection tables) { + public MaskTableMapperRuleAttribute(final Collection tables) { logicalTableMapper = new TableNamesMapper(); tables.stream().map(MaskTableRuleConfiguration::getName).forEach(logicalTableMapper::put); } diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleAttributeTest.java similarity index 68% rename from features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleTest.java rename to features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleAttributeTest.java index e3a56b6f0207b..4d6706e914477 100644 --- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleTest.java +++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/rule/MaskTableMapperRuleAttributeTest.java @@ -26,22 +26,22 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class MaskTableMapperRuleTest { +class MaskTableMapperRuleAttributeTest { - private final MaskTableMapperRule tableMapperRule = new MaskTableMapperRule(Collections.singleton(new MaskTableRuleConfiguration("foo_tbl", Collections.emptyList()))); + private final MaskTableMapperRuleAttribute ruleAttribute = new MaskTableMapperRuleAttribute(Collections.singleton(new MaskTableRuleConfiguration("foo_tbl", Collections.emptyList()))); @Test void assertGetLogicTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } @Test void assertGetDistributedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getDistributedTableMapper().getTableNames()), is(Collections.emptyList())); + assertThat(new LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()), is(Collections.emptyList())); } @Test void assertGetEnhancedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getEnhancedTableMapper().getTableNames()), is(Collections.emptyList())); + assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()), is(Collections.emptyList())); } } diff --git a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskImportRuleConfigurationProvider.java b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskImportRuleConfigurationProvider.java index 735910d7dc2f5..628ca2a59b795 100644 --- a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskImportRuleConfigurationProvider.java +++ b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskImportRuleConfigurationProvider.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration; import org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration; 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 ef9e1a16a8372..881f27d086998 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 @@ -19,7 +19,7 @@ import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.mask.rule.MaskRule; import java.util.Collection; @@ -32,7 +32,7 @@ public final class MaskCountResultRowBuilder implements CountResultRowBuilder generateRows(final MaskRule rule, final String databaseName) { - return Collections.singleton(new LocalDataQueryResultRow("mask", databaseName, rule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().getTableNames().size())); + return Collections.singleton(new LocalDataQueryResultRow("mask", databaseName, rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames().size())); } @Override diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java index 9c14311919a94..1cb58b9d7f919 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -90,8 +90,8 @@ private void checkWriteDataSourceNames(final String databaseName, final Map rules) { for (ShardingSphereRule each : rules) { - Optional dataSourceMapperRule = each.getRuleIdentifiers().findIdentifier(DataSourceMapperRule.class); - if (dataSourceMapperRule.isPresent() && dataSourceMapperRule.get().getDataSourceMapper().containsKey(datasourceName)) { + Optional ruleAttribute = each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class); + if (ruleAttribute.isPresent() && ruleAttribute.get().getDataSourceMapper().containsKey(datasourceName)) { return true; } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java index dba9961725089..98a6a3cabe5a3 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/datanode/ReadwriteSplittingDataNodeBuilder.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.datanode.DataNodeBuilder; import org.apache.shardingsphere.infra.datanode.DataNodeUtils; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule; @@ -36,7 +36,7 @@ public final class ReadwriteSplittingDataNodeBuilder implements DataNodeBuilder< public Collection build(final Collection dataNodes, final ReadwriteSplittingRule rule) { Collection result = new LinkedList<>(); for (DataNode each : dataNodes) { - result.addAll(DataNodeUtils.buildDataNode(each, rule.getRuleIdentifiers().getIdentifier(DataSourceMapperRule.class).getDataSourceMapper())); + result.addAll(DataNodeUtils.buildDataNode(each, rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper())); } return result; } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleAttribute.java similarity index 84% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRule.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleAttribute.java index de208e8941898..d181fc801d566 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRule.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleAttribute.java @@ -18,17 +18,17 @@ package org.apache.shardingsphere.readwritesplitting.rule; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import java.util.Collection; import java.util.HashMap; import java.util.Map; /** - * Readwrite-splitting data source mapper rule. + * Readwrite-splitting data source mapper rule attribute. */ @RequiredArgsConstructor -public final class ReadwriteSplittingDataSourceMapperRule implements DataSourceMapperRule { +public final class ReadwriteSplittingDataSourceMapperRuleAttribute implements DataSourceMapperRuleAttribute { private final Collection dataSourceRules; diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingExportableRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingExportableRuleAttribute.java similarity index 84% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingExportableRule.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingExportableRuleAttribute.java index bdd465e455d8d..9cbd5f1364b59 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingExportableRule.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingExportableRuleAttribute.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.readwritesplitting.rule; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants; +import org.apache.shardingsphere.infra.rule.attribute.exportable.ExportableRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableConstants; +import org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableItemConstants; import org.apache.shardingsphere.readwritesplitting.group.type.StaticReadwriteSplittingGroup; import java.util.HashMap; @@ -28,10 +28,10 @@ import java.util.Map; /** - * Readwrite-splitting exportable rule. + * Readwrite-splitting exportable rule attribute. */ @RequiredArgsConstructor -public final class ReadwriteSplittingExportableRule implements ExportableRule { +public final class ReadwriteSplittingExportableRuleAttribute implements ExportableRuleAttribute { private final Map dataSourceRules; diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java index c6c7d3abc51e8..4b6c711d1c985 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory; import org.apache.shardingsphere.infra.instance.InstanceContext; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -51,15 +51,15 @@ public final class ReadwriteSplittingRule implements DatabaseRule { private final Map dataSourceRules; @Getter - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public ReadwriteSplittingRule(final String databaseName, final ReadwriteSplittingRuleConfiguration ruleConfig, final InstanceContext instanceContext) { configuration = ruleConfig; loadBalancers = createLoadBalancers(ruleConfig); dataSourceRules = createDataSourceRules(ruleConfig); - ruleIdentifiers = new RuleIdentifiers( - new ReadwriteSplittingDataSourceMapperRule(dataSourceRules.values()), new ReadwriteSplittingStaticDataSourceRule(databaseName, dataSourceRules, instanceContext), - new ReadwriteSplittingExportableRule(dataSourceRules), new ReadwriteSplittingStorageConnectorReusableRule()); + attributes = new RuleAttributes( + new ReadwriteSplittingDataSourceMapperRuleAttribute(dataSourceRules.values()), new ReadwriteSplittingStaticDataSourceRuleAttribute(databaseName, dataSourceRules, instanceContext), + new ReadwriteSplittingExportableRuleAttribute(dataSourceRules), new ReadwriteSplittingStorageConnectorReusableRuleAttribute()); } private Map createLoadBalancers(final ReadwriteSplittingRuleConfiguration ruleConfig) { diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStaticDataSourceRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStaticDataSourceRuleAttribute.java similarity index 93% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStaticDataSourceRule.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStaticDataSourceRuleAttribute.java index 02c452f8e1eb2..bdfc23e8e157b 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStaticDataSourceRule.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStaticDataSourceRuleAttribute.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceDeletedEvent; @@ -32,8 +32,11 @@ import java.util.Map; import java.util.Map.Entry; +/** + * Readwrite-splitting static data source rule attribute. + */ @RequiredArgsConstructor -public final class ReadwriteSplittingStaticDataSourceRule implements StaticDataSourceRule { +public final class ReadwriteSplittingStaticDataSourceRuleAttribute implements StaticDataSourceRuleAttribute { private final String databaseName; diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStorageConnectorReusableRule.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStorageConnectorReusableRuleAttribute.java similarity index 80% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStorageConnectorReusableRule.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStorageConnectorReusableRuleAttribute.java index 72e8b5b2e38b9..2eb93397cffe6 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStorageConnectorReusableRule.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingStorageConnectorReusableRuleAttribute.java @@ -17,10 +17,10 @@ package org.apache.shardingsphere.readwritesplitting.rule; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.StorageConnectorReusableRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.StorageConnectorReusableRuleAttribute; /** - * Readwrite-splitting storage connector reusable rule. + * Readwrite-splitting storage connector reusable rule attribute. */ -public final class ReadwriteSplittingStorageConnectorReusableRule implements StorageConnectorReusableRule { +public final class ReadwriteSplittingStorageConnectorReusableRuleAttribute implements StorageConnectorReusableRuleAttribute { } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java index 08e7f201a1dc9..3fb85c1c339e5 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationCheckerTest.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -105,9 +105,9 @@ void assertCheckWhenConfigOtherRulesDatasource() { ReadwriteSplittingRuleConfiguration config = createContainsOtherRulesDatasourceConfig(); RuleConfigurationChecker checker = OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class, Collections.singleton(config.getClass())).get(config.getClass()); ShardingSphereRule rule = mock(ShardingSphereRule.class); - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class, RETURNS_DEEP_STUBS); - when(dataSourceMapperRule.getDataSourceMapper().containsKey("otherDatasourceName")).thenReturn(true); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class, RETURNS_DEEP_STUBS); + when(ruleAttribute.getDataSourceMapper().containsKey("otherDatasourceName")).thenReturn(true); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); checker.check("test", config, mockDataSources(), Collections.singleton(rule)); } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleAttributeTest.java similarity index 90% rename from features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleTest.java rename to features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleAttributeTest.java index fc1b2bd3c402f..edc7d4dcc721e 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRuleAttributeTest.java @@ -28,11 +28,11 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class ReadwriteSplittingDataSourceMapperRuleTest { +class ReadwriteSplittingDataSourceMapperRuleAttributeTest { @Test void assertGetDataSourceMapper() { - Map> actual = new ReadwriteSplittingDataSourceMapperRule(Collections.singleton(createReadwriteSplittingDataSourceRule())).getDataSourceMapper(); + Map> actual = new ReadwriteSplittingDataSourceMapperRuleAttribute(Collections.singleton(createReadwriteSplittingDataSourceRule())).getDataSourceMapper(); Map> expected = Collections.singletonMap("readwrite", Arrays.asList("write_ds", "read_ds_0", "read_ds_1")); assertThat(actual, is(expected)); } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java index 64ea660ce9d36..c7619a8c496a9 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent; @@ -70,7 +70,7 @@ private void assertDataSourceRule(final ReadwriteSplittingDataSourceRule actual) @Test void assertUpdateRuleStatusWithNotExistDataSource() { ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule(); - readwriteSplittingRule.getRuleIdentifiers().getIdentifier(StaticDataSourceRule.class).updateStatus(new StorageNodeDataSourceChangedEvent( + readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.singleton("read_ds"))); } @@ -78,7 +78,7 @@ void assertUpdateRuleStatusWithNotExistDataSource() { @Test void assertUpdateRuleStatus() { ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule(); - readwriteSplittingRule.getRuleIdentifiers().getIdentifier(StaticDataSourceRule.class).updateStatus(new StorageNodeDataSourceChangedEvent( + readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.singleton("read_ds_0"))); } @@ -86,10 +86,10 @@ void assertUpdateRuleStatus() { @Test void assertUpdateRuleStatusWithEnable() { ReadwriteSplittingRule readwriteSplittingRule = createReadwriteSplittingRule(); - readwriteSplittingRule.getRuleIdentifiers().getIdentifier(StaticDataSourceRule.class).updateStatus(new StorageNodeDataSourceChangedEvent( + readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.singleton("read_ds_0"))); - readwriteSplittingRule.getRuleIdentifiers().getIdentifier(StaticDataSourceRule.class).updateStatus(new StorageNodeDataSourceChangedEvent( + readwriteSplittingRule.getAttributes().getAttribute(StaticDataSourceRuleAttribute.class).updateStatus(new StorageNodeDataSourceChangedEvent( new QualifiedDatabase("readwrite_splitting_db.readwrite.read_ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.ENABLED))); assertThat(readwriteSplittingRule.getSingleDataSourceRule().getDisabledDataSourceNames(), is(Collections.emptySet())); } diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java index 04221bf6e6cb2..02c6c77981cbe 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java @@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -146,7 +146,7 @@ private static void checkDataSourcesExist(final String databaseName, final Colle private static Collection getLogicDataSources(final ShardingSphereDatabase database) { Collection result = new LinkedHashSet<>(); - for (DataSourceMapperRule each : database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)) { + for (DataSourceMapperRuleAttribute each : database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) { result.addAll(each.getDataSourceMapper().keySet()); } return result; diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingImportRuleConfigurationProvider.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingImportRuleConfigurationProvider.java index 0b3c55bdd01f6..f818b00811e64 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingImportRuleConfigurationProvider.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingImportRuleConfigurationProvider.java @@ -24,8 +24,8 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -73,7 +73,7 @@ private void checkDataSources(final ShardingSphereDatabase database, final Readw private Collection getLogicDataSources(final ShardingSphereDatabase database) { Collection result = new HashSet<>(); - for (DataSourceMapperRule each : database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)) { + for (DataSourceMapperRuleAttribute each : database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) { result.addAll(each.getDataSourceMapper().keySet()); } return result; diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingCountResultRowBuilder.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingCountResultRowBuilder.java index fcc0415a33618..6b22fefa230bd 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingCountResultRowBuilder.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ReadwriteSplittingCountResultRowBuilder.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule; import java.util.Collection; @@ -33,7 +33,7 @@ public final class ReadwriteSplittingCountResultRowBuilder implements CountResul @Override public Collection generateRows(final ReadwriteSplittingRule rule, final String databaseName) { return Collections.singleton( - new LocalDataQueryResultRow("readwrite_splitting", databaseName, rule.getRuleIdentifiers().getIdentifier(DataSourceMapperRule.class).getDataSourceMapper().size())); + new LocalDataQueryResultRow("readwrite_splitting", databaseName, rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper().size())); } @Override diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java index d80bcab07bd0e..92c9bf43780bb 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutor.java @@ -23,9 +23,9 @@ import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableItemConstants; +import org.apache.shardingsphere.infra.rule.attribute.exportable.ExportableRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableConstants; +import org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableItemConstants; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -68,7 +68,7 @@ public Collection getRows(final ShowReadwriteSplittingR @SuppressWarnings("unchecked") private Map> getExportableDataSourceMap(final ReadwriteSplittingRule rule) { - return (Map>) rule.getRuleIdentifiers().getIdentifier(ExportableRule.class).getExportData().get(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE); + return (Map>) rule.getAttributes().getAttribute(ExportableRuleAttribute.class).getExportData().get(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE); } private LocalDataQueryResultRow buildDataItem(final Map> exportableDataSourceMap, diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java index 4231f5879cc38..5f953ee549aa4 100644 --- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java +++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutor.java @@ -27,9 +27,9 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.distsql.statement.DropReadwriteSplittingRuleStatement; @@ -82,12 +82,12 @@ private Collection getInUsedResources() { if (each instanceof ReadwriteSplittingRule) { continue; } - Optional dataSourceMapperRule = each.getRuleIdentifiers().findIdentifier(DataSourceMapperRule.class); - if (!dataSourceMapperRule.isPresent()) { + Optional ruleAttribute = each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class); + if (!ruleAttribute.isPresent()) { continue; } Collection actualDataSources = new HashSet<>(); - dataSourceMapperRule.get().getDataSourceMapper().values().forEach(actualDataSources::addAll); + ruleAttribute.get().getDataSourceMapper().values().forEach(actualDataSources::addAll); result.addAll(actualDataSources); } for (ShardingSphereRule each : database.getRuleMetaData().getRules()) { @@ -95,9 +95,9 @@ private Collection getInUsedResources() { continue; } Collection actualDataNodes = new HashSet<>(); - Optional dataNodeRule = each.getRuleIdentifiers().findIdentifier(DataNodeRule.class); - if (dataNodeRule.isPresent()) { - dataNodeRule.get().getAllDataNodes().values().forEach(actualDataNodes::addAll); + Optional ruleAttribute = each.getAttributes().findAttribute(DataNodeRuleAttribute.class); + if (ruleAttribute.isPresent()) { + ruleAttribute.get().getAllDataNodes().values().forEach(actualDataNodes::addAll); result.addAll(actualDataNodes.stream().map(DataNode::getDataSourceName).collect(Collectors.toSet())); } } @@ -147,7 +147,7 @@ public boolean hasAnyOneToBeDropped(final DropReadwriteSplittingRuleStatement sq @Override public void operate(final DropReadwriteSplittingRuleStatement sqlStatement, final ShardingSphereDatabase database) { - for (StaticDataSourceRule each : database.getRuleMetaData().getRuleIdentifiers(StaticDataSourceRule.class)) { + for (StaticDataSourceRuleAttribute each : database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) { sqlStatement.getNames().forEach(each::cleanStorageNodeDataSource); } } diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java index d96bd83d5c293..ad93a39848f1b 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java @@ -22,13 +22,13 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableConstants; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowReadwriteSplittingRulesStatement; -import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingExportableRule; +import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingExportableRuleAttribute; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule; import org.apache.shardingsphere.test.util.PropertiesBuilder; import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; @@ -62,10 +62,10 @@ private ContextManager mockContextManager(final ReadwriteSplittingRuleConfigurat ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(result.getDatabase("foo_db")).thenReturn(database); ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class); - ReadwriteSplittingExportableRule exportableRule = mock(ReadwriteSplittingExportableRule.class); - when(exportableRule.getExportData()).thenReturn(createExportedData()); + ReadwriteSplittingExportableRuleAttribute ruleAttribute = mock(ReadwriteSplittingExportableRuleAttribute.class); + when(ruleAttribute.getExportData()).thenReturn(createExportedData()); when(rule.getConfiguration()).thenReturn(ruleConfig); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(exportableRule)); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); when(database.getRuleMetaData().findSingleRule(ReadwriteSplittingRule.class)).thenReturn(Optional.of(rule)); return result; } diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java index 51e60338313f6..c3a51fb414a4e 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/CreateReadwriteSplittingRuleExecutorTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.distsql.segment.AlgorithmSegment; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; @@ -98,9 +98,9 @@ void assertCheckSQLStatementWithoutExistedResources() { @Test void assertCheckSQLStatementWithDuplicateLogicResource() { - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds", Collections.singleton("ds_0"))); - when(database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)).thenReturn(Collections.singleton(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class); + when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds", Collections.singleton("ds_0"))); + when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); ReadwriteSplittingRuleSegment ruleSegment = new ReadwriteSplittingRuleSegment("duplicate_ds", "write_ds_0", Arrays.asList("read_ds_0", "read_ds_1"), new AlgorithmSegment(null, new Properties())); executor.setDatabase(database); @@ -148,9 +148,9 @@ void assertCheckSQLStatementWithIfNotExists() { @Test void assertUpdateSuccess() { - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class, RETURNS_DEEP_STUBS); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("ms_group", Collections.singleton("ds_0"))); - when(database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)).thenReturn(Collections.singleton(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class, RETURNS_DEEP_STUBS); + when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("ms_group", Collections.singleton("ds_0"))); + when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); ReadwriteSplittingRuleSegment staticSegment = new ReadwriteSplittingRuleSegment( "static_rule", "write_ds_0", Arrays.asList("read_ds_0", "read_ds_1"), new AlgorithmSegment("TEST", new Properties())); CreateReadwriteSplittingRuleStatement sqlStatement = createSQLStatement(false, staticSegment); diff --git a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java index a6b5ed7caf4f1..fedad50fb12da 100644 --- a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java +++ b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleExecutorTest.java @@ -23,9 +23,9 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration; import org.apache.shardingsphere.readwritesplitting.distsql.statement.DropReadwriteSplittingRuleStatement; @@ -80,12 +80,12 @@ void assertCheckSQLStatementWithIfExists() throws RuleDefinitionViolationExcepti @Test void assertCheckSQLStatementWithInUsed() throws RuleDefinitionViolationException { - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class); - when(database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)).thenReturn(Collections.singleton(dataSourceMapperRule)); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.getAllDataNodes()).thenReturn(Collections.singletonMap("foo_ds", Collections.singleton(new DataNode("readwrite_ds.tbl")))); + DataSourceMapperRuleAttribute dataSourceMapperRuleAttribute = mock(DataSourceMapperRuleAttribute.class); + when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(dataSourceMapperRuleAttribute)); + DataNodeRuleAttribute dataNodeRuleAttribute = mock(DataNodeRuleAttribute.class); + when(dataNodeRuleAttribute.getAllDataNodes()).thenReturn(Collections.singletonMap("foo_ds", Collections.singleton(new DataNode("readwrite_ds.tbl")))); ReadwriteSplittingRule rule = mock(ReadwriteSplittingRule.class); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + when(rule.getAttributes()).thenReturn(new RuleAttributes(dataNodeRuleAttribute)); when(database.getRuleMetaData().getRules()).thenReturn(Collections.singleton(rule)); executor.setDatabase(database); when(rule.getConfiguration()).thenReturn(createCurrentRuleConfiguration()); diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java index 9b20eebae409c..ffbd8fe6ebdc8 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/datanode/ShadowDataNodeBuilder.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.datanode.DataNodeBuilder; import org.apache.shardingsphere.infra.datanode.DataNodeUtils; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.shadow.constant.ShadowOrder; import org.apache.shardingsphere.shadow.rule.ShadowRule; @@ -36,7 +36,7 @@ public final class ShadowDataNodeBuilder implements DataNodeBuilder public Collection build(final Collection dataNodes, final ShadowRule rule) { Collection result = new LinkedList<>(); for (DataNode each : dataNodes) { - result.addAll(DataNodeUtils.buildDataNode(each, rule.getRuleIdentifiers().getIdentifier(DataSourceMapperRule.class).getDataSourceMapper())); + result.addAll(DataNodeUtils.buildDataNode(each, rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper())); } return result; } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowDataSourceMapperRule.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowDataSourceMapperRuleAttribute.java similarity index 87% rename from features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowDataSourceMapperRule.java rename to features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowDataSourceMapperRuleAttribute.java index dc5b13de7dfa9..7bd719248ca62 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowDataSourceMapperRule.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowDataSourceMapperRuleAttribute.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.shadow.rule; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import java.util.Collection; import java.util.LinkedHashMap; @@ -26,10 +26,10 @@ import java.util.Map; /** - * Shadow data source mapper rule. + * Shadow data source mapper rule attribute. */ @RequiredArgsConstructor -public final class ShadowDataSourceMapperRule implements DataSourceMapperRule { +public final class ShadowDataSourceMapperRuleAttribute implements DataSourceMapperRuleAttribute { private final Map shadowDataSourceMappings; diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java index b5f69229d05cb..fc46863b80aa7 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java @@ -19,8 +19,8 @@ import lombok.Getter; import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; @@ -56,7 +56,7 @@ public final class ShadowRule implements DatabaseRule { private final ShadowAlgorithm defaultShadowAlgorithm; @Getter - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public ShadowRule(final ShadowRuleConfiguration ruleConfig) { configuration = ruleConfig; @@ -67,7 +67,7 @@ public ShadowRule(final ShadowRuleConfiguration ruleConfig) { hintShadowAlgorithmNames.add(ruleConfig.getDefaultShadowAlgorithmName()); } initShadowTableRules(ruleConfig.getTables()); - ruleIdentifiers = new RuleIdentifiers(new ShadowDataSourceMapperRule(shadowDataSourceMappings)); + attributes = new RuleAttributes(new ShadowDataSourceMapperRuleAttribute(shadowDataSourceMappings)); } private void initShadowDataSourceMappings(final Collection dataSources) { diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java index abac9c7d8f985..034fde4387752 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/checker/ShadowRuleStatementChecker.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import java.util.Collection; import java.util.Collections; @@ -115,7 +115,7 @@ public static void checkDuplicatedWithLogicDataSource(final Collection t private static Collection getLogicDataSources(final ShardingSphereDatabase database) { Collection result = new LinkedHashSet<>(); - for (DataSourceMapperRule each : database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)) { + for (DataSourceMapperRuleAttribute each : database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) { result.addAll(each.getDataSourceMapper().keySet()); } return result; diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowImportRuleConfigurationProvider.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowImportRuleConfigurationProvider.java index c25295d0aa234..30de8d8521dd3 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowImportRuleConfigurationProvider.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowImportRuleConfigurationProvider.java @@ -24,8 +24,8 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.rule.ShadowRule; @@ -81,7 +81,7 @@ private Collection getRequiredResources(final ShadowRuleConfiguration cu private Collection getLogicDataSources(final ShardingSphereDatabase database) { Collection result = new LinkedHashSet<>(); - for (DataSourceMapperRule each : database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)) { + for (DataSourceMapperRuleAttribute each : database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) { result.addAll(each.getDataSourceMapper().keySet()); } return result; diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowCountResultRowBuilder.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowCountResultRowBuilder.java index 4fe0c0fe974eb..595aa2cfa480e 100644 --- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowCountResultRowBuilder.java +++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowCountResultRowBuilder.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.shadow.rule.ShadowRule; import java.util.Collection; @@ -32,7 +32,7 @@ public final class ShadowCountResultRowBuilder implements CountResultRowBuilder< @Override public Collection generateRows(final ShadowRule rule, final String databaseName) { - return Collections.singleton(new LocalDataQueryResultRow("shadow", databaseName, rule.getRuleIdentifiers().getIdentifier(DataSourceMapperRule.class).getDataSourceMapper().size())); + return Collections.singleton(new LocalDataQueryResultRow("shadow", databaseName, rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper().size())); } @Override diff --git a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleExecutorTest.java b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleExecutorTest.java index 4a6a7524062b5..1d265d89ad95c 100644 --- a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleExecutorTest.java +++ b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/update/CreateShadowRuleExecutorTest.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.distsql.segment.AlgorithmSegment; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration; @@ -93,9 +93,9 @@ void assertExecuteWithDuplicateRuleNameInMetaData() { @Test void assertExecuteWithDuplicateLogicResource() { - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class, RETURNS_DEEP_STUBS); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds", Collections.singleton("ds_0"))); - when(database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)).thenReturn(Collections.singleton(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class, RETURNS_DEEP_STUBS); + when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds", Collections.singleton("ds_0"))); + when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); executor.setDatabase(database); ShadowRuleSegment ruleSegment = new ShadowRuleSegment("duplicate_ds", null, null, null); assertThrows(InvalidRuleConfigurationException.class, () -> executor.checkBeforeUpdate(new CreateShadowRuleStatement(false, Collections.singleton(ruleSegment)))); diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviser.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviser.java index 434b0aa4508f7..379192c4a714e 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviser.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/reviser/constraint/ShardingConstraintReviser.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.database.core.metadata.data.model.ConstraintMetaData; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.constraint.ConstraintReviser; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sharding.rule.ShardingTable; @@ -42,7 +42,7 @@ public Optional revise(final String tableName, final Constra Optional logicIndexName = getLogicIndex(originalMetaData.getName(), each.getTableName()); if (logicIndexName.isPresent()) { return Optional.of(new ConstraintMetaData( - logicIndexName.get(), rule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).findLogicTableByActualTable(referencedTableName).orElse(referencedTableName))); + logicIndexName.get(), rule.getAttributes().getAttribute(DataNodeRuleAttribute.class).findLogicTableByActualTable(referencedTableName).orElse(referencedTableName))); } } return Optional.empty(); diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingDataNodeRule.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingDataNodeRuleAttribute.java similarity index 93% rename from features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingDataNodeRule.java rename to features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingDataNodeRuleAttribute.java index fe19f0a1bdbe7..b3e617a6fe55c 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingDataNodeRule.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingDataNodeRuleAttribute.java @@ -20,7 +20,7 @@ import com.cedarsoftware.util.CaseInsensitiveMap; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.util.Collection; import java.util.Collections; @@ -29,15 +29,15 @@ import java.util.Optional; /** - * Sharding data node rule. + * Sharding data node rule attribute. */ -public final class ShardingDataNodeRule implements DataNodeRule { +public final class ShardingDataNodeRuleAttribute implements DataNodeRuleAttribute { private final Map shardingTables; private final Map> tableDataNodes; - public ShardingDataNodeRule(final Map shardingTables) { + public ShardingDataNodeRuleAttribute(final Map shardingTables) { this.shardingTables = shardingTables; tableDataNodes = createShardingTableDataNodes(shardingTables); } 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 78395a134ca86..739912da655bb 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 @@ -34,8 +34,8 @@ import org.apache.shardingsphere.infra.instance.InstanceContextAware; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; @@ -114,7 +114,7 @@ public final class ShardingRule implements DatabaseRule { private final ShardingCache shardingCache; - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public ShardingRule(final ShardingRuleConfiguration ruleConfig, final Map dataSources, final InstanceContext instanceContext) { configuration = ruleConfig; @@ -141,7 +141,7 @@ public ShardingRule(final ShardingRuleConfiguration ruleConfig, final Map shardingTables) { + public ShardingTableMapperRuleAttribute(final Collection shardingTables) { logicalTableMapper = createLogicalTableMapper(shardingTables); actualTableMapper = createActualTableMapper(shardingTables); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataReviseEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataReviseEngineTest.java index 5588e53bebd90..ead7f28b81ca4 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataReviseEngineTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/ShardingMetaDataReviseEngineTest.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial; import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEngine; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.junit.jupiter.api.Test; @@ -58,9 +58,9 @@ void assertReviseWithKeyGenerateStrategy() { private ShardingRule mockShardingRule() { ShardingRule result = mock(ShardingRule.class); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.findLogicTableByActualTable("t_order")).thenReturn(Optional.of("t_order")); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.findLogicTableByActualTable("t_order")).thenReturn(Optional.of("t_order")); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRoutingEngineFixtureBuilder.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRoutingEngineFixtureBuilder.java index 36391d41ad243..11b9e702e1ea5 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRoutingEngineFixtureBuilder.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRoutingEngineFixtureBuilder.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.database.h2.type.H2DatabaseType; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -294,7 +294,7 @@ private static Map createDataSources() { public static SingleRule createSingleRule(final Collection rules) { Map dataSourceMap = createDataSourceMap(); SingleRule result = new SingleRule(new SingleRuleConfiguration(), DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, rules); - result.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put(dataSourceMap.keySet().iterator().next(), DefaultDatabase.LOGIC_NAME, "t_category"); + result.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put(dataSourceMap.keySet().iterator().next(), DefaultDatabase.LOGIC_NAME, "t_category"); return result; } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java index 3ff8496955dba..ae5277c8f80b1 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java @@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sharding.algorithm.audit.DMLShardingConditionsShardingAuditAlgorithm; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; @@ -202,12 +202,12 @@ void assertNotFindTableRuleByActualTable() { @Test void assertFindLogicTableByActualTable() { - assertTrue(createMaximumShardingRule().getRuleIdentifiers().getIdentifier(DataNodeRule.class).findLogicTableByActualTable("table_0").isPresent()); + assertTrue(createMaximumShardingRule().getAttributes().getAttribute(DataNodeRuleAttribute.class).findLogicTableByActualTable("table_0").isPresent()); } @Test void assertNotFindLogicTableByActualTable() { - assertFalse(createMaximumShardingRule().getRuleIdentifiers().getIdentifier(DataNodeRule.class).findLogicTableByActualTable("table_3").isPresent()); + assertFalse(createMaximumShardingRule().getAttributes().getAttribute(DataNodeRuleAttribute.class).findLogicTableByActualTable("table_3").isPresent()); } @Test @@ -706,7 +706,7 @@ private Map createColumnTableNameMap() { @Test void assertGetDataNodesByTableName() { ShardingRule shardingRule = createMinimumShardingRule(); - Collection actual = shardingRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getDataNodesByTableName("logic_table"); + Collection actual = shardingRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getDataNodesByTableName("logic_table"); assertThat(actual.size(), is(6)); Iterator iterator = actual.iterator(); DataNode firstDataNode = iterator.next(); @@ -768,7 +768,7 @@ void assertGetLogicAndActualTablesFromBindingTable() { @Test void assertGetAllDataNodes() { ShardingRule actual = createMaximumShardingRule(); - Map> allDataNodes = actual.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes(); + Map> allDataNodes = actual.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes(); assertTrue(allDataNodes.containsKey("logic_table")); assertTrue(allDataNodes.containsKey("sub_logic_table")); Collection logicTableDataNodes = allDataNodes.get("logic_table"); @@ -793,14 +793,14 @@ private void assertGetDataNodes(final Collection dataNodes, final Stri @Test void assertFindFirstActualTable() { ShardingRule actual = createMaximumShardingRule(); - Optional logicTable = actual.getRuleIdentifiers().getIdentifier(DataNodeRule.class).findFirstActualTable("logic_table"); + Optional logicTable = actual.getAttributes().getAttribute(DataNodeRuleAttribute.class).findFirstActualTable("logic_table"); assertThat(logicTable.orElse(""), is("table_0")); } @Test void assertFindActualTableByCatalog() { ShardingRule actual = createMaximumShardingRule(); - Optional actualTableByCatalog = actual.getRuleIdentifiers().getIdentifier(DataNodeRule.class).findActualTableByCatalog("ds_0", "logic_table"); + Optional actualTableByCatalog = actual.getAttributes().getAttribute(DataNodeRuleAttribute.class).findActualTableByCatalog("ds_0", "logic_table"); assertThat(actualTableByCatalog.orElse(""), is("table_0")); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingTableMapperRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingTableMapperRuleAttributeTest.java similarity index 72% rename from features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingTableMapperRuleTest.java rename to features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingTableMapperRuleAttributeTest.java index 0303cf197c6e8..7cbd8de1556b5 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingTableMapperRuleTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingTableMapperRuleAttributeTest.java @@ -29,35 +29,35 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -class ShardingTableMapperRuleTest { +class ShardingTableMapperRuleAttributeTest { - private ShardingTableMapperRule tableMapperRule; + private ShardingTableMapperRuleAttribute 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"))); - tableMapperRule = new ShardingTableMapperRule(Collections.singleton(shardingTable)); + ruleAttribute = new ShardingTableMapperRuleAttribute(Collections.singleton(shardingTable)); } @Test void assertGetLogicTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } @Test void assertGetActualTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getActualTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl_0"))); + assertThat(new LinkedList<>(ruleAttribute.getActualTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl_0"))); } @Test void assertGetDistributedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getDistributedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } @Test void assertGetEnhancedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getEnhancedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } } diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java index 9e2b2a705e3dd..44e05edc6be9a 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java @@ -32,7 +32,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; @@ -336,7 +336,7 @@ private static Collection parseDateSource(final String dateSource) { private static Collection getLogicDataSources(final ShardingSphereDatabase database) { Collection result = new LinkedHashSet<>(); - for (DataSourceMapperRule each : database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)) { + for (DataSourceMapperRuleAttribute each : database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) { result.addAll(each.getDataSourceMapper().keySet()); } return result; diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingImportRuleConfigurationProvider.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingImportRuleConfigurationProvider.java index e73a2cad4d83b..0b2080d7af100 100644 --- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingImportRuleConfigurationProvider.java +++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingImportRuleConfigurationProvider.java @@ -28,8 +28,8 @@ import org.apache.shardingsphere.infra.expr.core.InlineExpressionParserFactory; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; @@ -107,7 +107,7 @@ private Collection getDataSourceNames(final ShardingTableRuleConfigurati private Collection getLogicDataSources(final ShardingSphereDatabase database) { Collection result = new LinkedHashSet<>(); - for (DataSourceMapperRule each : database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)) { + for (DataSourceMapperRuleAttribute each : database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) { result.addAll(each.getDataSourceMapper().keySet()); } return result; diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleExecutorTest.java index c4908b983adc2..e4a12ce43d990 100644 --- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleExecutorTest.java +++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleExecutorTest.java @@ -26,8 +26,8 @@ import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration; @@ -82,10 +82,10 @@ void setUp() { when(database.getName()).thenReturn("schema"); ResourceMetaData resourceMetaData = new ResourceMetaData(createDataSource()); when(database.getResourceMetaData()).thenReturn(resourceMetaData); - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("logic_ds", null)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class); + when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("logic_ds", null)); ShardingSphereRule rule = mock(ShardingSphereRule.class); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataSourceMapperRule)); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule))); executor.setDatabase(database); } 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 53b962af11121..3c26672b2aecf 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 @@ -45,7 +45,7 @@ import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.sql.parser.sql.common.enums.ParameterMarkerType; import org.apache.shardingsphere.sql.parser.sql.common.enums.SubqueryType; import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor; @@ -129,7 +129,7 @@ public SelectStatementContext(final ShardingSphereMetaData metaData, final List< } private boolean isContainsEnhancedTable(final ShardingSphereMetaData metaData, final String databaseName, final Collection tableNames) { - for (TableMapperRule each : getTableMapperRules(metaData, databaseName)) { + for (TableMapperRuleAttribute each : getTableMapperRuleAttributes(metaData, databaseName)) { for (String tableName : tableNames) { if (each.getEnhancedTableMapper().contains(tableName)) { return true; @@ -139,14 +139,14 @@ private boolean isContainsEnhancedTable(final ShardingSphereMetaData metaData, f return false; } - private Collection getTableMapperRules(final ShardingSphereMetaData metaData, final String databaseName) { + private Collection getTableMapperRuleAttributes(final ShardingSphereMetaData metaData, final String databaseName) { if (null == databaseName) { ShardingSpherePreconditions.checkState(tablesContext.getSimpleTableSegments().isEmpty(), NoDatabaseSelectedException::new); return Collections.emptyList(); } ShardingSphereDatabase database = metaData.getDatabase(databaseName); ShardingSpherePreconditions.checkNotNull(database, () -> new UnknownDatabaseException(databaseName)); - return database.getRuleMetaData().getRuleIdentifiers(TableMapperRule.class); + return database.getRuleMetaData().getAttributes(TableMapperRuleAttribute.class); } private Map createSubqueryContexts(final ShardingSphereMetaData metaData, final List params, final String defaultDatabaseName) { 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 80ea773bbb301..756fd5d3b1654 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 @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.sql.parser.sql.common.enums.AggregationType; import org.apache.shardingsphere.sql.parser.sql.common.enums.OrderDirection; import org.apache.shardingsphere.sql.parser.sql.common.enums.ParameterMarkerType; @@ -120,9 +120,9 @@ private void assertSetIndexForItemsByIndexOrderBy(final SelectStatement selectSt private ShardingSphereDatabase mockDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); - TableMapperRule tableMapperRule = mock(TableMapperRule.class, RETURNS_DEEP_STUBS); - when(tableMapperRule.getEnhancedTableMapper().contains("t_order")).thenReturn(true); - when(result.getRuleMetaData().getRuleIdentifiers(TableMapperRule.class)).thenReturn(Collections.singleton(tableMapperRule)); + TableMapperRuleAttribute ruleAttribute = mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS); + when(ruleAttribute.getEnhancedTableMapper().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/datanode/DataNodes.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java index e2bb62bc425b5..0622fca1ed73f 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodes.java @@ -19,7 +19,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; import java.util.Collection; @@ -61,6 +61,6 @@ public Collection getDataNodes(final String tableName) { } private Collection getDataNodes(final ShardingSphereRule rule, final String tableName) { - return rule.getRuleIdentifiers().findIdentifier(DataNodeRule.class).map(optional -> optional.getDataNodesByTableName(tableName)).orElse(Collections.emptyList()); + return rule.getAttributes().findAttribute(DataNodeRuleAttribute.class).map(optional -> optional.getDataNodesByTableName(tableName)).orElse(Collections.emptyList()); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java index 8245aa8676deb..e9ed36bdab21d 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java @@ -25,8 +25,8 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import java.util.Collections; import java.util.HashMap; @@ -95,7 +95,7 @@ public ShardingSphereDatabase getDatabase(final String databaseName) { public void addDatabase(final String databaseName, final DatabaseType protocolType, final ConfigurationProperties props) { ShardingSphereDatabase database = ShardingSphereDatabase.create(databaseName, protocolType, props); databases.put(database.getName().toLowerCase(), database); - globalRuleMetaData.getRuleIdentifiers(ResourceHeldRule.class).forEach(each -> each.addResource(database)); + globalRuleMetaData.getAttributes(ResourceHeldRuleAttribute.class).forEach(each -> each.addResource(database)); } /** @@ -108,9 +108,9 @@ public void dropDatabase(final String databaseName) { } private void cleanResources(final ShardingSphereDatabase database) { - globalRuleMetaData.getRuleIdentifiers(ResourceHeldRule.class).forEach(each -> each.closeStaleResource(database.getName())); - database.getRuleMetaData().getRuleIdentifiers(ResourceHeldRule.class).forEach(each -> each.closeStaleResource(database.getName())); - database.getRuleMetaData().getRuleIdentifiers(StaticDataSourceRule.class).forEach(StaticDataSourceRule::cleanStorageNodeDataSources); + globalRuleMetaData.getAttributes(ResourceHeldRuleAttribute.class).forEach(each -> each.closeStaleResource(database.getName())); + database.getRuleMetaData().getAttributes(ResourceHeldRuleAttribute.class).forEach(each -> each.closeStaleResource(database.getName())); + database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class).forEach(StaticDataSourceRuleAttribute::cleanStorageNodeDataSources); Optional.ofNullable(database.getResourceMetaData()) .ifPresent(optional -> optional.getStorageUnits().values().forEach(each -> new DataSourcePoolDestroyer(each.getDataSource()).asyncDestroy())); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java index 33988769822b2..1e1fcc71dfa2b 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabase.java @@ -35,7 +35,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager; import javax.sql.DataSource; @@ -192,14 +192,14 @@ public boolean containsDataSource() { */ public synchronized void reloadRules() { Collection toBeReloadedRules = ruleMetaData.getRules().stream() - .filter(each -> each.getRuleIdentifiers().findIdentifier(MutableDataNodeRule.class).isPresent()).collect(Collectors.toList()); + .filter(each -> each.getAttributes().findAttribute(MutableDataNodeRuleAttribute.class).isPresent()).collect(Collectors.toList()); RuleConfiguration ruleConfig = toBeReloadedRules.stream().map(ShardingSphereRule::getConfiguration).findFirst().orElse(null); Collection rules = new LinkedList<>(ruleMetaData.getRules()); toBeReloadedRules.stream().findFirst().ifPresent(optional -> { rules.removeAll(toBeReloadedRules); Map dataSources = resourceMetaData.getStorageUnits().entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getDataSource(), (oldValue, currentValue) -> oldValue, LinkedHashMap::new)); - rules.add(optional.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).reloadRule(ruleConfig, name, dataSources, rules)); + rules.add(optional.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).reloadRule(ruleConfig, name, dataSources, rules)); }); ruleMetaData.getRules().clear(); ruleMetaData.getRules().addAll(rules); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java index 2d501561c50ab..12ecdea84b154 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/rule/RuleMetaData.java @@ -22,9 +22,9 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import java.util.Collection; import java.util.LinkedHashMap; @@ -107,12 +107,12 @@ public T getSingleRule(final Class clazz) { public Map>> getInUsedStorageUnitNameAndRulesMap() { Map>> result = new LinkedHashMap<>(); for (ShardingSphereRule each : rules) { - Optional dataSourceMapperRule = each.getRuleIdentifiers().findIdentifier(DataSourceMapperRule.class); - if (dataSourceMapperRule.isPresent()) { - mergeInUsedStorageUnitNameAndRules(result, getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames(dataSourceMapperRule.get()))); + Optional ruleAttribute = each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class); + if (ruleAttribute.isPresent()) { + mergeInUsedStorageUnitNameAndRules(result, getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames(ruleAttribute.get()))); continue; } - each.getRuleIdentifiers().findIdentifier(DataNodeRule.class) + each.getAttributes().findAttribute(DataNodeRuleAttribute.class) .ifPresent(optional -> mergeInUsedStorageUnitNameAndRules(result, getInUsedStorageUnitNameAndRulesMap(each, getInUsedStorageUnitNames(optional)))); } return result; @@ -129,12 +129,12 @@ private Map>> getInUsedSt return result; } - private Collection getInUsedStorageUnitNames(final DataSourceMapperRule rule) { - return rule.getDataSourceMapper().values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); + private Collection getInUsedStorageUnitNames(final DataSourceMapperRuleAttribute ruleAttribute) { + return ruleAttribute.getDataSourceMapper().values().stream().flatMap(Collection::stream).collect(Collectors.toSet()); } - private Collection getInUsedStorageUnitNames(final DataNodeRule rule) { - return rule.getAllDataNodes().values().stream().flatMap(each -> each.stream().map(DataNode::getDataSourceName).collect(Collectors.toSet()).stream()).collect(Collectors.toSet()); + private Collection getInUsedStorageUnitNames(final DataNodeRuleAttribute ruleAttribute) { + return ruleAttribute.getAllDataNodes().values().stream().flatMap(each -> each.stream().map(DataNode::getDataSourceName).collect(Collectors.toSet()).stream()).collect(Collectors.toSet()); } private void mergeInUsedStorageUnitNameAndRules(final Map>> storageUnitNameAndRules, @@ -153,16 +153,16 @@ private void mergeInUsedStorageUnitNameAndRules(final Map type of rule identifiers - * @return rule identifiers + * @param attributeClass rule attribute class + * @param type of rule attributes + * @return rule attributes */ - public Collection getRuleIdentifiers(final Class ruleIdentifierClass) { + public Collection getAttributes(final Class attributeClass) { Collection result = new LinkedList<>(); for (ShardingSphereRule each : rules) { - each.getRuleIdentifiers().findIdentifier(ruleIdentifierClass).ifPresent(result::add); + each.getAttributes().findAttribute(attributeClass).ifPresent(result::add); } return result; } 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 3492d121e68bd..6d314f5e6d461 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 @@ -37,7 +37,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEngine; import org.apache.shardingsphere.infra.metadata.database.schema.util.SchemaMetaDataUtils; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import java.sql.SQLException; import java.util.Collection; @@ -87,7 +87,7 @@ public static Map build(final Collection t private static Collection getAllTableNames(final Collection rules) { Collection result = new HashSet<>(); for (ShardingSphereRule each : rules) { - each.getRuleIdentifiers().findIdentifier(TableMapperRule.class).ifPresent(mapperRule -> result.addAll(mapperRule.getLogicTableMapper().getTableNames())); + each.getAttributes().findAttribute(TableMapperRuleAttribute.class).ifPresent(mapperRule -> result.addAll(mapperRule.getLogicTableMapper().getTableNames())); } return result; } @@ -113,7 +113,7 @@ private static Map translate(final Map revise(final Map schemaMetaDataMap, final GenericSchemaBuilderMaterial material) { Map result = new LinkedHashMap<>(schemaMetaDataMap); result.putAll(new MetaDataReviseEngine(material.getRules().stream() - .filter(each -> each.getRuleIdentifiers().findIdentifier(TableMapperRule.class).isPresent()).collect(Collectors.toList())).revise(result, material)); + .filter(each -> each.getAttributes().findAttribute(TableMapperRuleAttribute.class).isPresent()).collect(Collectors.toList())).revise(result, material)); return convertToSchemaMap(result, material); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java index 03c41db048ea8..2fad7707705ff 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/statistics/collector/tables/PgClassTableCollector.java @@ -18,13 +18,13 @@ package org.apache.shardingsphere.infra.metadata.statistics.collector.tables; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; +import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereRowData; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData; import org.apache.shardingsphere.infra.metadata.statistics.collector.ShardingSphereStatisticsCollector; import org.apache.shardingsphere.infra.metadata.statistics.collector.ShardingSphereTableDataCollectorUtils; -import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.sql.SQLException; import java.util.ArrayList; @@ -52,25 +52,22 @@ public final class PgClassTableCollector implements ShardingSphereStatisticsColl public Optional collect(final String databaseName, final ShardingSphereTable table, final Map databases) throws SQLException { Collection rows = ShardingSphereTableDataCollectorUtils.collectRowData(databases.get(databaseName), table, Arrays.stream(COLUMN_NAMES.split(",")).map(String::trim).collect(Collectors.toList()), SELECT_SQL); - Collection rowData = decorateTableName(rows, table, databases.get(databaseName).getRuleMetaData().getRules()); + Collection rowData = decorateTableName(rows, table, databases.get(databaseName).getRuleMetaData()); ShardingSphereTableData result = new ShardingSphereTableData(PG_CLASS); result.getRows().addAll(rowData); return Optional.of(result); } - private Collection decorateTableName(final Collection rows, final ShardingSphereTable table, final Collection rules) { - Collection dataNodeRules = new LinkedList<>(); - for (ShardingSphereRule each : rules) { - each.getRuleIdentifiers().findIdentifier(DataNodeRule.class).ifPresent(dataNodeRules::add); - } - if (dataNodeRules.isEmpty()) { + private Collection decorateTableName(final Collection rows, final ShardingSphereTable table, final RuleMetaData ruleMetaData) { + Collection ruleAttributes = ruleMetaData.getAttributes(DataNodeRuleAttribute.class); + if (ruleAttributes.isEmpty()) { return rows; } int tableNameIndex = table.getColumnNames().indexOf("relname"); Collection result = new LinkedList<>(); for (ShardingSphereRowData each : rows) { String tableName = (String) each.getRows().get(tableNameIndex); - String logicTableName = decorateTableName(dataNodeRules, tableName); + String logicTableName = decorateTableName(ruleAttributes, tableName); List decoratedRow = new ArrayList<>(each.getRows()); decoratedRow.set(tableNameIndex, logicTableName); result.add(new ShardingSphereRowData(decoratedRow)); @@ -78,8 +75,8 @@ private Collection decorateTableName(final Collection dataNodeRules, final String actualTableName) { - for (DataNodeRule each : dataNodeRules) { + private String decorateTableName(final Collection ruleAttributes, final String actualTableName) { + for (DataNodeRuleAttribute each : ruleAttributes) { if (each.findLogicTableByActualTable(actualTableName).isPresent()) { return each.findLogicTableByActualTable(actualTableName).get(); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/ShardingSphereRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/ShardingSphereRule.java index a89deb8e79902..2593a3f3ca95a 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/ShardingSphereRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/ShardingSphereRule.java @@ -18,7 +18,7 @@ package org.apache.shardingsphere.infra.rule; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; /** * ShardingSphere rule. @@ -33,9 +33,9 @@ public interface ShardingSphereRule { RuleConfiguration getConfiguration(); /** - * Get rule identifiers. + * Get rule attributes. * - * @return rule identifiers + * @return rule attributes */ - RuleIdentifiers getRuleIdentifiers(); + RuleAttributes getAttributes(); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/RuleIdentifier.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/RuleAttribute.java similarity index 87% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/RuleIdentifier.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/RuleAttribute.java index 12cd7a6883fd7..83cd3ff5499ca 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/RuleIdentifier.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/RuleAttribute.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type; +package org.apache.shardingsphere.infra.rule.attribute; /** - * Rule identifier. + * Rule attribute. */ -public interface RuleIdentifier { +public interface RuleAttribute { } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/RuleIdentifiers.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/RuleAttributes.java similarity index 50% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/RuleIdentifiers.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/RuleAttributes.java index c686946cfc3ff..d7f7217701b3a 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/RuleIdentifiers.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/RuleAttributes.java @@ -15,34 +15,34 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type; +package org.apache.shardingsphere.infra.rule.attribute; import java.util.Arrays; import java.util.Collection; import java.util.Optional; /** - * Rule identifiers. + * Rule attribute. */ -public final class RuleIdentifiers { +public final class RuleAttributes { - private final Collection identifiers; + private final Collection attributes; - public RuleIdentifiers(final RuleIdentifier... identifiers) { - this.identifiers = Arrays.asList(identifiers); + public RuleAttributes(final RuleAttribute... attributes) { + this.attributes = Arrays.asList(attributes); } /** - * Find rule identifier. + * Find rule attribute. * - * @param ruleIdentifierClass rule identifier class - * @param type of rule identifier - * @return found rule identifier + * @param attributeClass rule attribute class + * @param type of rule attribute + * @return found rule attribute */ @SuppressWarnings("unchecked") - public Optional findIdentifier(final Class ruleIdentifierClass) { - for (RuleIdentifier each : identifiers) { - if (ruleIdentifierClass.isAssignableFrom(each.getClass())) { + public Optional findAttribute(final Class attributeClass) { + for (RuleAttribute each : attributes) { + if (attributeClass.isAssignableFrom(each.getClass())) { return Optional.of((T) each); } } @@ -50,13 +50,13 @@ public Optional findIdentifier(final Class rule } /** - * Get rule identifier. + * Get rule attribute. * - * @param ruleIdentifierClass rule identifier class - * @param type of rule identifier - * @return got rule identifier + * @param attributeClass rule attribute class + * @param type of rule attribute + * @return got rule attribute */ - public T getIdentifier(final Class ruleIdentifierClass) { - return findIdentifier(ruleIdentifierClass).orElseThrow(() -> new IllegalStateException(String.format("Can not find rule identifier: %s", ruleIdentifierClass))); + public T getAttribute(final Class attributeClass) { + return findAttribute(attributeClass).orElseThrow(() -> new IllegalStateException(String.format("Can not find rule attribute: %s", attributeClass))); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datanode/DataNodeRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datanode/DataNodeRuleAttribute.java similarity index 90% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datanode/DataNodeRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datanode/DataNodeRuleAttribute.java index aa1804ea039c6..721eb86328b1b 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datanode/DataNodeRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datanode/DataNodeRuleAttribute.java @@ -15,19 +15,19 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.datanode; +package org.apache.shardingsphere.infra.rule.attribute.datanode; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; import java.util.Collection; import java.util.Map; import java.util.Optional; /** - * Data node rule. + * Data node rule attribute. */ -public interface DataNodeRule extends RuleIdentifier { +public interface DataNodeRuleAttribute extends RuleAttribute { /** * Get all data nodes. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datanode/MutableDataNodeRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datanode/MutableDataNodeRuleAttribute.java similarity index 90% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datanode/MutableDataNodeRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datanode/MutableDataNodeRuleAttribute.java index 20005cc5e03f6..a96af466eba15 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datanode/MutableDataNodeRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datanode/MutableDataNodeRuleAttribute.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.datanode; +package org.apache.shardingsphere.infra.rule.attribute.datanode; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; import javax.sql.DataSource; import java.util.Collection; @@ -28,9 +28,9 @@ import java.util.Optional; /** - * Mutable data node rule. + * Mutable data node rule attribute. */ -public interface MutableDataNodeRule extends RuleIdentifier { +public interface MutableDataNodeRuleAttribute extends RuleAttribute { /** * Add data node. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/DataSourceMapperRuleAttribute.java similarity index 80% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/DataSourceMapperRuleAttribute.java index 48c8c93181871..e51ac148178bc 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/DataSourceMapperRuleAttribute.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.datasource; +package org.apache.shardingsphere.infra.rule.attribute.datasource; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; import java.util.Collection; import java.util.Map; /** - * Data source mapper rule. + * Data source mapper rule attribute. */ -public interface DataSourceMapperRule extends RuleIdentifier { +public interface DataSourceMapperRuleAttribute extends RuleAttribute { /** * Get data source mapper. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/StaticDataSourceRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/StaticDataSourceRuleAttribute.java similarity index 86% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/StaticDataSourceRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/StaticDataSourceRuleAttribute.java index cab4aae0e9109..7a7d92b142796 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/StaticDataSourceRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/datasource/StaticDataSourceRuleAttribute.java @@ -15,18 +15,18 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.datasource; +package org.apache.shardingsphere.infra.rule.attribute.datasource; import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; import java.util.Collection; import java.util.Map; /** - * Static data source rule. + * Static data source rule attribute. */ -public interface StaticDataSourceRule extends RuleIdentifier { +public interface StaticDataSourceRuleAttribute extends RuleAttribute { /** * Get data source mapper. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/ExportableRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/ExportableRuleAttribute.java similarity index 80% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/ExportableRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/ExportableRuleAttribute.java index ba403420a0a34..10029e401faa6 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/ExportableRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/ExportableRuleAttribute.java @@ -15,16 +15,16 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.exportable; +package org.apache.shardingsphere.infra.rule.attribute.exportable; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; import java.util.Map; /** - * Exportable rule. + * Exportable rule attribute. */ -public interface ExportableRule extends RuleIdentifier { +public interface ExportableRuleAttribute extends RuleAttribute { /** * Get export data. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/constant/ExportableConstants.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/constant/ExportableConstants.java similarity index 94% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/constant/ExportableConstants.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/constant/ExportableConstants.java index a52728bf888a8..74153fc0249cf 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/constant/ExportableConstants.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/constant/ExportableConstants.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant; +package org.apache.shardingsphere.infra.rule.attribute.exportable.constant; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/constant/ExportableItemConstants.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/constant/ExportableItemConstants.java similarity index 93% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/constant/ExportableItemConstants.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/constant/ExportableItemConstants.java index d54474ad75797..76b6a6c588eec 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/exportable/constant/ExportableItemConstants.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/exportable/constant/ExportableItemConstants.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant; +package org.apache.shardingsphere.infra.rule.attribute.exportable.constant; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/metadata/MetaDataHeldRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/metadata/MetaDataHeldRuleAttribute.java similarity index 83% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/metadata/MetaDataHeldRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/metadata/MetaDataHeldRuleAttribute.java index c662d50988647..492cae133b62d 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/metadata/MetaDataHeldRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/metadata/MetaDataHeldRuleAttribute.java @@ -15,15 +15,15 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.metadata; +package org.apache.shardingsphere.infra.rule.attribute.metadata; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; /** - * Meta data held rule. + * Meta data held rule attribute. */ -public interface MetaDataHeldRule extends RuleIdentifier { +public interface MetaDataHeldRuleAttribute extends RuleAttribute { /** * Alter database. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/raw/RawExecutionRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/raw/RawExecutionRuleAttribute.java similarity index 78% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/raw/RawExecutionRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/raw/RawExecutionRuleAttribute.java index c5ad1219b0109..6d7bcfd00a553 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/raw/RawExecutionRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/raw/RawExecutionRuleAttribute.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.raw; +package org.apache.shardingsphere.infra.rule.attribute.raw; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; /** - * Raw execution rule. + * Raw execution rule attribute. */ -public interface RawExecutionRule extends RuleIdentifier { +public interface RawExecutionRuleAttribute extends RuleAttribute { } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/resoure/ResourceHeldRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/resoure/ResourceHeldRuleAttribute.java similarity index 85% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/resoure/ResourceHeldRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/resoure/ResourceHeldRuleAttribute.java index 4fdc460d595cf..ca66fdc423b3c 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/resoure/ResourceHeldRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/resoure/ResourceHeldRuleAttribute.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.resoure; +package org.apache.shardingsphere.infra.rule.attribute.resoure; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; /** - * Resource held rule. + * Resource held rule attribute. * * @param type of resource */ -public interface ResourceHeldRule extends RuleIdentifier { +public interface ResourceHeldRuleAttribute extends RuleAttribute { /** * Get resource. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/resoure/StorageConnectorReusableRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/resoure/StorageConnectorReusableRuleAttribute.java similarity index 75% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/resoure/StorageConnectorReusableRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/resoure/StorageConnectorReusableRuleAttribute.java index 95af0cc6fab87..3dded9cf4c782 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/resoure/StorageConnectorReusableRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/resoure/StorageConnectorReusableRuleAttribute.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.resoure; +package org.apache.shardingsphere.infra.rule.attribute.resoure; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; /** - * Storage connector reusable rule. + * Storage connector reusable rule attribute. */ -public interface StorageConnectorReusableRule extends RuleIdentifier { +public interface StorageConnectorReusableRuleAttribute extends RuleAttribute { } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableMapperRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableMapperRuleAttribute.java similarity index 86% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableMapperRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableMapperRuleAttribute.java index a35c658e3aa69..af9ccd8a80a45 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableMapperRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableMapperRuleAttribute.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.table; +package org.apache.shardingsphere.infra.rule.attribute.table; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifier; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttribute; /** - * Table mapper rule. + * Table mapper rule attribute. */ -public interface TableMapperRule extends RuleIdentifier { +public interface TableMapperRuleAttribute extends RuleAttribute { /** * Get logic table mapper. diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableNamesMapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableNamesMapper.java similarity index 96% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableNamesMapper.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableNamesMapper.java index dbf4c943d9f0a..81a5b1b7c29bf 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/table/TableNamesMapper.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/attribute/table/TableNamesMapper.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.type.table; +package org.apache.shardingsphere.infra.rule.attribute.table; import com.cedarsoftware.util.CaseInsensitiveMap; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilder.java index 26feb2688e2a9..b5f7274127fb8 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/database/DatabaseRuleBuilder.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.builder.RuleBuilder; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; import javax.sql.DataSource; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java index fe89707552b31..6188828fa35d3 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.builder.RuleBuilder; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; import java.util.Map; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/scope/DatabaseRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/DatabaseRule.java similarity index 93% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/scope/DatabaseRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/DatabaseRule.java index e41e17b3699a3..79e282506c44b 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/scope/DatabaseRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/DatabaseRule.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.scope; +package org.apache.shardingsphere.infra.rule.scope; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/scope/GlobalRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java similarity index 93% rename from infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/scope/GlobalRule.java rename to infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java index 4bec1039ffe0e..fbe266c21440d 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/scope/GlobalRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.infra.rule.identifier.scope; +package org.apache.shardingsphere.infra.rule.scope; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java index 461d6c6dd22d5..1ed9397f2e487 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java @@ -19,9 +19,9 @@ import org.apache.shardingsphere.infra.fixture.FixtureRule; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -137,9 +137,9 @@ private Collection mockShardingSphereRules() { private ShardingSphereRule mockDataSourceMapperRule() { ShardingSphereRule result = mock(FixtureRule.class, RETURNS_DEEP_STUBS); - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(READ_WRITE_SPLITTING_DATASOURCE_MAP); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class); + when(ruleAttribute.getDataSourceMapper()).thenReturn(READ_WRITE_SPLITTING_DATASOURCE_MAP); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } @@ -151,10 +151,10 @@ private Collection mockDataNodeRules() { } private ShardingSphereRule mockSingleRule() { - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.getDataNodesByTableName("t_single")).thenReturn(Collections.singleton(new DataNode("readwrite_ds", "t_single"))); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.getDataNodesByTableName("t_single")).thenReturn(Collections.singleton(new DataNode("readwrite_ds", "t_single"))); ShardingSphereRule result = mock(ShardingSphereRule.class); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } @@ -162,10 +162,10 @@ private ShardingSphereRule mockShardingRule() { Collection dataNodes = new LinkedList<>(); dataNodes.add(new DataNode("readwrite_ds", "t_order_0")); dataNodes.add(new DataNode("readwrite_ds", "t_order_1")); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.getDataNodesByTableName("t_order")).thenReturn(dataNodes); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.getDataNodesByTableName("t_order")).thenReturn(dataNodes); ShardingSphereRule result = mock(ShardingSphereRule.class); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/DataNodeBuilderFixture.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/DataNodeBuilderFixture.java index 1235c8d845716..116942caf0b62 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/DataNodeBuilderFixture.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/DataNodeBuilderFixture.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.datanode.DataNodeBuilder; import org.apache.shardingsphere.infra.datanode.DataNodeUtils; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import java.util.Collection; import java.util.LinkedList; @@ -31,7 +31,7 @@ public final class DataNodeBuilderFixture implements DataNodeBuilder build(final Collection dataNodes, final FixtureRule rule) { Collection result = new LinkedList<>(); for (DataNode each : dataNodes) { - result.addAll(DataNodeUtils.buildDataNode(each, rule.getRuleIdentifiers().getIdentifier(DataSourceMapperRule.class).getDataSourceMapper())); + result.addAll(DataNodeUtils.buildDataNode(each, rule.getAttributes().getAttribute(DataSourceMapperRuleAttribute.class).getDataSourceMapper())); } return result; } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java index f9a144bac3673..d5599af26160f 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.infra.fixture; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +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 static org.mockito.Mockito.mock; @@ -32,7 +32,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(mock(DataSourceMapperRule.class)); + public RuleAttributes getAttributes() { + return new RuleAttributes(mock(DataSourceMapperRuleAttribute.class)); } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java index 57dd4e92717f7..ff29ba8424e06 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java @@ -26,8 +26,8 @@ import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -59,9 +59,9 @@ class ShardingSphereMetaDataTest { @Test void assertAddDatabase() { - ResourceHeldRule globalResourceHeldRule = mock(ResourceHeldRule.class); + ResourceHeldRuleAttribute globalResourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); ShardingSphereRule globalRule = mock(ShardingSphereRule.class); - when(globalRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(globalResourceHeldRule)); + when(globalRule.getAttributes()).thenReturn(new RuleAttributes(globalResourceHeldRuleAttribute)); ShardingSphereDatabase database = mockDatabase(mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new MockedDataSource(), globalRule); DatabaseType databaseType = mock(DatabaseType.class); ConfigurationProperties configProps = new ConfigurationProperties(new Properties()); @@ -70,34 +70,34 @@ void assertAddDatabase() { ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(globalRule)), configProps); metaData.addDatabase("foo_db", databaseType, configProps); assertThat(metaData.getDatabases(), is(databases)); - verify(globalResourceHeldRule).addResource(database); + verify(globalResourceHeldRuleAttribute).addResource(database); } @Test void assertDropDatabase() { ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS); MockedDataSource dataSource = new MockedDataSource(); - ResourceHeldRule databaseResourceHeldRule = mock(ResourceHeldRule.class, RETURNS_DEEP_STUBS); - ResourceHeldRule globalResourceHeldRule = mock(ResourceHeldRule.class); + ResourceHeldRuleAttribute databaseResourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class, RETURNS_DEEP_STUBS); + ResourceHeldRuleAttribute globalResourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); ShardingSphereRule databaseRule = mock(ShardingSphereRule.class); - when(databaseRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(databaseResourceHeldRule)); + when(databaseRule.getAttributes()).thenReturn(new RuleAttributes(databaseResourceHeldRuleAttribute)); ShardingSphereRule globalRule = mock(ShardingSphereRule.class); - when(globalRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(globalResourceHeldRule)); + when(globalRule.getAttributes()).thenReturn(new RuleAttributes(globalResourceHeldRuleAttribute)); ShardingSphereMetaData metaData = new ShardingSphereMetaData(new HashMap<>(Collections.singletonMap("foo_db", mockDatabase(resourceMetaData, dataSource, databaseRule))), mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(globalRule)), new ConfigurationProperties(new Properties())); metaData.dropDatabase("foo_db"); assertTrue(metaData.getDatabases().isEmpty()); Awaitility.await().pollDelay(10L, TimeUnit.MILLISECONDS).until(dataSource::isClosed); assertTrue(dataSource.isClosed()); - verify(databaseResourceHeldRule).closeStaleResource("foo_db"); - verify(globalResourceHeldRule).closeStaleResource("foo_db"); + verify(databaseResourceHeldRuleAttribute).closeStaleResource("foo_db"); + verify(globalResourceHeldRuleAttribute).closeStaleResource("foo_db"); } @Test void assertContainsDatabase() { - ResourceHeldRule globalResourceHeldRule = mock(ResourceHeldRule.class); + ResourceHeldRuleAttribute globalResourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); ShardingSphereRule globalRule = mock(ShardingSphereRule.class); - when(globalRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(globalResourceHeldRule)); + when(globalRule.getAttributes()).thenReturn(new RuleAttributes(globalResourceHeldRuleAttribute)); ShardingSphereDatabase database = mockDatabase(mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new MockedDataSource(), globalRule); Map databases = new HashMap<>(Collections.singletonMap("foo_db", database)); ConfigurationProperties configProps = new ConfigurationProperties(new Properties()); @@ -107,9 +107,9 @@ void assertContainsDatabase() { @Test void assertGetDatabase() { - ResourceHeldRule globalResourceHeldRule = mock(ResourceHeldRule.class); + ResourceHeldRuleAttribute globalResourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); ShardingSphereRule globalRule = mock(ShardingSphereRule.class); - when(globalRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(globalResourceHeldRule)); + when(globalRule.getAttributes()).thenReturn(new RuleAttributes(globalResourceHeldRuleAttribute)); ShardingSphereDatabase database = mockDatabase(mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new MockedDataSource(), globalRule); Map databases = new HashMap<>(Collections.singletonMap("foo_db", database)); ConfigurationProperties configProps = new ConfigurationProperties(new Properties()); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java index 610b2c9356a74..df5ba90ac979f 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/ShardingSphereDatabaseTest.java @@ -26,8 +26,8 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.mock.AutoMockExtension; @@ -150,11 +150,11 @@ void assertReloadRules() { Collection rules = new LinkedList<>(); ShardingSphereRule rule0 = mock(ShardingSphereRule.class); when(rule0.getConfiguration()).thenReturn(mock(RuleConfiguration.class)); - when(rule0.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(mock(MutableDataNodeRule.class))); + when(rule0.getAttributes()).thenReturn(new RuleAttributes(mock(MutableDataNodeRuleAttribute.class))); rules.add(rule0); ShardingSphereRule rule1 = mock(ShardingSphereRule.class); when(rule1.getConfiguration()).thenReturn(mock(RuleConfiguration.class)); - when(rule1.getRuleIdentifiers()).thenReturn(new RuleIdentifiers()); + when(rule1.getAttributes()).thenReturn(new RuleAttributes()); rules.add(rule1); RuleMetaData ruleMetaData = new RuleMetaData(rules); ResourceMetaData resourceMetaData = new ResourceMetaData(Collections.singletonMap("ds", new MockedDataSource())); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/rule/ShardingSphereRuleFixture.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/rule/ShardingSphereRuleFixture.java index f0080e63a9b77..b140619a36d6a 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/rule/ShardingSphereRuleFixture.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/rule/ShardingSphereRuleFixture.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -31,7 +31,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java index 7cf04f35fccd7..3a49c73337657 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/builder/GenericSchemaBuilderTest.java @@ -26,8 +26,8 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.test.mock.AutoMockExtension; @@ -65,7 +65,7 @@ class GenericSchemaBuilderTest { void setUp() { DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); ShardingSphereRule rule = mock(ShardingSphereRule.class); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(mock(TableMapperRule.class))); + when(rule.getAttributes()).thenReturn(new RuleAttributes(mock(TableMapperRuleAttribute.class))); material = new GenericSchemaBuilderMaterial(databaseType, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, databaseType), Collections.singletonMap(DefaultDatabase.LOGIC_NAME, new MockedDataSource()), Collections.singleton(rule), new ConfigurationProperties(new Properties()), DefaultDatabase.LOGIC_NAME); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java index 643194f90df46..55f51be33f166 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtilsTest.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.junit.jupiter.api.Test; @@ -48,9 +48,9 @@ class SchemaMetaDataUtilsTest { @Test void assertGetSchemaMetaDataLoaderMaterialsWhenConfigCheckMetaDataEnable() { ShardingSphereRule rule = mock(ShardingSphereRule.class); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.getDataNodesByTableName("t_order")).thenReturn(mockShardingDataNodes()); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.getDataNodesByTableName("t_order")).thenReturn(mockShardingDataNodes()); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(mock(DatabaseType.class), mockStorageTypes(), mockDataSourceMap(), Arrays.asList(rule, mock(ShardingSphereRule.class)), mock(ConfigurationProperties.class), "sharding_db"); Collection actual = SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_order"), material, true); @@ -67,9 +67,9 @@ void assertGetSchemaMetaDataLoaderMaterialsWhenConfigCheckMetaDataEnable() { @Test void assertGetSchemaMetaDataLoaderMaterialsWhenNotConfigCheckMetaDataEnable() { ShardingSphereRule rule = mock(ShardingSphereRule.class); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.getDataNodesByTableName("t_order")).thenReturn(mockShardingDataNodes()); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.getDataNodesByTableName("t_order")).thenReturn(mockShardingDataNodes()); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(mock(DatabaseType.class), mockStorageTypes(), mockDataSourceMap(), Arrays.asList(rule, mock(ShardingSphereRule.class)), mock(ConfigurationProperties.class), "sharding_db"); Collection actual = SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_order"), material, false); @@ -83,9 +83,9 @@ void assertGetSchemaMetaDataLoaderMaterialsWhenNotConfigCheckMetaDataEnable() { @Test void assertGetSchemaMetaDataLoaderMaterialsWhenNotConfigCheckMetaDataEnableForSingleTableDataNode() { ShardingSphereRule rule = mock(ShardingSphereRule.class); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.getDataNodesByTableName("t_single")).thenReturn(mockSingleTableDataNodes()); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.getDataNodesByTableName("t_single")).thenReturn(mockSingleTableDataNodes()); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(mock(DatabaseType.class), mockStorageTypes(), mockDataSourceMap(), Arrays.asList(rule, mock(ShardingSphereRule.class)), mock(ConfigurationProperties.class), "public"); Collection actual = SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_single"), material, false); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRule.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRule.java index 483c5ed8a6f3d..a6a6b6ad3c3c1 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRule.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRule.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.infra.rule.builder.fixture; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -31,7 +31,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } 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 index 2cf0f54b72ecc..21ed27bb59c3f 100644 --- 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 @@ -17,6 +17,7 @@ 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; diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java index 0b75215a6da85..f44096bed3203 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/AlterTableStatementSchemaRefresher.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaMetaDataPOJO; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement; import java.sql.SQLException; @@ -63,7 +63,7 @@ private ShardingSphereTable getTable(final ShardingSphereDatabase database, fina final String tableName, final ConfigurationProperties props) throws SQLException { RuleMetaData ruleMetaData = new RuleMetaData(new LinkedList<>(database.getRuleMetaData().getRules())); if (TableRefreshUtils.isSingleTable(tableName, database)) { - ruleMetaData.getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); + ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java index 8b7143c5ad034..35c24aa582d69 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/CreateTableStatementSchemaRefresher.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaMetaDataPOJO; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement; import java.sql.SQLException; @@ -51,7 +51,7 @@ public void refresh(final ModeContextManager modeContextManager, final ShardingS RuleMetaData ruleMetaData = new RuleMetaData(new LinkedList<>(database.getRuleMetaData().getRules())); boolean isSingleTable = TableRefreshUtils.isSingleTable(tableName, database); if (isSingleTable) { - ruleMetaData.getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); + ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java index cf1e529b943ad..48c9e518ab105 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/table/RenameTableStatementSchemaRefresher.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaMetaDataPOJO; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.RenameTableDefinitionSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.RenameTableStatement; @@ -61,7 +61,7 @@ private ShardingSphereTable getTable(final ShardingSphereDatabase database, fina final ConfigurationProperties props) throws SQLException { RuleMetaData ruleMetaData = new RuleMetaData(new LinkedList<>(database.getRuleMetaData().getRules())); if (TableRefreshUtils.isSingleTable(tableName, database) && !logicDataSourceNames.isEmpty()) { - ruleMetaData.getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); + ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, tableName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java index 5e472912a3e6c..0bf9f2da574a4 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/AlterViewStatementSchemaRefresher.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaMetaDataPOJO; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterViewStatement; import org.apache.shardingsphere.sql.parser.sql.dialect.handler.ddl.AlterViewStatementHandler; @@ -75,7 +75,7 @@ private ShardingSphereSchema getSchema(final ShardingSphereDatabase database, fi final String schemaName, final String viewName, final String viewDefinition, final ConfigurationProperties props) throws SQLException { RuleMetaData ruleMetaData = new RuleMetaData(new LinkedList<>(database.getRuleMetaData().getRules())); if (TableRefreshUtils.isSingleTable(viewName, database)) { - ruleMetaData.getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); + ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); diff --git a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java index b4a51ae7ea473..9d2b99e9a83ef 100644 --- a/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java +++ b/infra/context/src/main/java/org/apache/shardingsphere/infra/connection/refresher/type/view/CreateViewStatementSchemaRefresher.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaMetaDataPOJO; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateViewStatement; import java.sql.SQLException; @@ -51,7 +51,7 @@ public void refresh(final ModeContextManager modeContextManager, final ShardingS String viewName = TableRefreshUtils.getTableName(databaseType, sqlStatement.getView().getTableName().getIdentifier()); RuleMetaData ruleMetaData = new RuleMetaData(new LinkedList<>(database.getRuleMetaData().getRules())); if (TableRefreshUtils.isSingleTable(viewName, database)) { - ruleMetaData.getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); + ruleMetaData.getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceNames.iterator().next(), schemaName, viewName)); } GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial( database.getProtocolType(), database.getResourceMetaData().getStorageUnits(), ruleMetaData.getRules(), props, schemaName); 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 05c965c32cbca..c5eee0ec32101 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 @@ -28,8 +28,8 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +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.single.api.constant.SingleTableConstants; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; @@ -64,7 +64,7 @@ public static String getTableName(final DatabaseType databaseType, final Identif * @return whether single table */ public static boolean isSingleTable(final String tableName, final ShardingSphereDatabase database) { - return database.getRuleMetaData().getRuleIdentifiers(TableMapperRule.class).stream().noneMatch(each -> each.getDistributedTableMapper().contains(tableName)); + return database.getRuleMetaData().getAttributes(TableMapperRuleAttribute.class).stream().noneMatch(each -> each.getDistributedTableMapper().contains(tableName)); } /** @@ -95,7 +95,7 @@ public static boolean isRuleRefreshRequired(final RuleMetaData ruleMetaData, fin public static boolean isRuleRefreshRequired(final RuleMetaData ruleMetaData, final String schemaName, final String tableName) { Collection rules = new LinkedList<>(); for (ShardingSphereRule each : ruleMetaData.getRules()) { - each.getRuleIdentifiers().findIdentifier(MutableDataNodeRule.class).ifPresent(optional -> rules.add(each)); + each.getAttributes().findAttribute(MutableDataNodeRuleAttribute.class).ifPresent(optional -> rules.add(each)); } if (rules.isEmpty()) { return false; @@ -109,7 +109,7 @@ public static boolean isRuleRefreshRequired(final RuleMetaData ruleMetaData, fin if (tablesConfig.contains(SingleTableConstants.ALL_TABLES) || tablesConfig.contains(SingleTableConstants.ALL_SCHEMA_TABLES)) { return false; } - Optional dataNode = rule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).findTableDataNode(schemaName, tableName); + Optional dataNode = rule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).findTableDataNode(schemaName, tableName); if (!dataNode.isPresent()) { return false; } diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/ral/rule/spi/database/ImportRuleConfigurationProvider.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/ral/rule/spi/database/ImportRuleConfigurationProvider.java index c4859c2938a5b..07ac40787d6b0 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/ral/rule/spi/database/ImportRuleConfigurationProvider.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/ral/rule/spi/database/ImportRuleConfigurationProvider.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java index 5feff44d1b3fa..a5f6d430a40bc 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/engine/update/rdl/rule/engine/database/type/DropDatabaseRuleOperator.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.instance.mode.ModeContextManager; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapperEngine; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -54,7 +54,7 @@ public Collection operate(final DatabaseRuleDefinitionStatement ModeContextManager modeContextManager = contextManager.getInstanceContext().getModeContextManager(); RuleConfiguration toBeDroppedRuleConfig = executor.buildToBeDroppedRuleConfiguration(sqlStatement); if (sqlStatement instanceof StaticDataSourceContainedRuleAwareStatement) { - for (StaticDataSourceRule each : database.getRuleMetaData().getRuleIdentifiers(StaticDataSourceRule.class)) { + for (StaticDataSourceRuleAttribute each : database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) { ((StaticDataSourceContainedRuleAwareStatement) sqlStatement).getNames().forEach(each::cleanStorageNodeDataSource); } // TODO refactor to new metadata refresh way diff --git a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java index f41baca757966..5517a8465c4e3 100644 --- a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java +++ b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutor.java @@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.ShardingSphereExternalException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import java.sql.SQLException; @@ -109,7 +109,7 @@ private Collection getCurrentStorageUnitNames(final ContextManager conte } private Collection getLogicalDataSourceNames() { - return database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class).stream().flatMap(each -> each.getDataSourceMapper().keySet().stream()).collect(Collectors.toList()); + return database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class).stream().flatMap(each -> each.getDataSourceMapper().keySet().stream()).collect(Collectors.toList()); } @Override diff --git a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java index 8732a4fd251c3..a97caebac8b27 100644 --- a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java +++ b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/RegisterStorageUnitExecutorTest.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.distsql.statement.rdl.resource.unit.type.RegisterStorageUnitStatement; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.test.mock.AutoMockExtension; @@ -85,9 +85,9 @@ void assertExecuteUpdateWithDuplicateStorageUnitNamesWithResourceMetaData() { void assertExecuteUpdateWithDuplicateStorageUnitNamesWithDataSourceContainedRule() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts()).thenReturn(mock(MetaDataContexts.class, RETURNS_DEEP_STUBS)); - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("ds_0", Collections.emptyList())); - when(database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)).thenReturn(Collections.singleton(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class); + when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("ds_0", Collections.emptyList())); + when(database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); assertThrows(InvalidStorageUnitsException.class, () -> executor.executeUpdate(createRegisterStorageUnitStatement(), contextManager)); } diff --git a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java index 1fa4dd5942ae0..4521b9617835e 100644 --- a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java +++ b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/rdl/resource/UnregisterStorageUnitExecutorTest.java @@ -29,8 +29,8 @@ import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; @@ -109,9 +109,9 @@ void assertExecuteUpdateWithStorageUnitNotExisted() { @Test void assertExecuteUpdateWithStorageUnitInUsed() { ShardingSphereRule rule = mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS); - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("foo_ds"))); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class); + when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("foo_ds"))); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule))); assertThrows(StorageUnitInUsedException.class, () -> executor.executeUpdate(new UnregisterStorageUnitStatement(Collections.singleton("foo_ds"), false, false), mock(ContextManager.class))); } @@ -140,9 +140,9 @@ void assertExecuteUpdateWithIfExists() throws SQLException { @Test void assertExecuteUpdateWithStorageUnitInUsedWithIfExists() { ShardingSphereRule rule = mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS); - DataSourceMapperRule dataSourceMapperRule = mock(DataSourceMapperRule.class); - when(dataSourceMapperRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("foo_ds"))); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataSourceMapperRule)); + DataSourceMapperRuleAttribute ruleAttribute = mock(DataSourceMapperRuleAttribute.class); + when(ruleAttribute.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("foo_ds"))); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule))); assertThrows(DistSQLException.class, () -> executor.executeUpdate(new UnregisterStorageUnitStatement(true, Collections.singleton("foo_ds"), true, false), contextManager)); } diff --git a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/DistSQLHandlerFixtureRule.java b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/DistSQLHandlerFixtureRule.java index 18c1d0bcc4751..34313dd132d1a 100644 --- a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/DistSQLHandlerFixtureRule.java +++ b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/fixture/DistSQLHandlerFixtureRule.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.util.Collections; import java.util.Optional; @@ -38,12 +38,12 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(getDataNodeRule()); + public RuleAttributes getAttributes() { + return new RuleAttributes(getDataNodeRuleAttribute()); } - private DataNodeRule getDataNodeRule() { - DataNodeRule result = mock(DataNodeRule.class); + private DataNodeRuleAttribute getDataNodeRuleAttribute() { + DataNodeRuleAttribute result = mock(DataNodeRuleAttribute.class); DataNode dataNode = mock(DataNode.class); when(dataNode.getDataSourceName()).thenReturn("foo_ds"); when(result.getAllDataNodes()).thenReturn(Collections.singletonMap("", Collections.singleton(dataNode))); diff --git a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/DecoratorRuleFixture.java b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/DecoratorRuleFixture.java index 00368fce403b7..86f8b0b88f330 100644 --- a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/DecoratorRuleFixture.java +++ b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/DecoratorRuleFixture.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -31,7 +31,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/MergerRuleFixture.java b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/MergerRuleFixture.java index ef40c61e9d856..0c965ba98534e 100644 --- a/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/MergerRuleFixture.java +++ b/infra/merge/src/test/java/org/apache/shardingsphere/infra/merge/fixture/rule/MergerRuleFixture.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -31,7 +31,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteFailureRuleFixture.java b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteFailureRuleFixture.java index 6a6bc169304e2..ee58632a5b7ca 100644 --- a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteFailureRuleFixture.java +++ b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteFailureRuleFixture.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -31,7 +31,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteRuleFixture.java b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteRuleFixture.java index 285bffa4d9a06..97783668bf6f7 100644 --- a/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteRuleFixture.java +++ b/infra/route/src/test/java/org/apache/shardingsphere/infra/route/fixture/rule/RouteRuleFixture.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -31,7 +31,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java index febb9eb33b830..9e956f63af65e 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/DriverJDBCExecutor.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.instance.mode.ModeContextManager; import org.apache.shardingsphere.infra.route.context.RouteUnit; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -106,8 +106,8 @@ public int executeUpdate(final ExecutionGroupContext executio private boolean isNeedAccumulate(final Collection rules, final SQLStatementContext sqlStatementContext) { for (ShardingSphereRule each : rules) { - Optional dataNodeRule = each.getRuleIdentifiers().findIdentifier(DataNodeRule.class); - if (dataNodeRule.isPresent() && dataNodeRule.get().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) { + Optional ruleAttribute = each.getAttributes().findAttribute(DataNodeRuleAttribute.class); + if (ruleAttribute.isPresent() && ruleAttribute.get().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) { return true; } } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java index 1059f69abf86c..dfca1b1469bb7 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutor.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor; import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback; import org.apache.shardingsphere.infra.metadata.user.Grantee; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -157,7 +157,7 @@ protected Optional getSaneResult(final SQLStatement sqlStatement, final S } private boolean isNeedAccumulate(final SQLStatementContext sqlStatementContext) { - for (DataNodeRule each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(DataNodeRule.class)) { + for (DataNodeRuleAttribute each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) { if (each.isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) { return true; } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java index 323924bd9a69a..37687f3196174 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/metadata/ShardingSphereDatabaseMetaData.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.driver.jdbc.core.resultset.DatabaseMetaDataResultSet; import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.sql.Connection; import java.sql.DatabaseMetaData; @@ -201,22 +201,22 @@ public ResultSet getPseudoColumns(final String catalog, final String schemaPatte private String getActualTableNamePattern(final String tableNamePattern) { return null == tableNamePattern ? null - : findDataNodeRule().filter(optional -> optional.findFirstActualTable(tableNamePattern).isPresent()).map(optional -> "%" + tableNamePattern + "%").orElse(tableNamePattern); + : findDataNodeRuleAttribute().filter(optional -> optional.findFirstActualTable(tableNamePattern).isPresent()).map(optional -> "%" + tableNamePattern + "%").orElse(tableNamePattern); } private String getActualTable(final String catalog, final String table) { - return null == table ? null : findDataNodeRule().map(each -> findActualTable(each, catalog, table).orElse(table)).orElse(table); + return null == table ? null : findDataNodeRuleAttribute().map(each -> findActualTable(each, catalog, table).orElse(table)).orElse(table); } - private Optional findActualTable(final DataNodeRule dataNodeRule, final String catalog, final String table) { - return Strings.isNullOrEmpty(catalog) ? dataNodeRule.findFirstActualTable(table) : dataNodeRule.findActualTableByCatalog(catalog, table); + private Optional findActualTable(final DataNodeRuleAttribute ruleAttribute, final String catalog, final String table) { + return Strings.isNullOrEmpty(catalog) ? ruleAttribute.findFirstActualTable(table) : ruleAttribute.findActualTableByCatalog(catalog, table); } - private Optional findDataNodeRule() { + private Optional findDataNodeRuleAttribute() { for (ShardingSphereRule each : rules) { - Optional dataNodeRule = each.getRuleIdentifiers().findIdentifier(DataNodeRule.class); - if (dataNodeRule.isPresent()) { - return dataNodeRule; + Optional ruleAttribute = each.getAttributes().findAttribute(DataNodeRuleAttribute.class); + if (ruleAttribute.isPresent()) { + return ruleAttribute; } } return Optional.empty(); diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java index 9c157a87695f4..0baa225a3c6f4 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedDatabaseMetaDataResultSet; import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.util.ResultSetUtils; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.math.BigDecimal; import java.net.URL; @@ -107,11 +107,11 @@ private Iterator initIterator(final ResultSet resultSet) private DatabaseMetaDataObject generateDatabaseMetaDataObject(final int tableNameColumnIndex, final int indexNameColumnIndex, final ResultSet resultSet) throws SQLException { DatabaseMetaDataObject result = new DatabaseMetaDataObject(resultSetMetaData.getColumnCount()); - Optional dataNodeRule = findDataNodeRule(); + Optional ruleAttribute = findDataNodeRuleAttribute(); for (int i = 1; i <= columnLabelIndexMap.size(); i++) { if (tableNameColumnIndex == i) { String tableName = resultSet.getString(i); - Optional logicTableName = dataNodeRule.isPresent() ? dataNodeRule.get().findLogicTableByActualTable(tableName) : Optional.empty(); + Optional logicTableName = ruleAttribute.isPresent() ? ruleAttribute.get().findLogicTableByActualTable(tableName) : Optional.empty(); result.addObject(logicTableName.orElse(tableName)); } else if (indexNameColumnIndex == i) { String tableName = resultSet.getString(tableNameColumnIndex); @@ -124,11 +124,11 @@ private DatabaseMetaDataObject generateDatabaseMetaDataObject(final int tableNam return result; } - private Optional findDataNodeRule() { + private Optional findDataNodeRuleAttribute() { for (ShardingSphereRule each : rules) { - Optional dataNodeRule = each.getRuleIdentifiers().findIdentifier(DataNodeRule.class); - if (dataNodeRule.isPresent()) { - return dataNodeRule; + Optional ruleAttribute = each.getAttributes().findAttribute(DataNodeRuleAttribute.class); + if (ruleAttribute.isPresent()) { + return ruleAttribute; } } return Optional.empty(); diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java index dcf8ffd90d461..8398fa0013d98 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetMetaData.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.sql.ResultSetMetaData; import java.sql.SQLException; @@ -138,11 +138,11 @@ public int getScale(final int column) throws SQLException { @Override public String getTableName(final int column) throws SQLException { - return decorateTableName(database.getRuleMetaData().getRuleIdentifiers(DataNodeRule.class), resultSetMetaData.getTableName(column)); + return decorateTableName(database.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class), resultSetMetaData.getTableName(column)); } - private String decorateTableName(final Collection dataNodeRules, final String actualTableName) { - for (DataNodeRule each : dataNodeRules) { + private String decorateTableName(final Collection ruleAttributes, final String actualTableName) { + for (DataNodeRuleAttribute each : ruleAttributes) { if (each.findLogicTableByActualTable(actualTableName).isPresent()) { return each.findLogicTableByActualTable(actualTableName).get(); } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java index 63ff36180e9c3..7c33d2b42ce79 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java @@ -76,9 +76,9 @@ import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.parser.SQLParserEngine; import org.apache.shardingsphere.infra.route.context.RouteContext; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.raw.RawExecutionRule; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.StorageConnectorReusableRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.raw.RawExecutionRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.resoure.StorageConnectorReusableRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.parser.rule.SQLParserRule; @@ -219,7 +219,7 @@ private ShardingSpherePreparedStatement(final ShardingSphereConnection connectio } private boolean isStatementsCacheable(final RuleMetaData databaseRuleMetaData) { - return databaseRuleMetaData.getRuleIdentifiers(StorageConnectorReusableRule.class).size() == databaseRuleMetaData.getRules().size() && !HintManager.isInstantiated(); + return databaseRuleMetaData.getAttributes(StorageConnectorReusableRuleAttribute.class).size() == databaseRuleMetaData.getRules().size() && !HintManager.isInstantiated(); } @Override @@ -442,7 +442,7 @@ public boolean execute() throws SQLException { } private boolean hasRawExecutionRule() { - return !metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(RawExecutionRule.class).isEmpty(); + return !metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty(); } private ExecutionGroupContext createRawExecutionGroupContext(final ExecutionContext executionContext) throws SQLException { @@ -756,7 +756,7 @@ public int getResultSetHoldability() { @Override public boolean isAccumulate() { - for (DataNodeRule each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(DataNodeRule.class)) { + for (DataNodeRuleAttribute each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) { if (each.isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames())) { return true; } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java index eadf56b700709..d0a126f646c51 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java @@ -71,8 +71,8 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.route.context.RouteContext; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.raw.RawExecutionRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.raw.RawExecutionRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.parser.rule.SQLParserRule; @@ -224,7 +224,7 @@ private Optional getInstanceId(final QueryContext queryContext) { } private List executeQuery0(final ExecutionContext executionContext) throws SQLException { - if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(RawExecutionRule.class).isEmpty()) { + if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { return executor.getRawExecutor().execute( createRawExecutionContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()).stream().map(QueryResult.class::cast).collect(Collectors.toList()); } @@ -330,7 +330,7 @@ private int executeUpdate0(final String sql, final ExecuteUpdateCallback updateC return executor.getTrafficExecutor().execute(executionUnit, trafficCallback); } executionContext = createExecutionContext(queryContext); - if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(RawExecutionRule.class).isEmpty()) { + if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { Collection results = executor.getRawExecutor().execute(createRawExecutionContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); return accumulate(results); } @@ -459,7 +459,7 @@ private boolean execute0(final String sql, final ExecuteCallback executeCallback return null != resultSet; } executionContext = createExecutionContext(queryContext); - if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(RawExecutionRule.class).isEmpty()) { + if (!metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(RawExecutionRuleAttribute.class).isEmpty()) { Collection results = executor.getRawExecutor().execute(createRawExecutionContext(executionContext), executionContext.getQueryContext(), new RawSQLExecutorCallback()); return results.iterator().next() instanceof QueryResult; } @@ -666,7 +666,7 @@ public int getResultSetHoldability() { @Override public boolean isAccumulate() { - for (DataNodeRule each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(DataNodeRule.class)) { + for (DataNodeRuleAttribute each : metaDataContexts.getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) { if (each.isNeedAccumulate(executionContext.getSqlStatementContext().getTablesContext().getTableNames())) { return true; } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java index 36479d6656ae2..899e8b8a09025 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java @@ -33,8 +33,8 @@ import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.user.Grantee; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.sharding.rule.ShardingRule; @@ -118,9 +118,9 @@ private TransactionRule mockTransactionRule() { private ShardingRule mockShardingRule() { ShardingRule result = mock(ShardingRule.class, RETURNS_DEEP_STUBS); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.isNeedAccumulate(any())).thenReturn(true); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.isNeedAccumulate(any())).thenReturn(true); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java index 575a83ece9ba8..923c9d4b8be35 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.traffic.rule.TrafficRule; import org.apache.shardingsphere.traffic.rule.builder.DefaultTrafficRuleConfigurationBuilder; @@ -103,9 +103,9 @@ void assertSetSchema() throws SQLException { private Connection createConnectionAdaptor() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn( new RuleMetaData(Arrays.asList(transactionRule, new TrafficRule(new DefaultTrafficRuleConfigurationBuilder().build())))); return new ShardingSphereConnection(DefaultDatabase.LOGIC_NAME, contextManager); diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java index bbce679f7d572..74bd32033021a 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.parser.rule.SQLParserRule; import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder; @@ -252,10 +252,10 @@ private ShardingSphereStatement mockShardingSphereStatement(final Statement... s private ShardingSphereStatement mockShardingSphereStatementWithNeedAccumulate(final Statement... statements) { ShardingSphereConnection connection = mock(ShardingSphereConnection.class, RETURNS_DEEP_STUBS); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.isNeedAccumulate(any())).thenReturn(true); - when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getRuleIdentifiers(DataNodeRule.class)) - .thenReturn(Collections.singleton(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.isNeedAccumulate(any())).thenReturn(true); + when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase(DefaultDatabase.LOGIC_NAME).getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) + .thenReturn(Collections.singleton(ruleAttribute)); when(connection.getDatabaseName()).thenReturn("db"); DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase("db").getProtocolType()).thenReturn(databaseType); diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java index c0a8a02ab114b..1b4ce67dddc67 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/DriverDatabaseConnectionManagerTest.java @@ -27,8 +27,8 @@ import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; @@ -84,9 +84,9 @@ private ContextManager mockContextManager() throws SQLException { MetaDataPersistService persistService = mockMetaDataPersistService(); when(result.getMetaDataContexts().getPersistService()).thenReturn(persistService); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn( new RuleMetaData(Arrays.asList(transactionRule, mock(TrafficRule.class, RETURNS_DEEP_STUBS)))); when(result.getInstanceContext().getAllClusterInstances(InstanceType.PROXY, Arrays.asList("OLTP", "OLAP"))).thenReturn( diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSetTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSetTest.java index afb7efe1408bb..d82f9ca4ce955 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSetTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSetTest.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.driver.jdbc.core.resultset; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -137,9 +137,9 @@ private ResultSet mockResultSet() throws SQLException { private ShardingRule mockShardingRule() { ShardingRule result = mock(ShardingRule.class, RETURNS_DEEP_STUBS); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.findLogicTableByActualTable(ACTUAL_TABLE_NAME)).thenReturn(Optional.of(LOGIC_TABLE_NAME)); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.findLogicTableByActualTable(ACTUAL_TABLE_NAME)).thenReturn(Optional.of(LOGIC_TABLE_NAME)); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java index 327a6fae50146..268d50fab9de6 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java @@ -21,8 +21,8 @@ import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.traffic.rule.TrafficRule; import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine; @@ -46,9 +46,9 @@ class UnsupportedOperationConnectionTest { UnsupportedOperationConnectionTest() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Arrays.asList(transactionRule, mock(TrafficRule.class)))); shardingSphereConnection = new ShardingSphereConnection(DefaultDatabase.LOGIC_NAME, contextManager); } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java index a974bb6d71711..741c1664c928f 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/DriverStateContextTest.java @@ -25,8 +25,8 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.state.cluster.ClusterStateContext; import org.apache.shardingsphere.infra.state.instance.InstanceStateContext; @@ -65,9 +65,9 @@ class DriverStateContextTest { void setUp() { Map databases = mockDatabases(); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); TrafficRule trafficRule = mock(TrafficRule.class); RuleMetaData globalRuleMetaData = new RuleMetaData(Arrays.asList(transactionRule, trafficRule)); MetaDataContexts metaDataContexts = new MetaDataContexts( diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java index afb14493a2d7b..4f817db2a188b 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/state/ok/OKDriverStateTest.java @@ -20,8 +20,8 @@ import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.traffic.rule.TrafficRule; import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine; @@ -44,9 +44,9 @@ class OKDriverStateTest { void assertGetConnection() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Arrays.asList(transactionRule, mock(TrafficRule.class)))); Connection actual = new OKDriverState().getConnection(DefaultDatabase.LOGIC_NAME, contextManager); assertThat(actual, instanceOf(ShardingSphereConnection.class)); diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java index 9636f82d73178..d44f1d918275c 100644 --- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java +++ b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/AuthorityRule.java @@ -23,8 +23,8 @@ import org.apache.shardingsphere.authority.spi.PrivilegeProvider; import org.apache.shardingsphere.infra.metadata.user.Grantee; import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import java.util.Map; @@ -82,7 +82,7 @@ public Optional findPrivileges(final Grantee grantee) } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtils.java b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtils.java index da667565d4248..a7fab4f593ec4 100644 --- a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtils.java +++ b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtils.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.data.pipeline.core.exception.param.PipelineInvalidParameterException; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sharding.rule.ShardingTable; import org.apache.shardingsphere.single.rule.SingleRule; @@ -57,8 +57,8 @@ public static Map> buildDataNodesMap(final ShardingSphere Map> result = new HashMap<>(); // TODO support virtual data source name for (String each : tableNames) { - if (singleRule.isPresent() && singleRule.get().getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().containsKey(each)) { - result.put(each, new ArrayList<>(singleRule.get().getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().get(each))); + if (singleRule.isPresent() && singleRule.get().getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().containsKey(each)) { + result.put(each, new ArrayList<>(singleRule.get().getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().get(each))); continue; } if (shardingRule.isPresent() && shardingRule.get().findShardingTable(each).isPresent()) { @@ -66,8 +66,8 @@ public static Map> buildDataNodesMap(final ShardingSphere result.put(each, shardingTable.getActualDataNodes()); continue; } - if (broadcastRule.isPresent() && broadcastRule.get().getRuleIdentifiers().getIdentifier(DataNodeRule.class).findFirstActualTable(each).isPresent()) { - result.put(each, Collections.singletonList(broadcastRule.get().getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().get(each).iterator().next())); + if (broadcastRule.isPresent() && broadcastRule.get().getAttributes().getAttribute(DataNodeRuleAttribute.class).findFirstActualTable(each).isPresent()) { + result.put(each, Collections.singletonList(broadcastRule.get().getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().get(each).iterator().next())); continue; } throw new PipelineInvalidParameterException(String.format("Not find actual data nodes of `%s`", each)); diff --git a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtilsTest.java b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtilsTest.java index c05ebfce54be3..b9533157a792d 100644 --- a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtilsTest.java +++ b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCDataNodeUtilsTest.java @@ -21,8 +21,8 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.sharding.rule.ShardingRule; import org.apache.shardingsphere.sharding.rule.ShardingTable; import org.apache.shardingsphere.single.rule.SingleRule; @@ -55,16 +55,16 @@ void assertBuildDataNodesMap() { when(mockRuleMetaData.findSingleRule(ShardingRule.class)).thenReturn(Optional.of(mockShardingRule)); SingleRule singleRule = mock(SingleRule.class); when(mockRuleMetaData.findSingleRule(SingleRule.class)).thenReturn(Optional.of(singleRule)); - DataNodeRule singleDataNodeRule = mock(DataNodeRule.class); - when(singleDataNodeRule.getAllDataNodes()).thenReturn(Collections.singletonMap("t_order_item", Collections.singletonList(new DataNode("single.t_order_item")))); - when(singleRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(singleDataNodeRule)); + DataNodeRuleAttribute singleDataNodeRuleAttribute = mock(DataNodeRuleAttribute.class); + when(singleDataNodeRuleAttribute.getAllDataNodes()).thenReturn(Collections.singletonMap("t_order_item", Collections.singletonList(new DataNode("single.t_order_item")))); + when(singleRule.getAttributes()).thenReturn(new RuleAttributes(singleDataNodeRuleAttribute)); when(mockDatabase.getRuleMetaData()).thenReturn(mockRuleMetaData); BroadcastRule broadcastRule = mock(BroadcastRule.class, RETURNS_DEEP_STUBS); when(mockRuleMetaData.findSingleRule(BroadcastRule.class)).thenReturn(Optional.of(broadcastRule)); - DataNodeRule broadcastDataNodeRule = mock(DataNodeRule.class); - when(broadcastDataNodeRule.findFirstActualTable("t_address")).thenReturn(Optional.of("broadcast.t_address")); - when(broadcastDataNodeRule.getAllDataNodes()).thenReturn(Collections.singletonMap("t_address", Collections.singletonList(new DataNode("broadcast.t_address")))); - when(broadcastRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(broadcastDataNodeRule)); + DataNodeRuleAttribute broadcastDataNodeRuleAttribute = mock(DataNodeRuleAttribute.class); + when(broadcastDataNodeRuleAttribute.findFirstActualTable("t_address")).thenReturn(Optional.of("broadcast.t_address")); + when(broadcastDataNodeRuleAttribute.getAllDataNodes()).thenReturn(Collections.singletonMap("t_address", Collections.singletonList(new DataNode("broadcast.t_address")))); + when(broadcastRule.getAttributes()).thenReturn(new RuleAttributes(broadcastDataNodeRuleAttribute)); Map> actual = CDCDataNodeUtils.buildDataNodesMap(mockDatabase, Arrays.asList("t_order", "t_order_item", "t_address")); assertTrue(actual.containsKey("t_order")); assertTrue(actual.containsKey("t_order_item")); diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java index cd8af08e59308..5f9934951a636 100644 --- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java +++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/rule/GlobalClockRule.java @@ -24,8 +24,8 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.transaction.spi.TransactionHook; @@ -75,7 +75,7 @@ public String getGlobalClockProviderType() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java index c17f2aa1bfd9b..1de955483517c 100644 --- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java +++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/LoggingRule.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.logging.rule; import lombok.Getter; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration; /** @@ -35,7 +35,7 @@ public LoggingRule(final LoggingRuleConfiguration ruleConfig) { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDecider.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDecider.java index 62b02a74ca108..0799b25da5fa9 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDecider.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDecider.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.single.constant.SingleOrder; import org.apache.shardingsphere.single.rule.SingleRule; import org.apache.shardingsphere.sqlfederation.spi.SQLFederationDecider; @@ -68,7 +68,7 @@ private boolean containsView(final ShardingSphereDatabase database, final Collec private Collection getTableDataNodes(final SingleRule rule, final Collection singleTables) { Collection result = new HashSet<>(); for (QualifiedTable each : singleTables) { - rule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).findTableDataNode(each.getSchemaName(), each.getTableName()).ifPresent(result::add); + rule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).findTableDataNode(each.getSchemaName(), each.getTableName()).ifPresent(result::add); } return result; } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngine.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngine.java index 44a03de064b11..f62365ed3cca4 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngine.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngine.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.route.context.RouteUnit; import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnsupportedSQLOperationException; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.single.exception.SingleTableNotFoundException; import org.apache.shardingsphere.single.rule.SingleRule; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -86,7 +86,7 @@ private Collection getDataNodes(final RouteContext routeContext) { private void routeDDLStatement(final RouteContext routeContext, final SingleRule rule) { if (sqlStatement instanceof CreateTableStatement) { QualifiedTable table = singleTables.iterator().next(); - Optional dataNode = rule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).findTableDataNode(table.getSchemaName(), table.getTableName()); + Optional dataNode = rule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).findTableDataNode(table.getSchemaName(), table.getTableName()); boolean containsIfNotExists = CreateTableStatementHandler.ifNotExists((CreateTableStatement) sqlStatement); if (dataNode.isPresent() && containsIfNotExists) { String dataSourceName = dataNode.map(DataNode::getDataSourceName).orElse(null); @@ -105,7 +105,7 @@ private void routeDDLStatement(final RouteContext routeContext, final SingleRule private void fillRouteContext(final SingleRule singleRule, final RouteContext routeContext, final Collection logicTables) { for (QualifiedTable each : logicTables) { String tableName = each.getTableName(); - Optional dataNode = singleRule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).findTableDataNode(each.getSchemaName(), tableName); + Optional dataNode = singleRule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).findTableDataNode(each.getSchemaName(), tableName); ShardingSpherePreconditions.checkState(dataNode.isPresent(), () -> new SingleTableNotFoundException(tableName)); String dataSource = dataNode.get().getDataSourceName(); routeContext.putRouteUnit(new RouteMapper(dataSource, dataSource), Collections.singletonList(new RouteMapper(tableName, tableName))); diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleDataNodeRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleDataNodeRuleAttribute.java similarity index 90% rename from kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleDataNodeRule.java rename to kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleDataNodeRuleAttribute.java index ab6807ad3a088..6ba991ae14a8e 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleDataNodeRule.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleDataNodeRuleAttribute.java @@ -19,7 +19,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import java.util.Collection; import java.util.Collections; @@ -27,10 +27,10 @@ import java.util.Optional; /** - * Single data node rule. + * Single data node rule attribute. */ @RequiredArgsConstructor -public final class SingleDataNodeRule implements DataNodeRule { +public final class SingleDataNodeRuleAttribute implements DataNodeRuleAttribute { private final Map> tableDataNodes; diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRuleAttribute.java similarity index 70% rename from kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRule.java rename to kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRuleAttribute.java index f34d646c96610..97b312c716572 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRule.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleExportableRuleAttribute.java @@ -18,22 +18,22 @@ package org.apache.shardingsphere.single.rule; import lombok.RequiredArgsConstructor; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.ExportableRule; -import org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants; +import org.apache.shardingsphere.infra.rule.attribute.exportable.ExportableRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableConstants; import java.util.Collections; import java.util.Map; /** - * Single exportable rule. + * Single exportable rule attribute. */ @RequiredArgsConstructor -public final class SingleExportableRule implements ExportableRule { +public final class SingleExportableRuleAttribute implements ExportableRuleAttribute { - private final SingleTableMapperRule tableMapperRule; + private final SingleTableMapperRuleAttribute tableMapperRuleAttribute; @Override public Map getExportData() { - return Collections.singletonMap(ExportableConstants.EXPORT_SINGLE_TABLES, tableMapperRule.getLogicTableMapper().getTableNames()); + return Collections.singletonMap(ExportableConstants.EXPORT_SINGLE_TABLES, tableMapperRuleAttribute.getLogicTableMapper().getTableNames()); } } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRuleAttribute.java similarity index 91% rename from kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRule.java rename to kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRuleAttribute.java index 66ef41d16df2b..4ba2df409db20 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRule.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleMutableDataNodeRuleAttribute.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.util.SingleTableLoadUtils; @@ -35,10 +35,10 @@ import java.util.Optional; /** - * Single mutable data node rule. + * Single mutable data node rule attribute. */ @RequiredArgsConstructor -public final class SingleMutableDataNodeRule implements MutableDataNodeRule { +public final class SingleMutableDataNodeRuleAttribute implements MutableDataNodeRuleAttribute { private final SingleRuleConfiguration configuration; @@ -48,7 +48,7 @@ public final class SingleMutableDataNodeRule implements MutableDataNodeRule { private final DatabaseType protocolType; - private final SingleTableMapperRule tableMapperRule; + private final SingleTableMapperRuleAttribute tableMapperRuleAttribute; @Override public void put(final String dataSourceName, final String schemaName, final String tableName) { @@ -57,7 +57,7 @@ public void put(final String dataSourceName, final String schemaName, final Stri DataNode dataNode = new DataNode(dataSourceName, tableName); dataNode.setSchemaName(schemaName); dataNodes.add(dataNode); - tableMapperRule.getLogicTableMapper().put(tableName); + tableMapperRuleAttribute.getLogicTableMapper().put(tableName); addTableConfiguration(dataSourceName, schemaName, tableName); } } @@ -95,7 +95,7 @@ public void remove(final Collection schemaNames, final String tableName) } if (dataNodes.isEmpty()) { singleTableDataNodes.remove(tableName.toLowerCase()); - tableMapperRule.getLogicTableMapper().remove(tableName); + tableMapperRuleAttribute.getLogicTableMapper().remove(tableName); } } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java index c2bea9ddad817..93618cfcb73bd 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java @@ -27,8 +27,8 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable; import org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtils; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager; import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader; @@ -60,10 +60,10 @@ public final class SingleRule implements DatabaseRule { private final DatabaseType protocolType; - private final SingleMutableDataNodeRule mutableDataNodeRule; + private final SingleMutableDataNodeRuleAttribute mutableDataNodeRuleAttribute; @Getter - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public SingleRule(final SingleRuleConfiguration ruleConfig, final String databaseName, final DatabaseType protocolType, final Map dataSourceMap, final Collection builtRules) { @@ -74,9 +74,10 @@ public SingleRule(final SingleRuleConfiguration ruleConfig, final String databas dataSourceNames = aggregateDataSourceMap.keySet(); this.protocolType = protocolType; singleTableDataNodes = SingleTableDataNodeLoader.load(databaseName, protocolType, aggregateDataSourceMap, builtRules, configuration.getTables()); - SingleTableMapperRule tableMapperRule = new SingleTableMapperRule(singleTableDataNodes.values()); - mutableDataNodeRule = new SingleMutableDataNodeRule(configuration, dataSourceNames, singleTableDataNodes, protocolType, tableMapperRule); - ruleIdentifiers = new RuleIdentifiers(new SingleDataNodeRule(singleTableDataNodes), tableMapperRule, new SingleExportableRule(tableMapperRule), mutableDataNodeRule); + SingleTableMapperRuleAttribute tableMapperRuleAttribute = new SingleTableMapperRuleAttribute(singleTableDataNodes.values()); + mutableDataNodeRuleAttribute = new SingleMutableDataNodeRuleAttribute(configuration, dataSourceNames, singleTableDataNodes, protocolType, tableMapperRuleAttribute); + attributes = new RuleAttributes( + new SingleDataNodeRuleAttribute(singleTableDataNodes), tableMapperRuleAttribute, new SingleExportableRuleAttribute(tableMapperRuleAttribute), mutableDataNodeRuleAttribute); } /** @@ -100,7 +101,7 @@ public boolean isAllTablesInSameComputeNode(final Collection dataNodes return false; } QualifiedTable sampleTable = singleTables.iterator().next(); - Optional sampleDataNode = mutableDataNodeRule.findTableDataNode(sampleTable.getSchemaName(), sampleTable.getTableName()); + Optional sampleDataNode = mutableDataNodeRuleAttribute.findTableDataNode(sampleTable.getSchemaName(), sampleTable.getTableName()); if (sampleDataNode.isPresent()) { for (DataNode each : dataNodes) { if (!isSameComputeNode(sampleDataNode.get().getDataSourceName(), each.getDataSourceName())) { @@ -118,7 +119,7 @@ private boolean isSameComputeNode(final String sampleDataSourceName, final Strin private boolean isSingleTablesInSameComputeNode(final Collection singleTables) { String sampleDataSourceName = null; for (QualifiedTable each : singleTables) { - Optional dataNode = mutableDataNodeRule.findTableDataNode(each.getSchemaName(), each.getTableName()); + Optional dataNode = mutableDataNodeRuleAttribute.findTableDataNode(each.getSchemaName(), each.getTableName()); if (!dataNode.isPresent()) { continue; } diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttribute.java similarity index 79% rename from kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRule.java rename to kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttribute.java index 103e66ad2f845..2a4761f0f5b59 100644 --- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRule.java +++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttribute.java @@ -18,19 +18,19 @@ package org.apache.shardingsphere.single.rule; import org.apache.shardingsphere.infra.datanode.DataNode; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableNamesMapper; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.table.TableNamesMapper; import java.util.Collection; /** - * Single table mapper rule. + * Single table mapper rule attribute. */ -public final class SingleTableMapperRule implements TableMapperRule { +public final class SingleTableMapperRuleAttribute implements TableMapperRuleAttribute { private final TableNamesMapper logicTableMapper; - public SingleTableMapperRule(final Collection> singleTableDataNodes) { + public SingleTableMapperRuleAttribute(final Collection> singleTableDataNodes) { logicTableMapper = new TableNamesMapper(); singleTableDataNodes.forEach(each -> logicTableMapper.put(each.iterator().next().getTableName())); } 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 e0d04f255aa98..7a1983582ca68 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 @@ -25,8 +25,8 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.single.api.constant.SingleTableConstants; import javax.sql.DataSource; @@ -56,17 +56,17 @@ public final class SingleTableLoadUtils { public static Map getAggregatedDataSourceMap(final Map dataSourceMap, final Collection builtRules) { Map result = new LinkedHashMap<>(dataSourceMap); for (ShardingSphereRule each : builtRules) { - Optional dataSourceMapperRule = each.getRuleIdentifiers().findIdentifier(DataSourceMapperRule.class); - if (dataSourceMapperRule.isPresent()) { - result = getAggregatedDataSourceMap(result, dataSourceMapperRule.get()); + Optional ruleAttribute = each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class); + if (ruleAttribute.isPresent()) { + result = getAggregatedDataSourceMap(result, ruleAttribute.get()); } } return result; } - private static Map getAggregatedDataSourceMap(final Map dataSourceMap, final DataSourceMapperRule dataSourceMapperRule) { + private static Map getAggregatedDataSourceMap(final Map dataSourceMap, final DataSourceMapperRuleAttribute ruleAttribute) { Map result = new LinkedHashMap<>(); - for (Entry> entry : dataSourceMapperRule.getDataSourceMapper().entrySet()) { + for (Entry> entry : ruleAttribute.getDataSourceMapper().entrySet()) { for (String each : entry.getValue()) { if (dataSourceMap.containsKey(each)) { result.putIfAbsent(entry.getKey(), dataSourceMap.remove(each)); @@ -86,10 +86,10 @@ private static Map getAggregatedDataSourceMap(final Map getExcludedTables(final Collection builtRules) { Collection result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); for (ShardingSphereRule each : builtRules) { - Optional tableMapperRule = each.getRuleIdentifiers().findIdentifier(TableMapperRule.class); - if (tableMapperRule.isPresent()) { - result.addAll(tableMapperRule.get().getDistributedTableMapper().getTableNames()); - result.addAll(tableMapperRule.get().getActualTableMapper().getTableNames()); + Optional ruleAttribute = each.getAttributes().findAttribute(TableMapperRuleAttribute.class); + if (ruleAttribute.isPresent()) { + result.addAll(ruleAttribute.get().getDistributedTableMapper().getTableNames()); + result.addAll(ruleAttribute.get().getActualTableMapper().getTableNames()); } } return result; @@ -104,14 +104,14 @@ public static Collection getExcludedTables(final Collection getFeatureRequiredSingleTables(final Collection builtRules) { Collection result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); for (ShardingSphereRule each : builtRules) { - Optional tableMapperRule = each.getRuleIdentifiers().findIdentifier(TableMapperRule.class); - if (!tableMapperRule.isPresent()) { + Optional ruleAttribute = each.getAttributes().findAttribute(TableMapperRuleAttribute.class); + if (!ruleAttribute.isPresent()) { continue; } - if (tableMapperRule.get().getEnhancedTableMapper().getTableNames().isEmpty() || !tableMapperRule.get().getDistributedTableMapper().getTableNames().isEmpty()) { + if (ruleAttribute.get().getEnhancedTableMapper().getTableNames().isEmpty() || !ruleAttribute.get().getDistributedTableMapper().getTableNames().isEmpty()) { continue; } - result.addAll(tableMapperRule.get().getEnhancedTableMapper().getTableNames()); + result.addAll(ruleAttribute.get().getEnhancedTableMapper().getTableNames()); } 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 4f5747749bde7..e3fc84c690af6 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 @@ -21,8 +21,8 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.junit.jupiter.api.BeforeEach; @@ -97,9 +97,9 @@ private ResultSet mockResultSet(final List tableNames) throws SQLExcepti @Test void assertLoad() { ShardingSphereRule builtRule = mock(ShardingSphereRule.class); - TableMapperRule tableMapperRule = mock(TableMapperRule.class, RETURNS_DEEP_STUBS); - when(tableMapperRule.getDistributedTableMapper().getTableNames()).thenReturn(Arrays.asList("salary", "employee", "student")); - when(builtRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(tableMapperRule)); + TableMapperRuleAttribute ruleAttribute = mock(TableMapperRuleAttribute.class, RETURNS_DEEP_STUBS); + when(ruleAttribute.getDistributedTableMapper().getTableNames()).thenReturn(Arrays.asList("salary", "employee", "student")); + when(builtRule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); Map> actual = SingleTableDataNodeLoader.load(DefaultDatabase.LOGIC_NAME, databaseType, dataSourceMap, Collections.singleton(builtRule), configuredSingleTables); assertFalse(actual.containsKey("employee")); assertFalse(actual.containsKey("salary")); diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDeciderTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDeciderTest.java index ca1ddd22e8af4..c15fd731e659c 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDeciderTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/decider/SingleSQLFederationDeciderTest.java @@ -25,8 +25,8 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.single.rule.SingleRule; import org.junit.jupiter.api.Test; @@ -103,10 +103,10 @@ void assertDecideWhenAllTablesNotInSameComputeNode() { private SingleRule createSingleRule(final Collection qualifiedTables) { SingleRule result = mock(SingleRule.class); when(result.getSingleTables(any())).thenReturn(qualifiedTables); - MutableDataNodeRule mutableDataNodeRule = mock(MutableDataNodeRule.class); - when(mutableDataNodeRule.findTableDataNode(DefaultDatabase.LOGIC_NAME, "t_order")).thenReturn(Optional.of(new DataNode("ds_0", "t_order"))); - when(mutableDataNodeRule.findTableDataNode(DefaultDatabase.LOGIC_NAME, "t_order_item")).thenReturn(Optional.of(new DataNode("ds_0", "t_order_item"))); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(mutableDataNodeRule)); + MutableDataNodeRuleAttribute ruleAttribute = mock(MutableDataNodeRuleAttribute.class); + when(ruleAttribute.findTableDataNode(DefaultDatabase.LOGIC_NAME, "t_order")).thenReturn(Optional.of(new DataNode("ds_0", "t_order"))); + when(ruleAttribute.findTableDataNode(DefaultDatabase.LOGIC_NAME, "t_order_item")).thenReturn(Optional.of(new DataNode("ds_0", "t_order_item"))); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java index 7137cae4c41aa..9614d4089c581 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java @@ -35,7 +35,7 @@ import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; @@ -75,7 +75,7 @@ class SingleSQLRouterTest { void assertCreateRouteContextWithSingleDataSource() throws SQLException { SingleRule rule = new SingleRule(new SingleRuleConfiguration(), DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), Collections.singletonMap("foo_ds", new MockedDataSource(mockConnection())), Collections.emptyList()); - rule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().put("t_order", Collections.singleton(createDataNode("foo_ds"))); + rule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().put("t_order", Collections.singleton(createDataNode("foo_ds"))); ShardingSphereDatabase database = mockSingleDatabase(); RouteContext actual = new SingleSQLRouter().createRouteContext(createQueryContext(), mock(RuleMetaData.class), database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext()); @@ -96,7 +96,7 @@ private ShardingSphereDatabase mockSingleDatabase() { void assertCreateRouteContextWithReadwriteSplittingDataSource() throws SQLException { SingleRule rule = new SingleRule(new SingleRuleConfiguration(), DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), Collections.singletonMap("readwrite_ds", new MockedDataSource(mockConnection())), Collections.emptyList()); - rule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().put("t_order", Collections.singletonList(createDataNode("write_ds"))); + rule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().put("t_order", Collections.singletonList(createDataNode("write_ds"))); ShardingSphereDatabase database = mockReadwriteSplittingDatabase(); RouteContext actual = new SingleSQLRouter().createRouteContext(createQueryContext(), mock(RuleMetaData.class), database, rule, new ConfigurationProperties(new Properties()), new ConnectionContext()); diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java index 098e0f5360485..ecba92d84e812 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/engine/SingleStandardRouteEngineTest.java @@ -25,9 +25,9 @@ import org.apache.shardingsphere.infra.route.context.RouteContext; import org.apache.shardingsphere.infra.route.context.RouteMapper; import org.apache.shardingsphere.infra.route.context.RouteUnit; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +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.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment; @@ -65,8 +65,8 @@ class SingleStandardRouteEngineTest { void assertRouteInSameDataSource() throws SQLException { SingleStandardRouteEngine engine = new SingleStandardRouteEngine(mockQualifiedTables(), null); SingleRule singleRule = new SingleRule(new SingleRuleConfiguration(), DefaultDatabase.LOGIC_NAME, new MySQLDatabaseType(), createDataSourceMap(), Collections.emptyList()); - singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().put("t_order", Collections.singleton(mockDataNode("t_order"))); - singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().put("t_order_item", Collections.singleton(mockDataNode("t_order_item"))); + singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().put("t_order", Collections.singleton(mockDataNode("t_order"))); + singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().put("t_order_item", Collections.singleton(mockDataNode("t_order_item"))); RouteContext routeContext = new RouteContext(); engine.route(routeContext, singleRule); List routeUnits = new ArrayList<>(routeContext.getRouteUnits()); @@ -154,9 +154,9 @@ private SQLStatement mockStatement(final boolean ifNotExists) { private SingleRule mockSingleRule() { SingleRule result = mock(SingleRule.class); DataNode dataNode = mock(DataNode.class); - MutableDataNodeRule mutableDataNodeRule = mock(MutableDataNodeRule.class); - when(mutableDataNodeRule.findTableDataNode(DefaultDatabase.LOGIC_NAME, "t_order")).thenReturn(Optional.of(dataNode)); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(mutableDataNodeRule)); + MutableDataNodeRuleAttribute ruleAttribute = mock(MutableDataNodeRuleAttribute.class); + when(ruleAttribute.findTableDataNode(DefaultDatabase.LOGIC_NAME, "t_order")).thenReturn(Optional.of(dataNode)); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } } 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 b648c29df67d8..efca8756d5a92 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,10 +24,10 @@ 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.identifier.type.datanode.MutableDataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +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.table.TableMapperRuleAttribute; import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.junit.jupiter.api.BeforeEach; @@ -103,13 +103,13 @@ private ResultSet mockResultSet(final List tableNames) throws SQLExcepti @Test void assertGetSingleTableDataNodes() { - TableMapperRule tableMapperRule = mock(TableMapperRule.class, RETURNS_DEEP_STUBS); - when(tableMapperRule.getDistributedTableMapper().getTableNames()).thenReturn(Collections.singletonList("t_order")); - when(tableMapperRule.getActualTableMapper().getTableNames()).thenReturn(Arrays.asList("t_order_0", "t_order_1")); + 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")); ShardingSphereRule builtRule = mock(ShardingSphereRule.class); - when(builtRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(tableMapperRule)); + when(builtRule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(builtRule)); - Map> actual = singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes(); + Map> actual = singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes(); assertThat(actual.size(), is(2)); assertTrue(actual.containsKey("employee")); assertTrue(actual.containsKey("student")); @@ -118,12 +118,12 @@ void assertGetSingleTableDataNodes() { @Test void assertGetSingleTableDataNodesWithUpperCase() { ShardingSphereRule builtRule = mock(ShardingSphereRule.class); - TableMapperRule tableMapperRule = mock(TableMapperRule.class, RETURNS_DEEP_STUBS); - when(tableMapperRule.getDistributedTableMapper().getTableNames()).thenReturn(Collections.singleton("T_ORDER")); - when(tableMapperRule.getActualTableMapper().getTableNames()).thenReturn(Arrays.asList("T_ORDER_0", "T_ORDER_1")); - when(builtRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(tableMapperRule)); + 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(builtRule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(builtRule)); - Map> actual = singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes(); + Map> actual = singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes(); assertThat(actual.size(), is(2)); assertTrue(actual.containsKey("employee")); assertTrue(actual.containsKey("student")); @@ -132,7 +132,7 @@ void assertGetSingleTableDataNodesWithUpperCase() { @Test void assertFindSingleTableDataNode() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); - Optional actual = singleRule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).findTableDataNode(DefaultDatabase.LOGIC_NAME, "employee"); + Optional actual = singleRule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).findTableDataNode(DefaultDatabase.LOGIC_NAME, "employee"); assertTrue(actual.isPresent()); assertThat(actual.get().getDataSourceName(), is("foo_ds")); assertThat(actual.get().getTableName(), is("employee")); @@ -141,7 +141,7 @@ void assertFindSingleTableDataNode() { @Test void assertFindSingleTableDataNodeWithUpperCase() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); - Optional actual = singleRule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).findTableDataNode(DefaultDatabase.LOGIC_NAME, "EMPLOYEE"); + Optional actual = singleRule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).findTableDataNode(DefaultDatabase.LOGIC_NAME, "EMPLOYEE"); assertTrue(actual.isPresent()); assertThat(actual.get().getDataSourceName(), is("foo_ds")); assertThat(actual.get().getTableName(), is("employee")); @@ -183,44 +183,44 @@ void assertPut() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); String tableName = "teacher"; String dataSourceName = "foo_ds"; - singleRule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put(dataSourceName, DefaultDatabase.LOGIC_NAME, tableName); + singleRule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put(dataSourceName, DefaultDatabase.LOGIC_NAME, tableName); Collection tableNames = new LinkedList<>(); 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.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("employee")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("student")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("t_order_0")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("t_order_1")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("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")); } @Test void assertRemove() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); String tableName = "employee"; - singleRule.getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).remove(DefaultDatabase.LOGIC_NAME, tableName); + singleRule.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).remove(DefaultDatabase.LOGIC_NAME, tableName); Collection tableNames = new LinkedList<>(); tableNames.add(new QualifiedTable(DefaultDatabase.LOGIC_NAME, "employee")); assertTrue(singleRule.getSingleTables(tableNames).isEmpty()); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("student")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("t_order_0")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().contains("t_order_1")); + 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")); } @Test void assertGetAllDataNodes() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().containsKey("employee")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().containsKey("student")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().containsKey("t_order_0")); - assertTrue(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes().containsKey("t_order_1")); + assertTrue(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().containsKey("employee")); + assertTrue(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().containsKey("student")); + assertTrue(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().containsKey("t_order_0")); + assertTrue(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().containsKey("t_order_1")); } @Test void assertGetDataNodesByTableName() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); - Collection actual = singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getDataNodesByTableName("EMPLOYEE"); + Collection actual = singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getDataNodesByTableName("EMPLOYEE"); assertThat(actual.size(), is(1)); DataNode dataNode = actual.iterator().next(); assertThat(dataNode.getDataSourceName(), is("foo_ds")); @@ -231,20 +231,20 @@ void assertGetDataNodesByTableName() { void assertFindFirstActualTable() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); String logicTable = "employee"; - assertFalse(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).findFirstActualTable(logicTable).isPresent()); + assertFalse(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).findFirstActualTable(logicTable).isPresent()); } @Test void assertIsNeedAccumulate() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); - assertFalse(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).isNeedAccumulate(Collections.emptyList())); + assertFalse(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).isNeedAccumulate(Collections.emptyList())); } @Test void assertFindLogicTableByActualTable() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); String actualTable = "student"; - assertFalse(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).findLogicTableByActualTable(actualTable).isPresent()); + assertFalse(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).findLogicTableByActualTable(actualTable).isPresent()); } @Test @@ -252,6 +252,6 @@ void assertFindActualTableByCatalog() { SingleRule singleRule = new SingleRule(ruleConfig, DefaultDatabase.LOGIC_NAME, new H2DatabaseType(), dataSourceMap, Collections.singleton(mock(ShardingSphereRule.class, RETURNS_DEEP_STUBS))); String catalog = "employee"; String logicTable = "t_order_0"; - assertFalse(singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).findActualTableByCatalog(catalog, logicTable).isPresent()); + assertFalse(singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).findActualTableByCatalog(catalog, logicTable).isPresent()); } } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttributeTest.java similarity index 68% rename from kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleTest.java rename to kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttributeTest.java index 662216387aef6..554611b44113f 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/SingleTableMapperRuleAttributeTest.java @@ -26,22 +26,22 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -class SingleTableMapperRuleTest { +class SingleTableMapperRuleAttributeTest { - private final SingleTableMapperRule tableMapperRule = new SingleTableMapperRule(Collections.singleton(Collections.singleton(new DataNode("foo_ds.foo_tbl")))); + private final SingleTableMapperRuleAttribute ruleAttribute = new SingleTableMapperRuleAttribute(Collections.singleton(Collections.singleton(new DataNode("foo_ds.foo_tbl")))); @Test void assertGetLogicTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); + assertThat(new LinkedList<>(ruleAttribute.getLogicTableMapper().getTableNames()), is(Collections.singletonList("foo_tbl"))); } @Test void assertGetDistributedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getDistributedTableMapper().getTableNames()), is(Collections.emptyList())); + assertThat(new LinkedList<>(ruleAttribute.getDistributedTableMapper().getTableNames()), is(Collections.emptyList())); } @Test void assertGetEnhancedTableMapper() { - assertThat(new LinkedList<>(tableMapperRule.getEnhancedTableMapper().getTableNames()), is(Collections.emptyList())); + assertThat(new LinkedList<>(ruleAttribute.getEnhancedTableMapper().getTableNames()), is(Collections.emptyList())); } } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/builder/SingleRuleBuilderTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/builder/SingleRuleBuilderTest.java index 65961008ae2e9..a0b4751f0d09d 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/builder/SingleRuleBuilderTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/rule/builder/SingleRuleBuilderTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleImportRuleConfigurationProvider.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleImportRuleConfigurationProvider.java index b637fd4b981a9..49081b803a561 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleImportRuleConfigurationProvider.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/provider/SingleImportRuleConfigurationProvider.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.instance.InstanceContext; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java index 1b082931e1e56..073ba4082cf89 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutor.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecutor; import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.util.regex.RegexUtils; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.single.distsql.statement.rql.ShowSingleTableStatement; @@ -52,8 +52,8 @@ public Collection getColumnNames(final ShowSingleTableStatement sqlState @Override public Collection getRows(final ShowSingleTableStatement sqlStatement, final ContextManager contextManager) { Collection resultDataNodes = getPattern(sqlStatement) - .map(optional -> getDataNodesWithLikePattern(rule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes(), optional)) - .orElseGet(() -> getDataNodes(rule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getAllDataNodes(), sqlStatement)); + .map(optional -> getDataNodesWithLikePattern(rule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes(), optional)) + .orElseGet(() -> getDataNodes(rule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes(), sqlStatement)); Collection sortedDataNodes = resultDataNodes.stream().sorted(Comparator.comparing(DataNode::getTableName)).collect(Collectors.toList()); return sortedDataNodes.stream().map(each -> new LocalDataQueryResultRow(each.getTableName(), each.getDataSourceName())).collect(Collectors.toList()); } 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 70167c2e59602..d1f9ccb3ff265 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 @@ -25,7 +25,7 @@ import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader; import org.apache.shardingsphere.single.distsql.statement.rql.ShowUnloadedSingleTableStatement; @@ -58,7 +58,7 @@ public Collection getColumnNames(final ShowUnloadedSingleTableStatement @Override public Collection getRows(final ShowUnloadedSingleTableStatement sqlStatement, final ContextManager contextManager) { Map> actualDataNodes = getActualDataNodes(database); - for (String each : rule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().getTableNames()) { + for (String each : rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames()) { 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 e2d99d4a56632..7588eb38c168e 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 @@ -19,7 +19,7 @@ import org.apache.shardingsphere.distsql.handler.executor.rql.rule.CountResultRowBuilder; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.single.rule.SingleRule; import java.util.Collection; @@ -32,7 +32,8 @@ public final class SingleCountResultRowBuilder implements CountResultRowBuilder< @Override public Collection generateRows(final SingleRule rule, final String databaseName) { - return Collections.singleton(new LocalDataQueryResultRow("single", databaseName, rule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().getTableNames().size())); + return Collections.singleton( + new LocalDataQueryResultRow("single", databaseName, rule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames().size())); } @Override diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java index bdfcfb56737d7..a04ec6a3ab7e2 100644 --- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java +++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.DataSourceMapperRuleAttribute; import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.api.constant.SingleTableConstants; import org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader; @@ -148,7 +148,7 @@ private void checkActualTableExist(final LoadSingleTableStatement sqlStatement, private Collection getLogicDataSources(final ShardingSphereDatabase database) { Collection result = new LinkedHashSet<>(); - for (DataSourceMapperRule each : database.getRuleMetaData().getRuleIdentifiers(DataSourceMapperRule.class)) { + for (DataSourceMapperRuleAttribute each : database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class)) { result.addAll(each.getDataSourceMapper().keySet()); } return result; 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 30e9a5f1c2efe..8ff44831a2bd6 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 @@ -29,8 +29,8 @@ import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.table.TableMapperRuleAttribute; import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.distsql.statement.rdl.UnloadSingleTableStatement; import org.apache.shardingsphere.single.exception.SingleTableNotFoundException; @@ -62,11 +62,11 @@ private void checkTables(final UnloadSingleTableStatement sqlStatement) { } Collection allTables = getAllTableNames(database); SingleRule singleRule = database.getRuleMetaData().getSingleRule(SingleRule.class); - Collection singleTables = singleRule.getRuleIdentifiers().getIdentifier(TableMapperRule.class).getLogicTableMapper().getTableNames(); + Collection singleTables = singleRule.getAttributes().getAttribute(TableMapperRuleAttribute.class).getLogicTableMapper().getTableNames(); for (String each : sqlStatement.getTables()) { checkTableExist(allTables, each); checkIsSingleTable(singleTables, each); - checkTableRuleExist(database.getName(), database.getProtocolType(), singleRule.getRuleIdentifiers().getIdentifier(DataNodeRule.class).getDataNodesByTableName(each), each); + checkTableRuleExist(database.getName(), database.getProtocolType(), singleRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getDataNodesByTableName(each), each); } } diff --git a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java index 69abd2d189290..235b694c69666 100644 --- a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java +++ b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTableExecutorTest.java @@ -22,8 +22,8 @@ import org.apache.shardingsphere.infra.datanode.DataNode; import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.single.distsql.statement.rql.ShowSingleTableStatement; import org.apache.shardingsphere.single.rule.SingleRule; @@ -91,10 +91,10 @@ private SingleRule mockSingleRule() { Map> singleTableDataNodeMap = new HashMap<>(2, 1F); singleTableDataNodeMap.put("t_order", Collections.singleton(new DataNode("ds_1", "t_order"))); singleTableDataNodeMap.put("t_order_item", Collections.singleton(new DataNode("ds_2", "t_order_item"))); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.getAllDataNodes()).thenReturn(singleTableDataNodeMap); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.getAllDataNodes()).thenReturn(singleTableDataNodeMap); SingleRule result = mock(SingleRule.class); - when(result.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(dataNodeRule)); + when(result.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); return result; } } diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationMetaDataHeldRule.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationMetaDataHeldRuleAttribute.java similarity index 91% rename from kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationMetaDataHeldRule.java rename to kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationMetaDataHeldRuleAttribute.java index 267202135f190..b4a5ec7d4f27f 100644 --- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationMetaDataHeldRule.java +++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationMetaDataHeldRuleAttribute.java @@ -20,7 +20,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.metadata.MetaDataHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.metadata.MetaDataHeldRuleAttribute; import org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContext; import org.apache.shardingsphere.sqlfederation.optimizer.context.parser.OptimizerParserContext; import org.apache.shardingsphere.sqlfederation.optimizer.context.parser.dialect.OptimizerSQLPropertiesBuilder; @@ -28,10 +28,10 @@ import org.apache.shardingsphere.sqlfederation.optimizer.context.planner.OptimizerPlannerContextFactory; /** - * SQL federation meta data held rule. + * SQL federation meta data held rule attribute. */ @RequiredArgsConstructor -public final class SQLFederationMetaDataHeldRule implements MetaDataHeldRule { +public final class SQLFederationMetaDataHeldRuleAttribute implements MetaDataHeldRuleAttribute { private final OptimizerContext optimizerContext; diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java index f61dd6f433668..344586fa4062e 100644 --- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java +++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java @@ -20,8 +20,8 @@ import lombok.Getter; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration; import org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContext; import org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContextFactory; @@ -38,11 +38,11 @@ public final class SQLFederationRule implements GlobalRule { private final OptimizerContext optimizerContext; - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public SQLFederationRule(final SQLFederationRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { configuration = ruleConfig; optimizerContext = OptimizerContextFactory.create(databases, props); - ruleIdentifiers = new RuleIdentifiers(new SQLFederationMetaDataHeldRule(optimizerContext)); + attributes = new RuleAttributes(new SQLFederationMetaDataHeldRuleAttribute(optimizerContext)); } } diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java index 20b64d99ee926..c0954b4fa29a6 100644 --- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java +++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration; import org.apache.shardingsphere.sqlfederation.constant.SQLFederationOrder; import org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule; diff --git a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java index 80e992bc4500f..8ab1e9c97d25c 100644 --- a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java +++ b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleMatchFixture.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.sql.parser.api.CacheOption; import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration; @@ -33,7 +33,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java index 6569bb1d7539a..5b42b93618521 100644 --- a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java +++ b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/fixture/rule/SQLFederationDeciderRuleNotMatchFixture.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.sql.parser.api.CacheOption; import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration; @@ -33,7 +33,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/SQLParserRule.java b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/SQLParserRule.java index 70d1c59115dff..ede9bb6eb8138 100644 --- a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/SQLParserRule.java +++ b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/SQLParserRule.java @@ -22,8 +22,8 @@ import org.apache.shardingsphere.infra.parser.SQLParserEngine; import org.apache.shardingsphere.infra.parser.ShardingSphereSQLParserEngine; import org.apache.shardingsphere.infra.parser.SimpleSQLParserEngine; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration; import org.apache.shardingsphere.sql.parser.api.CacheOption; @@ -61,7 +61,7 @@ public SQLParserEngine getSQLParserEngine(final DatabaseType databaseType) { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRule.java b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRule.java index 5c90416766ddf..09ff75782a277 100644 --- a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRule.java +++ b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/SQLTranslatorRule.java @@ -21,8 +21,8 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration; @@ -78,7 +78,7 @@ public SQLTranslatorContext translate(final String sql, final List param } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/TimestampServiceRule.java b/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/TimestampServiceRule.java index 1c3e5238d819b..ff8aa89ce3f85 100644 --- a/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/TimestampServiceRule.java +++ b/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/TimestampServiceRule.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.timeservice.core.rule; import lombok.Getter; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.timeservice.api.config.TimestampServiceRuleConfiguration; import org.apache.shardingsphere.timeservice.spi.TimestampService; @@ -52,7 +52,7 @@ public Timestamp getTimestamp() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java index fec3e0f693c3f..8251fe716a8fc 100644 --- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java +++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/TrafficRule.java @@ -22,8 +22,8 @@ import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration; import org.apache.shardingsphere.infra.algorithm.load.balancer.core.LoadBalanceAlgorithm; import org.apache.shardingsphere.infra.hint.HintValueContext; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement; @@ -192,7 +192,7 @@ public Collection getLabels() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java index ce6b724ca8fdf..b98151d807ee9 100644 --- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java +++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/rule/builder/TrafficRuleBuilder.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration; import org.apache.shardingsphere.traffic.constant.TrafficOrder; import org.apache.shardingsphere.traffic.rule.TrafficRule; diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ConnectionTransaction.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ConnectionTransaction.java index e3179add18398..bda76f0cb5852 100644 --- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ConnectionTransaction.java +++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ConnectionTransaction.java @@ -19,7 +19,7 @@ import lombok.Getter; import lombok.Setter; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext; import org.apache.shardingsphere.transaction.api.TransactionType; import org.apache.shardingsphere.transaction.rule.TransactionRule; @@ -49,7 +49,7 @@ public ConnectionTransaction(final TransactionRule rule) { public ConnectionTransaction(final TransactionType transactionType, final TransactionRule rule) { this.transactionType = transactionType; - transactionManager = ((ShardingSphereTransactionManagerEngine) rule.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()).getTransactionManager(transactionType); + transactionManager = ((ShardingSphereTransactionManagerEngine) rule.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()).getTransactionManager(transactionType); } /** diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionResourceHeldRule.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionResourceHeldRuleAttribute.java similarity index 91% rename from kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionResourceHeldRule.java rename to kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionResourceHeldRuleAttribute.java index 4ad9106578d76..081eb93422caa 100644 --- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionResourceHeldRule.java +++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionResourceHeldRuleAttribute.java @@ -20,7 +20,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine; import org.apache.shardingsphere.transaction.api.TransactionType; @@ -31,10 +31,10 @@ import java.util.concurrent.atomic.AtomicReference; /** - * Transaction resource held rule. + * Transaction resource held rule attribute. */ @Slf4j -public final class TransactionResourceHeldRule implements ResourceHeldRule { +public final class TransactionResourceHeldRuleAttribute implements ResourceHeldRuleAttribute { private final TransactionType defaultType; @@ -44,7 +44,7 @@ public final class TransactionResourceHeldRule implements ResourceHeldRule resource; - public TransactionResourceHeldRule(final TransactionType defaultType, final String providerType, final Map databases) { + public TransactionResourceHeldRuleAttribute(final TransactionType defaultType, final String providerType, final Map databases) { this.defaultType = defaultType; this.providerType = providerType; this.databases = databases; diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java index cc87cf6711cc6..aa37f248cc7ce 100644 --- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java +++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java @@ -19,8 +19,8 @@ import lombok.Getter; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.rule.identifier.scope.GlobalRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.GlobalRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import org.apache.shardingsphere.transaction.api.TransactionType; import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration; @@ -44,7 +44,7 @@ public final class TransactionRule implements GlobalRule { private final Map databases; - private final RuleIdentifiers ruleIdentifiers; + private final RuleAttributes attributes; public TransactionRule(final TransactionRuleConfiguration ruleConfig, final Map databases) { configuration = ruleConfig; @@ -52,6 +52,6 @@ public TransactionRule(final TransactionRuleConfiguration ruleConfig, final Map< providerType = ruleConfig.getProviderType(); props = ruleConfig.getProps(); this.databases = new ConcurrentHashMap<>(databases); - ruleIdentifiers = new RuleIdentifiers(new TransactionResourceHeldRule(defaultType, providerType, this.databases)); + attributes = new RuleAttributes(new TransactionResourceHeldRuleAttribute(defaultType, providerType, this.databases)); } } diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java index e606aa1c1e261..9f92fc32e5557 100644 --- a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java +++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNode; import org.apache.shardingsphere.infra.metadata.database.resource.unit.StorageUnit; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource; import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine; import org.apache.shardingsphere.transaction.api.TransactionType; @@ -52,16 +52,16 @@ class TransactionRuleTest { @Test void assertInitTransactionRuleWithMultiDatabaseType() { TransactionRule actual = new TransactionRule(createTransactionRuleConfiguration(), Collections.singletonMap(SHARDING_DB_1, createDatabase())); - assertNotNull(actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()); - assertThat(((ShardingSphereTransactionManagerEngine) actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()).getTransactionManager(TransactionType.XA), + assertNotNull(actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()); + assertThat(((ShardingSphereTransactionManagerEngine) actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()).getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } @Test void assertAddResource() { TransactionRule actual = new TransactionRule(createTransactionRuleConfiguration(), Collections.singletonMap(SHARDING_DB_1, createDatabase())); - actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).addResource(createAddDatabase()); - assertNotNull(actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()); + actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).addResource(createAddDatabase()); + assertNotNull(actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()); assertThat(actual.getDatabases().size(), is(2)); assertTrue(actual.getDatabases().containsKey(SHARDING_DB_1)); ResourceMetaData resourceMetaData1 = actual.getDatabases().get(SHARDING_DB_1).getResourceMetaData(); @@ -73,25 +73,25 @@ void assertAddResource() { assertThat(resourceMetaData2.getStorageUnits().size(), is(2)); assertTrue(resourceMetaData2.getStorageUnits().containsKey("ds_0")); assertTrue(resourceMetaData2.getStorageUnits().containsKey("ds_1")); - assertThat(((ShardingSphereTransactionManagerEngine) actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()).getTransactionManager(TransactionType.XA), + assertThat(((ShardingSphereTransactionManagerEngine) actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()).getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } @Test void assertCloseStaleResource() { TransactionRule actual = new TransactionRule(createTransactionRuleConfiguration(), Collections.singletonMap(SHARDING_DB_1, createDatabase())); - actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).closeStaleResource(SHARDING_DB_1); + actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).closeStaleResource(SHARDING_DB_1); assertTrue(actual.getDatabases().isEmpty()); - assertThat(((ShardingSphereTransactionManagerEngine) actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()).getTransactionManager(TransactionType.XA), + assertThat(((ShardingSphereTransactionManagerEngine) actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()).getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } @Test void assertCloseAllStaleResources() { TransactionRule actual = new TransactionRule(createTransactionRuleConfiguration(), Collections.singletonMap(SHARDING_DB_1, createDatabase())); - actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).closeStaleResource(); + actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).closeStaleResource(); assertTrue(actual.getDatabases().isEmpty()); - assertThat(((ShardingSphereTransactionManagerEngine) actual.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()).getTransactionManager(TransactionType.XA), + assertThat(((ShardingSphereTransactionManagerEngine) actual.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()).getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java index 09725de767e42..4941536e68d26 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/context/ConfigurationContextManager.java @@ -37,8 +37,8 @@ import org.apache.shardingsphere.infra.rule.ShardingSphereRule; import org.apache.shardingsphere.infra.rule.builder.database.DatabaseRulesBuilder; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRulesBuilder; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.metadata.factory.ExternalMetaDataFactory; import org.apache.shardingsphere.metadata.factory.InternalMetaDataFactory; import org.apache.shardingsphere.metadata.persist.MetaDataBasedPersistService; @@ -80,8 +80,8 @@ public final class ConfigurationContextManager { @SuppressWarnings("rawtypes") public synchronized void registerStorageUnit(final String databaseName, final Map propsMap) { try { - Collection staleResourceHeldRules = getStaleResourceHeldRules(databaseName); - staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResource); + Collection staleResourceHeldRuleAttributes = getStaleResourceHeldRules(databaseName); + staleResourceHeldRuleAttributes.forEach(ResourceHeldRuleAttribute::closeStaleResource); SwitchingResource switchingResource = new NewResourceSwitchManager().registerStorageUnit(metaDataContexts.get().getMetaData().getDatabase(databaseName).getResourceMetaData(), propsMap); buildNewMetaDataContext(databaseName, switchingResource); @@ -99,8 +99,8 @@ public synchronized void registerStorageUnit(final String databaseName, final Ma @SuppressWarnings("rawtypes") public synchronized void alterStorageUnit(final String databaseName, final Map propsMap) { try { - Collection staleResourceHeldRules = getStaleResourceHeldRules(databaseName); - staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResource); + Collection staleResourceHeldRuleAttributes = getStaleResourceHeldRules(databaseName); + staleResourceHeldRuleAttributes.forEach(ResourceHeldRuleAttribute::closeStaleResource); SwitchingResource switchingResource = new NewResourceSwitchManager().alterStorageUnit(metaDataContexts.get().getMetaData().getDatabase(databaseName).getResourceMetaData(), propsMap); buildNewMetaDataContext(databaseName, switchingResource); @@ -118,8 +118,8 @@ public synchronized void alterStorageUnit(final String databaseName, final Map staleResourceHeldRules = getStaleResourceHeldRules(databaseName); - staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResource); + Collection staleResourceHeldRuleAttributes = getStaleResourceHeldRules(databaseName); + staleResourceHeldRuleAttributes.forEach(ResourceHeldRuleAttribute::closeStaleResource); SwitchingResource switchingResource = new NewResourceSwitchManager().unregisterStorageUnit(metaDataContexts.get().getMetaData().getDatabase(databaseName).getResourceMetaData(), Collections.singletonList(storageUnitName)); buildNewMetaDataContext(databaseName, switchingResource); @@ -151,9 +151,9 @@ private void buildNewMetaDataContext(final String databaseName, final SwitchingR @SuppressWarnings("rawtypes") public synchronized void alterRuleConfiguration(final String databaseName, final Collection ruleConfigs) { try { - Collection staleResourceHeldRules = getStaleResourceHeldRules(databaseName); + Collection staleResourceHeldRuleAttributes = getStaleResourceHeldRules(databaseName); // TODO consider rename this method to alterDatabaseRuleConfiguration - staleResourceHeldRules.stream().filter(DatabaseRule.class::isInstance).forEach(ResourceHeldRule::closeStaleResource); + staleResourceHeldRuleAttributes.stream().filter(DatabaseRule.class::isInstance).forEach(ResourceHeldRuleAttribute::closeStaleResource); MetaDataContexts reloadMetaDataContexts = createMetaDataContextsWhenRuleChanged(databaseName, false, null, ruleConfigs); alterSchemaMetaData(databaseName, reloadMetaDataContexts.getMetaData().getDatabase(databaseName), metaDataContexts.get().getMetaData().getDatabase(databaseName)); metaDataContexts.set(reloadMetaDataContexts); @@ -235,8 +235,8 @@ private MetaDataContexts createMetaDataContextsByAlterRule(final String database @SuppressWarnings("rawtypes") public synchronized void alterDataSourceUnitsConfiguration(final String databaseName, final Map propsMap) { try { - Collection staleResourceHeldRules = getStaleResourceHeldRules(databaseName); - staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResource); + Collection staleResourceHeldRuleAttributes = getStaleResourceHeldRules(databaseName); + staleResourceHeldRuleAttributes.forEach(ResourceHeldRuleAttribute::closeStaleResource); SwitchingResource switchingResource = new ResourceSwitchManager().createByAlterDataSourcePoolProperties(metaDataContexts.get().getMetaData().getDatabase(databaseName).getResourceMetaData(), propsMap); metaDataContexts.get().getMetaData().getDatabases().putAll(renewDatabase(metaDataContexts.get().getMetaData().getDatabase(databaseName), switchingResource)); @@ -305,9 +305,9 @@ private Map getNewStorageUnits(final Map getStaleResourceHeldRules(final String databaseName) { - Collection result = metaDataContexts.get().getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(ResourceHeldRule.class); - result.addAll(metaDataContexts.get().getMetaData().getGlobalRuleMetaData().getRuleIdentifiers(ResourceHeldRule.class)); + private Collection getStaleResourceHeldRules(final String databaseName) { + Collection result = metaDataContexts.get().getMetaData().getDatabase(databaseName).getRuleMetaData().getAttributes(ResourceHeldRuleAttribute.class); + result.addAll(metaDataContexts.get().getMetaData().getGlobalRuleMetaData().getAttributes(ResourceHeldRuleAttribute.class)); return result; } @@ -422,7 +422,7 @@ public synchronized void alterGlobalRuleConfiguration(final Collection each.alterDatabase(database)); + metaDataContexts.get().getMetaData().getGlobalRuleMetaData().getAttributes(MetaDataHeldRuleAttribute.class).forEach(each -> each.alterDatabase(database)); metaDataContexts.set(new MetaDataContexts(metaDataContexts.get().getPersistService(), metaDataContexts.get().getMetaData())); } private void alterMetaDataHeldRule(final ShardingSphereDatabase database) { - metaDataContexts.get().getMetaData().getGlobalRuleMetaData().getRuleIdentifiers(MetaDataHeldRule.class).forEach(each -> each.alterDatabase(database)); + metaDataContexts.get().getMetaData().getGlobalRuleMetaData().getAttributes(MetaDataHeldRuleAttribute.class).forEach(each -> each.alterDatabase(database)); } /** @@ -71,7 +71,7 @@ public synchronized void dropDatabase(final String databaseName) { return; } metaDataContexts.get().getMetaData().dropDatabase(metaDataContexts.get().getMetaData().getDatabase(databaseName).getName()); - metaDataContexts.get().getMetaData().getGlobalRuleMetaData().getRuleIdentifiers(MetaDataHeldRule.class).forEach(each -> each.dropDatabase(databaseName)); + metaDataContexts.get().getMetaData().getGlobalRuleMetaData().getAttributes(MetaDataHeldRuleAttribute.class).forEach(each -> each.dropDatabase(databaseName)); } /** @@ -143,12 +143,14 @@ public synchronized void alterSchema(final String databaseName, final String sch private void dropTable(final String databaseName, final String schemaName, final String toBeDeletedTableName) { metaDataContexts.get().getMetaData().getDatabase(databaseName).getSchema(schemaName).removeTable(toBeDeletedTableName); - metaDataContexts.get().getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, toBeDeletedTableName)); + metaDataContexts.get().getMetaData().getDatabase(databaseName) + .getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.remove(schemaName, toBeDeletedTableName)); } private void dropView(final String databaseName, final String schemaName, final String toBeDeletedViewName) { metaDataContexts.get().getMetaData().getDatabase(databaseName).getSchema(schemaName).removeView(toBeDeletedViewName); - metaDataContexts.get().getMetaData().getDatabase(databaseName).getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.remove(schemaName, toBeDeletedViewName)); + metaDataContexts.get().getMetaData().getDatabase(databaseName) + .getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.remove(schemaName, toBeDeletedViewName)); } private void alterTable(final String databaseName, final String schemaName, final ShardingSphereTable beBoChangedTable) { diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java index 860d2ea2697d5..5b1d28f98eabf 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContexts.java @@ -29,7 +29,7 @@ import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereStatistics; import org.apache.shardingsphere.infra.metadata.statistics.ShardingSphereTableData; import org.apache.shardingsphere.infra.metadata.statistics.builder.ShardingSphereStatisticsBuilder; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.MetaDataBasedPersistService; @@ -99,9 +99,9 @@ private void useLoadedToReplaceInitBySchemaData(final ShardingSphereSchemaData i @Override public void close() { persistService.getRepository().close(); - metaData.getGlobalRuleMetaData().getRuleIdentifiers(ResourceHeldRule.class).forEach(ResourceHeldRule::closeStaleResource); + metaData.getGlobalRuleMetaData().getAttributes(ResourceHeldRuleAttribute.class).forEach(ResourceHeldRuleAttribute::closeStaleResource); for (ShardingSphereDatabase each : metaData.getDatabases().values()) { - each.getRuleMetaData().getRuleIdentifiers(ResourceHeldRule.class).forEach(ResourceHeldRule::closeStaleResource); + each.getRuleMetaData().getAttributes(ResourceHeldRuleAttribute.class).forEach(ResourceHeldRuleAttribute::closeStaleResource); } } } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/fixture/ModeRuleFixture.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/fixture/ModeRuleFixture.java index 2091be209f615..6d55e3bc5672e 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/fixture/ModeRuleFixture.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/fixture/ModeRuleFixture.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.mode.fixture; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.scope.DatabaseRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -31,7 +31,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java index 9d61af1ffcf02..b06f0b54855ab 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java @@ -39,8 +39,8 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; @@ -106,9 +106,9 @@ private ShardingSphereDatabase mockDatabase() { when(result.getName()).thenReturn("foo_db"); when(result.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE")); ShardingSphereRule rule = mock(ShardingSphereRule.class); - MutableDataNodeRule mutableDataNodeRule = mock(MutableDataNodeRule.class); - when(mutableDataNodeRule.findTableDataNode("foo_schema", "foo_tbl")).thenReturn(Optional.of(mock(DataNode.class))); - when(rule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(mutableDataNodeRule)); + MutableDataNodeRuleAttribute ruleAttribute = mock(MutableDataNodeRuleAttribute.class); + when(ruleAttribute.findTableDataNode("foo_schema", "foo_tbl")).thenReturn(Optional.of(mock(DataNode.class))); + when(rule.getAttributes()).thenReturn(new RuleAttributes(ruleAttribute)); when(result.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule))); when(result.getSchemas()).thenReturn(new HashMap<>(Collections.singletonMap("foo_schema", new ShardingSphereSchema()))); StorageUnit storageUnit = mock(StorageUnit.class, RETURNS_DEEP_STUBS); diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java index fd07311cbec7b..18f9c03059bd0 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java @@ -20,7 +20,7 @@ import com.google.common.eventbus.Subscribe; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSource; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent; @@ -98,26 +98,25 @@ public synchronized void renew(final PropertiesChangedEvent event) { private void disableDataSources() { Map storageNodes = getDisabledDataSources(); for (Entry entry : contextManager.getMetaDataContexts().getMetaData().getDatabases().entrySet()) { - entry.getValue().getRuleMetaData().getRuleIdentifiers(StaticDataSourceRule.class).forEach(each -> disableDataSources(entry.getKey(), each, storageNodes)); + entry.getValue().getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class).forEach(each -> disableDataSources(entry.getKey(), each, storageNodes)); } } - private void disableDataSources(final String databaseName, final StaticDataSourceRule staticDataSourceRule, final Map storageNodes) { + private void disableDataSources(final String databaseName, final StaticDataSourceRuleAttribute ruleAttribute, final Map storageNodes) { for (Entry entry : storageNodes.entrySet()) { QualifiedDatabase database = new QualifiedDatabase(entry.getKey()); if (!database.getDatabaseName().equals(databaseName)) { continue; } - disableDataSources(entry.getValue(), staticDataSourceRule, database); + disableDataSources(entry.getValue(), ruleAttribute, database); } } - private void disableDataSources(final StorageNodeDataSource storageNodeDataSource, final StaticDataSourceRule staticDataSourceRule, final QualifiedDatabase database) { - for (Entry> entry : staticDataSourceRule.getDataSourceMapper().entrySet()) { - if (!database.getGroupName().equals(entry.getKey())) { - continue; + private void disableDataSources(final StorageNodeDataSource storageNodeDataSource, final StaticDataSourceRuleAttribute ruleAttribute, final QualifiedDatabase database) { + for (Entry> entry : ruleAttribute.getDataSourceMapper().entrySet()) { + if (database.getGroupName().equals(entry.getKey())) { + entry.getValue().forEach(each -> ruleAttribute.updateStatus(new StorageNodeDataSourceChangedEvent(database, storageNodeDataSource))); } - entry.getValue().forEach(each -> staticDataSourceRule.updateStatus(new StorageNodeDataSourceChangedEvent(database, storageNodeDataSource))); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewStateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewStateChangedSubscriber.java index 49b338e86f56e..899e628df75ab 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewStateChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewStateChangedSubscriber.java @@ -20,7 +20,7 @@ import com.google.common.eventbus.Subscribe; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent; @@ -64,7 +64,7 @@ public synchronized void renew(final StorageNodeChangedEvent event) { if (!metaData.containsDatabase(event.getQualifiedDatabase().getDatabaseName())) { return; } - for (StaticDataSourceRule each : metaData.getDatabase(event.getQualifiedDatabase().getDatabaseName()).getRuleMetaData().getRuleIdentifiers(StaticDataSourceRule.class)) { + for (StaticDataSourceRuleAttribute each : metaData.getDatabase(event.getQualifiedDatabase().getDatabaseName()).getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) { each.updateStatus(new StorageNodeDataSourceChangedEvent(event.getQualifiedDatabase(), event.getDataSource())); } DataSourceStateManager.getInstance().updateState( diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java index bcb8b80469c08..4f1a2b9de8c19 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriber.java @@ -20,7 +20,7 @@ import com.google.common.eventbus.Subscribe; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager; import org.apache.shardingsphere.mode.event.storage.StorageNodeDataSourceChangedEvent; @@ -62,7 +62,7 @@ public synchronized void renew(final StorageNodeChangedEvent event) { if (!metaData.containsDatabase(event.getQualifiedDatabase().getDatabaseName())) { return; } - for (StaticDataSourceRule each : metaData.getDatabase(event.getQualifiedDatabase().getDatabaseName()).getRuleMetaData().getRuleIdentifiers(StaticDataSourceRule.class)) { + for (StaticDataSourceRuleAttribute each : metaData.getDatabase(event.getQualifiedDatabase().getDatabaseName()).getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)) { each.updateStatus(new StorageNodeDataSourceChangedEvent(event.getQualifiedDatabase(), event.getDataSource())); } DataSourceStateManager.getInstance().updateState( diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java index 94f5c97fad2d2..2c58feddbc7ed 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/StateChangedSubscriberTest.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.rule.identifier.type.datasource.StaticDataSourceRule; +import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; @@ -114,11 +114,11 @@ private Map createDatabases() { @Test void assertRenewForDisableStateChanged() { - StaticDataSourceRule staticDataSourceRule = mock(StaticDataSourceRule.class); - when(database.getRuleMetaData().getRuleIdentifiers(StaticDataSourceRule.class)).thenReturn(Collections.singleton(staticDataSourceRule)); + StaticDataSourceRuleAttribute ruleAttribute = mock(StaticDataSourceRuleAttribute.class); + when(database.getRuleMetaData().getAttributes(StaticDataSourceRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); StorageNodeChangedEvent event = new StorageNodeChangedEvent(new QualifiedDatabase("db.readwrite_ds.ds_0"), new StorageNodeDataSource(StorageNodeRole.MEMBER, DataSourceState.DISABLED)); subscriber.renew(event); - verify(staticDataSourceRule).updateStatus(argThat( + verify(ruleAttribute).updateStatus(argThat( (ArgumentMatcher) argumentEvent -> Objects.equals(event.getQualifiedDatabase(), argumentEvent.getQualifiedDatabase()) && Objects.equals(event.getDataSource(), argumentEvent.getDataSource()))); } diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneModeContextManager.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneModeContextManager.java index 4af6fde320567..8cfd7db0faec5 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneModeContextManager.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/NewStandaloneModeContextManager.java @@ -29,9 +29,9 @@ import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaMetaDataPOJO; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaPOJO; import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.metadata.MetaDataHeldRule; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.metadata.MetaDataHeldRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.spi.type.ordered.cache.OrderedServicesCache; import org.apache.shardingsphere.metadata.persist.service.config.global.GlobalPersistService; import org.apache.shardingsphere.metadata.persist.service.database.DatabaseMetaDataBasedPersistService; @@ -109,7 +109,7 @@ private void putSchemaMetaData(final ShardingSphereDatabase database, final Stri private void addDataNode(final ShardingSphereDatabase database, final String logicDataSourceName, final String schemaName, final Collection tobeAddedTableNames) { tobeAddedTableNames.forEach(each -> { if (!Strings.isNullOrEmpty(logicDataSourceName) && TableRefreshUtils.isSingleTable(each, database)) { - database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, each)); + database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, each)); } }); } @@ -123,7 +123,7 @@ private void addDataNode(final ShardingSphereDatabase database, final String log private void addTablesToDataNode(final ShardingSphereDatabase database, final String schemaName, final String logicDataSourceName, final Map toBeAddedTables) { for (Entry entry : toBeAddedTables.entrySet()) { if (!Strings.isNullOrEmpty(logicDataSourceName) && TableRefreshUtils.isSingleTable(entry.getKey(), database)) { - database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, entry.getKey())); + database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, entry.getKey())); } database.getSchema(schemaName).putTable(entry.getKey(), entry.getValue()); } @@ -133,7 +133,7 @@ private void addViewsToDataNode(final ShardingSphereDatabase database, final Str final Map toBeAddedTables, final Map toBeAddedViews) { for (Entry entry : toBeAddedViews.entrySet()) { if (!Strings.isNullOrEmpty(logicDataSourceName) && TableRefreshUtils.isSingleTable(entry.getKey(), database)) { - database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(each -> each.put(logicDataSourceName, schemaName, entry.getKey())); + database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(each -> each.put(logicDataSourceName, schemaName, entry.getKey())); } database.getSchema(schemaName).putTable(entry.getKey(), toBeAddedTables.get(entry.getKey().toLowerCase())); database.getSchema(schemaName).putView(entry.getKey(), entry.getValue()); @@ -143,12 +143,11 @@ private void addViewsToDataNode(final ShardingSphereDatabase database, final Str private void removeSchemaMetaData(final ShardingSphereDatabase database, final String schemaName) { ShardingSphereSchema schema = new ShardingSphereSchema(database.getSchema(schemaName).getTables(), database.getSchema(schemaName).getViews()); database.dropSchema(schemaName); - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, Collections.singletonList(schemaName), schema.getAllTableNames()); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), Collections.singletonList(schemaName), schema.getAllTableNames()); } - private void removeDataNode(final Collection rules, final Collection schemaNames, final Collection tobeRemovedTables) { - tobeRemovedTables.forEach(each -> rules.forEach(rule -> rule.remove(schemaNames, each))); + private void removeDataNode(final Collection ruleAttributes, final Collection schemaNames, final Collection tobeRemovedTables) { + tobeRemovedTables.forEach(each -> ruleAttributes.forEach(rule -> rule.remove(schemaNames, each))); } private void removeDataNode(final ShardingSphereDatabase database, final String schemaName, final Collection tobeRemovedTables, final Collection tobeRemovedViews) { @@ -156,19 +155,17 @@ private void removeDataNode(final ShardingSphereDatabase database, final String removeViewsToDataNode(database, schemaName, tobeRemovedTables, tobeRemovedViews); } - private void removeDataNode(final Collection rules, final String schemaName, final Collection tobeRemovedTables) { - tobeRemovedTables.forEach(each -> rules.forEach(rule -> rule.remove(schemaName, each))); + private void removeDataNode(final Collection ruleAttributes, final String schemaName, final Collection tobeRemovedTables) { + tobeRemovedTables.forEach(each -> ruleAttributes.forEach(rule -> rule.remove(schemaName, each))); } private void removeTablesToDataNode(final ShardingSphereDatabase database, final String schemaName, final Collection toBeDroppedTables) { - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, schemaName, toBeDroppedTables); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), schemaName, toBeDroppedTables); toBeDroppedTables.forEach(each -> database.getSchema(schemaName).removeTable(each)); } private void removeViewsToDataNode(final ShardingSphereDatabase database, final String schemaName, final Collection toBeDroppedTables, final Collection toBeDroppedViews) { - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, schemaName, toBeDroppedViews); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), schemaName, toBeDroppedViews); ShardingSphereSchema schema = database.getSchema(schemaName); toBeDroppedTables.forEach(schema::removeTable); toBeDroppedViews.forEach(schema::removeView); @@ -185,8 +182,7 @@ public void dropSchema(final String databaseName, final Collection schem Optional.of(schema).ifPresent(optional -> tobeRemovedTables.addAll(optional.getAllTableNames())); tobeRemovedSchemas.add(each.toLowerCase()); } - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, tobeRemovedSchemas, tobeRemovedTables); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), tobeRemovedSchemas, tobeRemovedTables); refreshMetaDataHeldRule(database); } @@ -208,7 +204,7 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat } private void refreshMetaDataHeldRule(final ShardingSphereDatabase database) { - contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRuleIdentifiers(MetaDataHeldRule.class).forEach(each -> each.alterDatabase(database)); + contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getAttributes(MetaDataHeldRuleAttribute.class).forEach(each -> each.alterDatabase(database)); } @Override @@ -216,7 +212,7 @@ public void registerStorageUnits(final String databaseName, final Map each.addResource(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName))); contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getSchemas() .forEach((schemaName, schema) -> contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService() @@ -231,7 +227,7 @@ public void alterStorageUnits(final String databaseName, final Map each.addResource(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName))); contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().append( contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), toBeUpdatedProps); diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java index 73c9fe95ee1ea..95a84b9aa265e 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneModeContextManager.java @@ -28,9 +28,9 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaMetaDataPOJO; import org.apache.shardingsphere.infra.metadata.database.schema.pojo.AlterSchemaPOJO; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; -import org.apache.shardingsphere.infra.rule.identifier.type.metadata.MetaDataHeldRule; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.metadata.MetaDataHeldRuleAttribute; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.spi.type.ordered.cache.OrderedServicesCache; import org.apache.shardingsphere.metadata.persist.service.database.DatabaseMetaDataBasedPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -101,7 +101,7 @@ private void putSchemaMetaData(final ShardingSphereDatabase database, final Stri private void addDataNode(final ShardingSphereDatabase database, final String logicDataSourceName, final String schemaName, final Collection tobeAddedTableNames) { tobeAddedTableNames.forEach(each -> { if (!Strings.isNullOrEmpty(logicDataSourceName) && TableRefreshUtils.isSingleTable(each, database)) { - database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, each)); + database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, each)); } }); } @@ -115,7 +115,7 @@ private void addDataNode(final ShardingSphereDatabase database, final String log private void addTablesToDataNode(final ShardingSphereDatabase database, final String schemaName, final String logicDataSourceName, final Map toBeAddedTables) { for (Entry entry : toBeAddedTables.entrySet()) { if (!Strings.isNullOrEmpty(logicDataSourceName) && TableRefreshUtils.isSingleTable(entry.getKey(), database)) { - database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, entry.getKey())); + database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, entry.getKey())); } database.getSchema(schemaName).putTable(entry.getKey(), entry.getValue()); } @@ -125,7 +125,7 @@ private void addViewsToDataNode(final ShardingSphereDatabase database, final Str final Map toBeAddedTables, final Map toBeAddedViews) { for (Entry entry : toBeAddedViews.entrySet()) { if (!Strings.isNullOrEmpty(logicDataSourceName) && TableRefreshUtils.isSingleTable(entry.getKey(), database)) { - database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, entry.getKey())); + database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class).forEach(rule -> rule.put(logicDataSourceName, schemaName, entry.getKey())); } database.getSchema(schemaName).putTable(entry.getKey(), toBeAddedTables.get(entry.getKey().toLowerCase())); database.getSchema(schemaName).putView(entry.getKey(), entry.getValue()); @@ -135,12 +135,11 @@ private void addViewsToDataNode(final ShardingSphereDatabase database, final Str private void removeSchemaMetaData(final ShardingSphereDatabase database, final String schemaName) { ShardingSphereSchema schema = new ShardingSphereSchema(database.getSchema(schemaName).getTables(), database.getSchema(schemaName).getViews()); database.dropSchema(schemaName); - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, Collections.singleton(schemaName), schema.getAllTableNames()); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), Collections.singleton(schemaName), schema.getAllTableNames()); } - private void removeDataNode(final Collection rules, final Collection schemaNames, final Collection tobeRemovedTables) { - tobeRemovedTables.forEach(each -> rules.forEach(rule -> rule.remove(schemaNames, each))); + private void removeDataNode(final Collection ruleAttributes, final Collection schemaNames, final Collection tobeRemovedTables) { + tobeRemovedTables.forEach(each -> ruleAttributes.forEach(rule -> rule.remove(schemaNames, each))); } private void removeDataNode(final ShardingSphereDatabase database, final String schemaName, final Collection tobeRemovedTables, final Collection tobeRemovedViews) { @@ -148,19 +147,17 @@ private void removeDataNode(final ShardingSphereDatabase database, final String removeViewsToDataNode(database, schemaName, tobeRemovedTables, tobeRemovedViews); } - private void removeDataNode(final Collection rules, final String schemaName, final Collection tobeRemovedTables) { - tobeRemovedTables.forEach(each -> rules.forEach(rule -> rule.remove(schemaName, each))); + private void removeDataNode(final Collection ruleAttributes, final String schemaName, final Collection tobeRemovedTables) { + tobeRemovedTables.forEach(each -> ruleAttributes.forEach(rule -> rule.remove(schemaName, each))); } private void removeTablesToDataNode(final ShardingSphereDatabase database, final String schemaName, final Collection toBeDroppedTables) { - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, schemaName, toBeDroppedTables); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), schemaName, toBeDroppedTables); toBeDroppedTables.forEach(each -> database.getSchema(schemaName).removeTable(each)); } private void removeViewsToDataNode(final ShardingSphereDatabase database, final String schemaName, final Collection toBeDroppedTables, final Collection toBeDroppedViews) { - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, schemaName, toBeDroppedViews); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), schemaName, toBeDroppedViews); ShardingSphereSchema schema = database.getSchema(schemaName); toBeDroppedTables.forEach(schema::removeTable); toBeDroppedViews.forEach(schema::removeView); @@ -177,8 +174,7 @@ public void dropSchema(final String databaseName, final Collection schem Optional.of(schema).ifPresent(optional -> tobeRemovedTables.addAll(optional.getAllTableNames())); tobeRemovedSchemas.add(each.toLowerCase()); } - Collection mutableDataNodeRules = database.getRuleMetaData().getRuleIdentifiers(MutableDataNodeRule.class); - removeDataNode(mutableDataNodeRules, tobeRemovedSchemas, tobeRemovedTables); + removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), tobeRemovedSchemas, tobeRemovedTables); refreshMetaDataHeldRule(database); } @@ -200,7 +196,7 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat } private void refreshMetaDataHeldRule(final ShardingSphereDatabase database) { - contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRuleIdentifiers(MetaDataHeldRule.class).forEach(each -> each.alterDatabase(database)); + contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getAttributes(MetaDataHeldRuleAttribute.class).forEach(each -> each.alterDatabase(database)); } @Override @@ -208,7 +204,7 @@ public void registerStorageUnits(final String databaseName, final Map each.addResource(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName))); contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getSchemas() .forEach((schemaName, schema) -> contextManager.getMetaDataContexts().getPersistService().getDatabaseMetaDataService() @@ -223,7 +219,7 @@ public void alterStorageUnits(final String databaseName, final Map each.addResource(contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName))); contextManager.getMetaDataContexts().getPersistService().getDataSourceUnitService().append( contextManager.getMetaDataContexts().getMetaData().getDatabase(databaseName).getName(), toBeUpdatedProps); diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java index f45ec7c73a183..6a338863e1b5f 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java @@ -47,7 +47,7 @@ import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.util.SystemSchemaUtils; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -342,8 +342,8 @@ private void mergeUpdateCount(final SQLStatementContext sqlStatementContext, fin } private boolean isNeedAccumulate(final SQLStatementContext sqlStatementContext) { - Collection dataNodeRules = database.getRuleMetaData().getRuleIdentifiers(DataNodeRule.class); - return !dataNodeRules.isEmpty() && dataNodeRules.iterator().next().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()); + Collection ruleAttributes = database.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class); + return !ruleAttributes.isEmpty() && ruleAttributes.iterator().next().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames()); } /** diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java index 62e9aa8feda66..83cea2047df9a 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java @@ -39,7 +39,7 @@ import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; import org.apache.shardingsphere.infra.executor.sql.prepare.raw.RawExecutionPrepareEngine; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.raw.RawExecutionRule; +import org.apache.shardingsphere.infra.rule.attribute.raw.RawExecutionRuleAttribute; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; @@ -178,7 +178,7 @@ public List execute(final ExecutionContext executionContext) thro private boolean hasRawExecutionRule(final Collection rules) { for (ShardingSphereRule each : rules) { - if (each instanceof RawExecutionRule) { + if (each.getAttributes().findAttribute(RawExecutionRuleAttribute.class).isPresent()) { return true; } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java index b7b78ed4bbd88..0028e662a6e68 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSource.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.database.core.GlobalDataSourceRegistry; import org.apache.shardingsphere.infra.exception.OverallConnectionNotEnoughException; import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.proxy.backend.connector.BackendDataSource; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine; @@ -108,7 +108,7 @@ private List createConnections(final String databaseName, final Stri private Connection createConnection(final String databaseName, final String dataSourceName, final DataSource dataSource, final TransactionType transactionType) throws SQLException { TransactionRule transactionRule = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(TransactionRule.class); - ShardingSphereTransactionManager transactionManager = ((ShardingSphereTransactionManagerEngine) transactionRule.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource()) + ShardingSphereTransactionManager transactionManager = ((ShardingSphereTransactionManagerEngine) transactionRule.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource()) .getTransactionManager(transactionType); Connection result = isInTransaction(transactionManager) ? transactionManager.getConnection(databaseName, dataSourceName) : dataSource.getConnection(); if (dataSourceName.contains(".")) { diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java index 9718a3a265580..86238dd4ce4de 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManager.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext; import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager; @@ -56,7 +56,7 @@ public BackendTransactionManager(final ProxyDatabaseConnectionManager databaseCo transactionType = connection.getConnectionSession().getTransactionStatus().getTransactionType(); localTransactionManager = new LocalTransactionManager(databaseConnectionManager); TransactionRule transactionRule = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(TransactionRule.class); - ShardingSphereTransactionManagerEngine engine = (ShardingSphereTransactionManagerEngine) transactionRule.getRuleIdentifiers().getIdentifier(ResourceHeldRule.class).getResource(); + ShardingSphereTransactionManagerEngine engine = (ShardingSphereTransactionManagerEngine) transactionRule.getAttributes().getAttribute(ResourceHeldRuleAttribute.class).getResource(); shardingSphereTransactionManager = null == engine ? null : engine.getTransactionManager(transactionType); transactionHooks = ShardingSphereServiceLoader.getServiceInstances(TransactionHook.class); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java index e17340df2fa32..19e6bfafbd190 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/datasource/JDBCBackendDataSourceTest.java @@ -26,8 +26,8 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.mode.manager.ContextManager; @@ -106,9 +106,9 @@ private Map createDatabases() { @SuppressWarnings("unchecked") private RuleMetaData mockGlobalRuleMetaData() { TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); return new RuleMetaData(Collections.singleton(transactionRule)); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java index bfd9f515fef51..73da06c9c801a 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/jdbc/transaction/BackendTransactionManagerTest.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.proxy.backend.connector.jdbc.transaction; import lombok.SneakyThrows; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.connection.transaction.TransactionConnectionContext; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; @@ -198,9 +198,9 @@ private RuleMetaData mockGlobalRuleMetaData() { ShardingSphereTransactionManagerEngine transactionManagerEngine = mock(ShardingSphereTransactionManagerEngine.class); when(transactionManagerEngine.getTransactionManager(TransactionType.XA)).thenReturn(shardingSphereTransactionManager); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(transactionManagerEngine); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(transactionManagerEngine); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); return new RuleMetaData(Collections.singleton(transactionRule)); } } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/fixture/FixtureRule.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/fixture/FixtureRule.java index 0f51f5c5a728c..05cfa879277cb 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/fixture/FixtureRule.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/fixture/FixtureRule.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; public final class FixtureRule implements ShardingSphereRule { @@ -29,7 +29,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java index 7300ecb5c8adc..8edf97ec0a0e0 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerFactoryTest.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.proxy.backend.handler.transaction; import lombok.SneakyThrows; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; @@ -99,9 +99,9 @@ void assertTransactionBackendHandlerReturnedWhenTCLStatementInstanceOfRollbackSt private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(transactionRule))); return result; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java index 45f471d164503..51928977dfec5 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/transaction/TransactionBackendHandlerTest.java @@ -18,8 +18,8 @@ package org.apache.shardingsphere.proxy.backend.handler.transaction; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; @@ -63,9 +63,9 @@ void assertExecute() throws SQLException { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(transactionRule))); return result; } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java index f2fc98f34e8b8..9919f43b55f86 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/session/ConnectionSessionTest.java @@ -17,8 +17,8 @@ package org.apache.shardingsphere.proxy.backend.session; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; -import org.apache.shardingsphere.infra.rule.identifier.type.resoure.ResourceHeldRule; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; +import org.apache.shardingsphere.infra.rule.attribute.resoure.ResourceHeldRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.infra.database.mysql.type.MySQLDatabaseType; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; @@ -97,9 +97,9 @@ void assertSwitchSchemaWhileBegin() { private ContextManager mockContextManager() { ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS); TransactionRule transactionRule = mock(TransactionRule.class); - ResourceHeldRule resourceHeldRule = mock(ResourceHeldRule.class); - when(resourceHeldRule.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); - when(transactionRule.getRuleIdentifiers()).thenReturn(new RuleIdentifiers(resourceHeldRule)); + ResourceHeldRuleAttribute resourceHeldRuleAttribute = mock(ResourceHeldRuleAttribute.class); + when(resourceHeldRuleAttribute.getResource()).thenReturn(mock(ShardingSphereTransactionManagerEngine.class)); + when(transactionRule.getAttributes()).thenReturn(new RuleAttributes(resourceHeldRuleAttribute)); when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(transactionRule))); return result; } diff --git a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilder.java b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilder.java index 2ff9714096d59..d9fd6883b9bdf 100644 --- a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilder.java +++ b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilder.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeaderBuilder; @@ -60,7 +60,7 @@ public QueryHeader build(final QueryResultMetaData queryResultMetaData, } private String getLogicTableName(final ShardingSphereDatabase database, final String actualTableName) { - for (DataNodeRule each : database.getRuleMetaData().getRuleIdentifiers(DataNodeRule.class)) { + for (DataNodeRuleAttribute each : database.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) { Optional logicTable = each.findLogicTableByActualTable(actualTableName); if (logicTable.isPresent()) { return logicTable.get(); diff --git a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilderTest.java b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilderTest.java index 5a83c7f4a6278..dc900fde73a53 100644 --- a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilderTest.java +++ b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/response/header/query/MySQLQueryHeaderBuilderTest.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader; import org.junit.jupiter.api.Test; @@ -78,9 +78,9 @@ void assertBuildWithNullDatabase() throws SQLException { void assertBuildWithNullSchema() throws SQLException { ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(database.getSchemas()).thenReturn(Collections.emptyMap()); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.findLogicTableByActualTable("t_order")).thenReturn(Optional.of("t_order")); - when(database.getRuleMetaData().getRuleIdentifiers(DataNodeRule.class)).thenReturn(Collections.singleton(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.findLogicTableByActualTable("t_order")).thenReturn(Optional.of("t_order")); + when(database.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); QueryResultMetaData queryResultMetaData = createQueryResultMetaData(); QueryHeader actual = new MySQLQueryHeaderBuilder().build(queryResultMetaData, database, queryResultMetaData.getColumnName(1), queryResultMetaData.getColumnLabel(1), 1); assertFalse(actual.isPrimaryKey()); @@ -103,9 +103,9 @@ private ShardingSphereDatabase createDatabase() { when(schema.getTable("t_logic_order")).thenReturn( new ShardingSphereTable("t_logic_order", Collections.singleton(column), Collections.singleton(new ShardingSphereIndex("order_id")), Collections.emptyList())); when(result.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema); - DataNodeRule dataNodeRule = mock(DataNodeRule.class); - when(dataNodeRule.findLogicTableByActualTable("t_order")).thenReturn(Optional.of("t_logic_order")); - when(result.getRuleMetaData().getRuleIdentifiers(DataNodeRule.class)).thenReturn(Collections.singleton(dataNodeRule)); + DataNodeRuleAttribute ruleAttribute = mock(DataNodeRuleAttribute.class); + when(ruleAttribute.findLogicTableByActualTable("t_order")).thenReturn(Optional.of("t_logic_order")); + when(result.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)).thenReturn(Collections.singleton(ruleAttribute)); when(result.getName()).thenReturn(DefaultDatabase.LOGIC_NAME); return result; } diff --git a/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/rule/MockedRule.java b/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/rule/MockedRule.java index 79bce0fa71c21..53fb93b99d221 100644 --- a/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/rule/MockedRule.java +++ b/test/fixture/infra/src/main/java/org/apache/shardingsphere/test/fixture/infra/rule/MockedRule.java @@ -19,7 +19,7 @@ import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.RuleIdentifiers; +import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes; import static org.mockito.Mockito.mock; @@ -34,7 +34,7 @@ public RuleConfiguration getConfiguration() { } @Override - public RuleIdentifiers getRuleIdentifiers() { - return new RuleIdentifiers(); + public RuleAttributes getAttributes() { + return new RuleAttributes(); } } diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java index de318eee3eb09..74f543492c72a 100644 --- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java +++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; @@ -103,11 +103,11 @@ protected Map mockSchemas(final String schemaName) protected void mockRules(final Collection rules, final String schemaName, final SQLStatement sqlStatement) { Optional singleRule = rules.stream().filter(each -> each instanceof SingleRule).map(each -> (SingleRule) each).findFirst(); if (singleRule.isPresent() && !(sqlStatement instanceof CreateTableStatement)) { - singleRule.get().getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put("encrypt_ds", schemaName, "t_account"); - singleRule.get().getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put("encrypt_ds", schemaName, "t_account_bak"); - singleRule.get().getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put("encrypt_ds", schemaName, "t_account_detail"); - singleRule.get().getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put("encrypt_ds", schemaName, "t_order"); - singleRule.get().getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put("encrypt_ds", schemaName, "t_user"); + singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("encrypt_ds", schemaName, "t_account"); + singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("encrypt_ds", schemaName, "t_account_bak"); + singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("encrypt_ds", schemaName, "t_account_detail"); + singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("encrypt_ds", schemaName, "t_order"); + singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("encrypt_ds", schemaName, "t_user"); } } diff --git a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java index 8799defbfece3..7a66e736c3416 100644 --- a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java +++ b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import org.apache.shardingsphere.infra.rule.identifier.type.datanode.MutableDataNodeRule; +import org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; @@ -58,8 +58,8 @@ protected YamlRootConfiguration createRootConfiguration(final SQLRewriteEngineTe protected void mockRules(final Collection rules, final String schemaName, final SQLStatement sqlStatement) { Optional singleRule = rules.stream().filter(each -> each instanceof SingleRule).map(each -> (SingleRule) each).findFirst(); if (singleRule.isPresent() && !(sqlStatement instanceof CreateTableStatement)) { - singleRule.get().getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put("db", schemaName, "t_single"); - singleRule.get().getRuleIdentifiers().getIdentifier(MutableDataNodeRule.class).put("db", schemaName, "t_single_extend"); + singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("db", schemaName, "t_single"); + singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("db", schemaName, "t_single_extend"); } }