This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 64c4a1af8a8 Add DataSourceMapperRule (#30372)
64c4a1af8a8 is described below
commit 64c4a1af8a856de2e1125b336a0cd36db52814ca
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Mar 2 16:52:15 2024 +0800
Add DataSourceMapperRule (#30372)
* Add DataSourceMapperRule
* Add DataSourceMapperRule
* Add DataSourceMapperRule
* Add DataSourceMapperRule
* Add DataSourceMapperRule
* Update code Conduct
* Update code Conduct
---
docs/community/content/involved/conduct/code.cn.md | 45 +++++++++++---------
docs/community/content/involved/conduct/code.en.md | 43 ++++++++++---------
.../broadcast/rule/BroadcastRule.java | 10 ++---
...ReadwriteSplittingRuleConfigurationChecker.java | 4 +-
.../ReadwriteSplittingDataNodeBuilder.java | 2 +-
.../ReadwriteSplittingDataSourceMapperRule.java | 28 +++++++------
.../rule/ReadwriteSplittingRule.java | 9 +++-
...writeSplittingRuleConfigurationCheckerTest.java | 8 ++--
.../rule/ReadwriteSplittingRuleTest.java | 2 +-
.../ReadwriteSplittingRuleStatementChecker.java | 6 +--
.../ReadwriteSplittingCountResultRowBuilder.java | 2 +-
.../update/DropReadwriteSplittingRuleExecutor.java | 6 +--
.../CreateReadwriteSplittingRuleExecutorTest.java | 17 ++++----
.../DropReadwriteSplittingRuleExecutorTest.java | 8 ++--
.../shadow/datanode/ShadowDataNodeBuilder.java | 2 +-
.../shadow/rule/ShadowDataSourceMapperRule.java | 49 ++++++++++++++++++++++
.../shardingsphere/shadow/rule/ShadowRule.java | 21 +++-------
.../checker/ShadowRuleStatementChecker.java | 24 +++--------
.../handler/query/ShadowCountResultRowBuilder.java | 2 +-
.../update/CreateShadowRuleExecutorTest.java | 11 ++---
.../checker/ShardingTableRuleStatementChecker.java | 6 +--
.../CreateShardingTableRuleExecutorTest.java | 11 +++--
.../infra/metadata/database/rule/RuleMetaData.java | 10 ++---
.../DataSourceMapperContainedRule.java} | 17 ++++----
.../DataSourceMapperRule.java} | 8 ++--
.../infra/datanode/DataNodesTest.java | 6 +--
.../infra/fixture/DataNodeBuilderFixture.java | 2 +-
.../shardingsphere/infra/fixture/FixtureRule.java | 13 +++---
.../database/ShardingSphereDatabaseTest.java | 4 +-
.../schema/util/SchemaMetaDataUtilsTest.java | 8 ++--
.../rdl/resource/RegisterStorageUnitExecutor.java | 5 ++-
.../resource/RegisterStorageUnitExecutorTest.java | 8 ++--
.../UnregisterStorageUnitExecutorTest.java | 10 ++---
.../single/util/SingleTableLoadUtils.java | 10 ++---
.../handler/update/LoadSingleTableExecutor.java | 6 +--
.../update/LoadSingleTableExecutorTest.java | 4 +-
.../ShadowRuleConfigurationImportChecker.java | 6 +--
.../ShardingRuleConfigurationImportChecker.java | 6 +--
.../ImportDatabaseConfigurationExecutorTest.java | 9 ++--
39 files changed, 246 insertions(+), 202 deletions(-)
diff --git a/docs/community/content/involved/conduct/code.cn.md
b/docs/community/content/involved/conduct/code.cn.md
index b85b7e13cd9..9889e49347a 100644
--- a/docs/community/content/involved/conduct/code.cn.md
+++ b/docs/community/content/involved/conduct/code.cn.md
@@ -20,28 +20,34 @@ chapter = true
- 确保遵守编码规范。
- 确保构建流程中的各个步骤都成功完成,包括:Apache 协议文件头检查、Checkstyle 检查、编译、单元测试等。构建流程启动命令:`./mvnw
clean install -B -T1C -Pcheck`。
+ - 通过 Spotless 统一代码风格,执行 `./mvnw spotless:apply -Pcheck` 格式化代码。
- 确保覆盖率不低于 master 分支。
- 应尽量将设计精细化拆分;做到小幅度修改,多次数提交,但应保证提交的完整性。
- - 通过 Spotless 统一代码风格,执行 `./mvnw spotless:apply -Pcheck` 格式化代码。
- 如果您使用 IDEA,可导入推荐的 `src/resources/code-style-idea.xml`。
## 编码规范
- 使用 linux 换行符。
- 不应有无意义的空行。请提炼私有方法,代替方法体过长或代码段逻辑闭环而采用的空行间隔。
- - 类、方法和变量的命名要做到顾名思义,类、方法名避免使用缩写,部分变量名可以使用缩写。
- - 变量名 `arguments` 缩写为 `args`;
- - 变量名 `parameters` 缩写为 `params`;
- - 变量名 `environment` 缩写为 `env`;
- - 变量名 `properties` 缩写为 `props`;
- - 变量名 `configuration` 缩写为 `config`。
- - 三位以内字符的专有名词缩写使用大写,超过三位字符的缩写采用驼峰形式。
- - 三位以内字符的类和方法名称缩写的示例:SQL92Lexer、XMLTransfer、MySQLAdminExecutorCreator;
- - 三位以上字符的类和方法名称缩写的示例:JdbcUrlAppender、YamlAgentConfigurationSwapper;
- - 变量应使用小驼峰形式:mysqlAuthenticationMethod、sqlStatement、mysqlConfig。
- - 除了直接返回方法入参,返回变量使用 `result` 命名;循环中使用 `each` 命名循环变量;map 中使用 `entry` 代替 `each`。
- - 捕获的异常名称命名为 `ex` ;捕获异常且不做任何事情,异常名称命名为 `ignored`。
- - 配置文件使用 `Spinal Case` 命名(一种使用 `-` 分割单词的特殊 `Snake Case`)。
+ - 命名规范:
+ - 命名要做到顾名思义。
+ - 类、方法名避免使用缩写,部分变量名可以使用缩写。
+ - 变量名 `arguments` 缩写为 `args`;
+ - 变量名 `parameters` 缩写为 `params`;
+ - 变量名 `environment` 缩写为 `env`;
+ - 变量名 `properties` 缩写为 `props`;
+ - 变量名 `configuration` 缩写为 `config`。
+ - 三位以内字符的专有名词缩写使用大写,超过三位字符的缩写采用驼峰形式。
+ - 三位以内字符的类和方法名称缩写的示例:SQL92Lexer、XMLTransfer、MySQLAdminExecutorCreator;
+ - 三位以上字符的类和方法名称缩写的示例:JdbcUrlAppender、YamlAgentConfigurationSwapper;
+ - 变量应使用小驼峰形式:mysqlAuthenticationMethod、sqlStatement、mysqlConfig。
+ - 符合下列条件的局部变量,应参照下列规则命名:
+ - 除了直接返回方法入参,返回变量使用 `result` 命名;
+ - 循环中使用 `each` 命名循环变量;
+ - map 中使用 `entry` 代替 `each`;
+ - 捕获的异常名称命名为 `ex` ;捕获异常且不做任何事情,异常名称命名为 `ignored`。
+ - 工具类名称命名为 `xxUtils`。
+ - 配置文件使用 `Spinal Case` 命名(一种使用 `-` 分割单词的特殊 `Snake Case`)。
- 需要注释解释的代码尽量提成小方法,用方法名称解释。
- `equals` 和 `==` 条件表达式中,常量在左,变量在右;大于小于等条件表达式中,变量在左,常量在右。
- 除了构造器入参与全局变量名称相同的赋值语句外,避免使用 `this` 修饰符。
@@ -55,23 +61,22 @@ chapter = true
- 优先使用 lombok 代替构造器,getter, setter 方法和 log 变量。
- 优先考虑使用 `LinkedList`,只有在需要通过下标获取集合中元素值时再使用 `ArrayList`。
- `ArrayList`,`HashMap` 等可能产生扩容的集合类型必须指定集合初始大小,避免扩容。
- - 日志与注释一律使用英文。
- - 注释只能包含 javadoc,todo 和 fixme。
- - 公开的类和方法必须有 javadoc,对用户的 API 和 SPI 的 javadoc 需要写的清晰全面,其他类和方法以及覆盖自父类的方法无需
javadoc。
- 优先使用三目运算符代替 if else 的返回和赋值语句。
- 禁止嵌套使用三目运算符。
- 条件表达式中,优先使用正向语义,以便于理解代码逻辑。例如:`if (null == param) {} else {}`。
- 使用具体的 `@SuppressWarnings("xxx")` 代替 `@SuppressWarnings("all")`。
- - 热点方法内应避免使用 Java Stream,除非该场景下使用 Stream 的性能优于普通循环。
- - 工具类名称命名为 `xxUtils`。
- 合理使用 `@HighFrequencyInvocation` 注解,用于聚焦关键方法性能的优化。
- 使用 `@HighFrequencyInvocation` 注解的时机:
- 请求频繁调用的链路,标注其中高频调用的类、方法或构造器,标注范围精确匹配;
- `canBeCached` 属性为 `true` 时,表示该目标为可复用的缓存资源,例如:数据库连接。
- 标注 `@HighFrequencyInvocation` 的代码段须严格保证代码性能,以下为标注代码段内的禁止项:
- 禁止调用 Java Stream API;
- - 禁止通过 `+` 连接字符串;
+ - 禁止通过 `+` 拼接字符串;
- 禁止调用 LinkedList 的 `get(int index)` 方法。
+ - 注释 & 日志规范:
+ - 日志与注释一律使用英文。
+ - 注释只能包含 javadoc,todo 和 fixme。
+ - 公开的类和方法必须有 javadoc,对用户的 API 和 SPI 的 javadoc 需要写的清晰全面,其他类和方法以及覆盖自父类的方法无需
javadoc。
## 单元测试规范
diff --git a/docs/community/content/involved/conduct/code.en.md
b/docs/community/content/involved/conduct/code.en.md
index 92e165e1b21..c61601ecd37 100644
--- a/docs/community/content/involved/conduct/code.en.md
+++ b/docs/community/content/involved/conduct/code.en.md
@@ -17,28 +17,34 @@ The following code of conduct is based on full compliance
with [ASF CODE OF COND
- Conform to `Contributor Covenant Code of Conduct` below.
- Make sure Maven build process success. Run `./mvnw clean install -B -T1C
-Pcheck` command in shell to start Maven build process.
+ - Through the uniform code style of spotless, execute the `./mvnw
spotless:apply -Pcheck` formatted code.
- Make sure the test coverage rate is not lower than the master branch.
- Careful consideration for each `pull request`; Small and frequent `pull
request` with complete unit function is welcomed.
- - Through the uniform code style of spotless, execute the `./mvnw
spotless:apply -Pcheck` formatted code.
- If using IDEA, you can import the recommended
`src/resources/code-style-idea.xml`.
## Contributor Covenant Code of Conduct
- Use linux line separators.
- No meaningless blank lines. Please extract private methods to instead of
blank lines if too long method body or different logic code fragments.
- - Use meaningful class, method and variable names, class and method name
avoid to use abbreviation. Some variables could use abbreviation.
- - Variable `arguments` could abbreviate to `args`;
- - Variable `parameters` could abbreviate to `params`;
- - Variable `environment` could abbreviate to `env`;
- - Variable `properties` could abbreviate to `props`;
- - Variable `configuration` could abbreviate to `config`.
- - Abbreviation composed less than 3 characters should be uppercase, more than
3 characters must use camel case naming rule.
- - Example for abbreviation composed less than 3 characters: SQL92Lexer,
XMLTransfer, MySQLAdminExecutorCreator;
- - Example for abbreviation composed more than 3 characters:
JdbcUrlAppender, YamlAgentConfigurationSwapper;
- - A variable composed of abbreviation should use lower camel case:
mysqlAuthenticationMethod, sqlStatement, mysqlConfig.
- - Except return an input parameter as result, returning variable should be
named with `result`; Variables in the loop structure are named with `each`;
Replace `each` with `entry` in map.
- - Exceptions when catch are named with `ex`; Exceptions when catch but do
nothing are named with `ignored`.
- - Name property files with `Spinal Case`(a variant of `Snake Case` which uses
hyphens `-` to separate words).
+ - Naming covenant:
+ - Use meaningful names.
+ - Avoid to use abbreviation. Some variables could use abbreviation.
+ - Variable `arguments` could abbreviate to `args`;
+ - Variable `parameters` could abbreviate to `params`;
+ - Variable `environment` could abbreviate to `env`;
+ - Variable `properties` could abbreviate to `props`;
+ - Variable `configuration` could abbreviate to `config`.
+ - Abbreviation composed less than 3 characters should be uppercase, more
than 3 characters must use camel case naming rule.
+ - Example for abbreviation composed less than 3 characters: SQL92Lexer,
XMLTransfer, MySQLAdminExecutorCreator;
+ - Example for abbreviation composed more than 3 characters:
JdbcUrlAppender, YamlAgentConfigurationSwapper;
+ - A variable composed of abbreviation should use lower camel case:
mysqlAuthenticationMethod, sqlStatement, mysqlConfig.
+ - Local variables that meet the following conditions shall be named
according to the following rules:
+ - Except return an input parameter as result, returning variable should
be named with `result`;
+ - Variables in the loop structure are named with `each`;
+ - Replace `each` with `entry` in map;
+ - Exceptions when catch are named with `ex`; Exceptions when catch but do
nothing are named with `ignored`.
+ - Utility class should be named in the form of `xxUtils`.
+ - Name property files with `Spinal Case`(a variant of `Snake Case` which
uses hyphens `-` to separate words).
- Split codes that need to add notes with it into small methods, which are
explained with method names.
- Have constants on the left and variable on the right in `=` and `equals`
conditional expressions; Have variable on the left and constants on the right
in `greater than` and `less than` conditional expressions.
- Beside using same names as input parameters and global fields in assign
statement, avoid using `this` modifier.
@@ -52,15 +58,10 @@ The following code of conduct is based on full compliance
with [ASF CODE OF COND
- Replace constructors, getters, setter methods and log variable with lombok
in priority.
- Use `LinkedList` in priority. Use `ArrayList` for use index to get element
only.
- Use capacity based `Collection` such as `ArrayList`, `HashMap` must
indicate initial capacity to avoid recalculate capacity.
- - Use English in all the logs and javadoc.
- - Include Javadoc, todo and fixme only in the comments.
- - Only `public` classes and methods need javadoc, the Javadoc for the user
API and SPI needs to be written clearly and comprehensively, other methods,
classes and override methods do not need javadoc.
- Replace if else return and assign statement with ternary operator in
priority.
- Nested using ternary operator is forbidden.
- Use forward semantics in priority for better understanding code logic in
conditional expressions. For example: `if (null == param) {} else {}`.
- Use concentrate `@SuppressWarnings("xxx")` instead of
`@SuppressWarnings("all")`.
- - Avoid using Java Stream in hot methods, unless the performance of using
Stream is better than using loop in that situation.
- - Utility class should be named in the form of `xxUtils`.
- Reasonably use the @HighFrequencyInvocation annotation to focus on
optimizing the performance of critical methods.
- Occasions for using the @HighFrequencyInvocation annotation:
- In frequently invoked requests, add annotation to classes, methods, or
constructors with high frequency calls; precise matching within the scope of
annotation;
@@ -69,6 +70,10 @@ The following code of conduct is based on full compliance
with [ASF CODE OF COND
- It is prohibited to call Java Stream API;
- It is prohibited to concat String using "+";
- It is prohibited to call LinkedList's get(int index) method.
+ - Comments & Logs covenant:
+ - Use English in all the logs and javadoc.
+ - Include Javadoc, todo and fixme only in the comments.
+ - Only `public` classes and methods need javadoc, the Javadoc for the user
API and SPI needs to be written clearly and comprehensively, other methods,
classes and override methods do not need javadoc.
## Contributor Covenant Unit Test of Conduct
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 cfca4a67c10..984a34543dc 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
@@ -21,7 +21,7 @@ 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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperContainedRule;
@@ -65,16 +65,16 @@ public final class BroadcastRule implements DatabaseRule,
DataNodeContainedRule,
private Collection<String> getAggregatedDataSourceNames(final Map<String,
DataSource> dataSources, final Collection<ShardingSphereRule> builtRules) {
Collection<String> result = new LinkedList<>(dataSources.keySet());
for (ShardingSphereRule each : builtRules) {
- if (each instanceof DataSourceContainedRule) {
- result = getAggregatedDataSourceNames(result,
(DataSourceContainedRule) each);
+ if (each instanceof DataSourceMapperContainedRule) {
+ result = getAggregatedDataSourceNames(result,
(DataSourceMapperContainedRule) each);
}
}
return result;
}
- private Collection<String> getAggregatedDataSourceNames(final
Collection<String> dataSourceNames, final DataSourceContainedRule builtRule) {
+ private Collection<String> getAggregatedDataSourceNames(final
Collection<String> dataSourceNames, final DataSourceMapperContainedRule
builtRule) {
Collection<String> result = new LinkedList<>();
- for (Entry<String, Collection<String>> entry :
builtRule.getDataSourceMapper().entrySet()) {
+ for (Entry<String, Collection<String>> entry :
builtRule.getDataSourceMapperRule().getDataSourceMapper().entrySet()) {
for (String each : entry.getValue()) {
if (dataSourceNames.contains(each)) {
dataSourceNames.remove(each);
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 c94594d0280..07e000a5ad5 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.config.rule.checker.RuleConfigurationChec
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -89,7 +89,7 @@ public final class ReadwriteSplittingRuleConfigurationChecker
implements RuleCon
private boolean containsInOtherRules(final String datasourceName, final
Collection<ShardingSphereRule> rules) {
for (ShardingSphereRule each : rules) {
- if (each instanceof DataSourceContainedRule &&
((DataSourceContainedRule)
each).getDataSourceMapper().containsKey(datasourceName)) {
+ if (each instanceof DataSourceMapperContainedRule &&
((DataSourceMapperContainedRule)
each).getDataSourceMapperRule().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 de1330e52f2..fb22ce70f3a 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
@@ -35,7 +35,7 @@ public final class ReadwriteSplittingDataNodeBuilder
implements DataNodeBuilder<
public Collection<DataNode> build(final Collection<DataNode> dataNodes,
final ReadwriteSplittingRule rule) {
Collection<DataNode> result = new LinkedList<>();
for (DataNode each : dataNodes) {
- result.addAll(DataNodeUtils.buildDataNode(each,
rule.getDataSourceMapper()));
+ result.addAll(DataNodeUtils.buildDataNode(each,
rule.getDataSourceMapperRule().getDataSourceMapper()));
}
return result;
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRule.java
similarity index 56%
copy from
infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
copy to
features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRule.java
index 35a9971bd98..de208e89418 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingDataSourceMapperRule.java
@@ -15,27 +15,29 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.fixture;
+package org.apache.shardingsphere.readwritesplitting.rule;
-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.DataSourceContainedRule;
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule;
import java.util.Collection;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
-import static org.mockito.Mockito.mock;
-
-public final class FixtureRule implements DatabaseRule,
DataSourceContainedRule {
+/**
+ * Readwrite-splitting data source mapper rule.
+ */
+@RequiredArgsConstructor
+public final class ReadwriteSplittingDataSourceMapperRule implements
DataSourceMapperRule {
- @Override
- public RuleConfiguration getConfiguration() {
- return mock(RuleConfiguration.class);
- }
+ private final Collection<ReadwriteSplittingDataSourceRule> dataSourceRules;
@Override
public Map<String, Collection<String>> getDataSourceMapper() {
- return Collections.emptyMap();
+ Map<String, Collection<String>> result = new HashMap<>();
+ for (ReadwriteSplittingDataSourceRule each : dataSourceRules) {
+ result.put(each.getName(),
each.getReadwriteSplittingGroup().getAllDataSources());
+ }
+ return result;
}
}
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 7981e800294..bf4d48536bd 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
@@ -27,9 +27,10 @@ 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.scope.DatabaseRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.StaticDataSourceContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.StorageConnectorReusableRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule;
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;
@@ -54,7 +55,7 @@ import java.util.stream.Collectors;
/**
* Readwrite-splitting rule.
*/
-public final class ReadwriteSplittingRule implements DatabaseRule,
DataSourceContainedRule, StaticDataSourceContainedRule, ExportableRule,
StorageConnectorReusableRule {
+public final class ReadwriteSplittingRule implements DatabaseRule,
DataSourceMapperContainedRule, StaticDataSourceContainedRule, ExportableRule,
StorageConnectorReusableRule {
private final String databaseName;
@@ -68,12 +69,16 @@ public final class ReadwriteSplittingRule implements
DatabaseRule, DataSourceCon
private final InstanceContext instanceContext;
+ @Getter
+ private final DataSourceMapperRule dataSourceMapperRule;
+
public ReadwriteSplittingRule(final String databaseName, final
ReadwriteSplittingRuleConfiguration ruleConfig, final InstanceContext
instanceContext) {
this.databaseName = databaseName;
configuration = ruleConfig;
this.instanceContext = instanceContext;
loadBalancers = createLoadBalancers(ruleConfig);
dataSourceRules = createDataSourceRules(ruleConfig);
+ dataSourceMapperRule = new
ReadwriteSplittingDataSourceMapperRule(dataSourceRules.values());
}
private Map<String, LoadBalanceAlgorithm> createLoadBalancers(final
ReadwriteSplittingRuleConfiguration ruleConfig) {
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 283ba0b378a..6ecf3bf93df 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
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.readwritesplitting.checker;
import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -102,9 +102,9 @@ class ReadwriteSplittingRuleConfigurationCheckerTest {
void assertCheckWhenConfigOtherRulesDatasource() {
ReadwriteSplittingRuleConfiguration config =
createContainsOtherRulesDatasourceConfig();
RuleConfigurationChecker checker =
OrderedSPILoader.getServicesByClass(RuleConfigurationChecker.class,
Collections.singleton(config.getClass())).get(config.getClass());
- DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class, RETURNS_DEEP_STUBS);
-
when(dataSourceContainedRule.getDataSourceMapper().containsKey("otherDatasourceName")).thenReturn(true);
- checker.check("test", config, mockDataSources(),
Collections.singleton(dataSourceContainedRule));
+ DataSourceMapperContainedRule dataSourceMapperContainedRule =
mock(DataSourceMapperContainedRule.class, RETURNS_DEEP_STUBS);
+
when(dataSourceMapperContainedRule.getDataSourceMapperRule().getDataSourceMapper().containsKey("otherDatasourceName")).thenReturn(true);
+ checker.check("test", config, mockDataSources(),
Collections.singleton(dataSourceMapperContainedRule));
}
private ReadwriteSplittingRuleConfiguration
createContainsOtherRulesDatasourceConfig() {
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 33a3e5716e3..86d1fe50954 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
@@ -98,7 +98,7 @@ class ReadwriteSplittingRuleTest {
@Test
void assertGetDataSourceMapper() {
ReadwriteSplittingRule readwriteSplittingRule =
createReadwriteSplittingRule();
- Map<String, Collection<String>> actual =
readwriteSplittingRule.getDataSourceMapper();
+ Map<String, Collection<String>> actual =
readwriteSplittingRule.getDataSourceMapperRule().getDataSourceMapper();
Map<String, Collection<String>> expected =
Collections.singletonMap("readwrite", Arrays.asList("write_ds", "read_ds_0",
"read_ds_1"));
assertThat(actual, is(expected));
}
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 fbf37d51b3e..c7c0262c7c2 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.algorithm.load.balancer.core.LoadBalanceA
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -145,8 +145,8 @@ public final class ReadwriteSplittingRuleStatementChecker {
}
private static Collection<String> getLogicDataSources(final
ShardingSphereDatabase database) {
- return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream()
- .map(each ->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
+ return
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class).stream()
+ .map(each ->
each.getDataSourceMapperRule().getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
}
private static void checkDuplicatedDataSourceNames(final String
databaseName, final Collection<ReadwriteSplittingRuleSegment> segments,
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 bd1b1946d42..474b38167db 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
@@ -31,7 +31,7 @@ public final class ReadwriteSplittingCountResultRowBuilder
implements CountResul
@Override
public Collection<LocalDataQueryResultRow> generateRows(final
ReadwriteSplittingRule rule, final String databaseName) {
- return Collections.singleton(new
LocalDataQueryResultRow("readwrite_splitting", databaseName,
rule.getDataSourceMapper().size()));
+ return Collections.singleton(new
LocalDataQueryResultRow("readwrite_splitting", databaseName,
rule.getDataSourceMapperRule().getDataSourceMapper().size()));
}
@Override
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 bef6caca96f..2bc4db16915 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,7 +27,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeContainedRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.StaticDataSourceContainedRule;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -77,12 +77,12 @@ public final class DropReadwriteSplittingRuleExecutor
implements DatabaseRuleDro
private Collection<String> getInUsedResources() {
Collection<String> result = new HashSet<>();
- for (DataSourceContainedRule each :
database.getRuleMetaData().findRules(DataSourceContainedRule.class)) {
+ for (DataSourceMapperContainedRule each :
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)) {
if (each instanceof ReadwriteSplittingRule) {
continue;
}
Collection<String> actualDataSources = new HashSet<>();
-
each.getDataSourceMapper().values().forEach(actualDataSources::addAll);
+
each.getDataSourceMapperRule().getDataSourceMapper().values().forEach(actualDataSources::addAll);
result.addAll(actualDataSources);
}
for (DataNodeContainedRule each :
database.getRuleMetaData().findRules(DataNodeContainedRule.class)) {
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 e72171af6f6..3712d61ca47 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.handler.exception.storageunit.MissingRe
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
@@ -50,6 +50,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -68,7 +69,7 @@ class CreateReadwriteSplittingRuleExecutorTest {
@BeforeEach
void setUp() {
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.emptyList());
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.emptyList());
executor.setDatabase(database);
}
@@ -98,9 +99,9 @@ class CreateReadwriteSplittingRuleExecutorTest {
@Test
void assertCheckSQLStatementWithDuplicateLogicResource() {
- DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
-
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds",
Collections.singleton("ds_0")));
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
+ DataSourceMapperContainedRule dataSourceMapperContainedRule =
mock(DataSourceMapperContainedRule.class, RETURNS_DEEP_STUBS);
+
when(dataSourceMapperContainedRule.getDataSourceMapperRule().getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds",
Collections.singleton("ds_0")));
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.singleton(dataSourceMapperContainedRule));
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 +149,9 @@ class CreateReadwriteSplittingRuleExecutorTest {
@Test
void assertUpdateSuccess() {
- DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
-
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("ms_group",
Collections.singleton("ds_0")));
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
+ DataSourceMapperContainedRule dataSourceMapperContainedRule =
mock(DataSourceMapperContainedRule.class, RETURNS_DEEP_STUBS);
+
when(dataSourceMapperContainedRule.getDataSourceMapperRule().getDataSourceMapper()).thenReturn(Collections.singletonMap("ms_group",
Collections.singleton("ds_0")));
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.singleton(dataSourceMapperContainedRule));
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 ae1f283f9a9..e67292d2d26 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
@@ -24,7 +24,7 @@ import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfigurat
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeContainedRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.distsql.statement.DropReadwriteSplittingRuleStatement;
@@ -80,9 +80,9 @@ class DropReadwriteSplittingRuleExecutorTest {
@Test
void assertCheckSQLStatementWithInUsed() throws
RuleDefinitionViolationException {
- DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
-
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("foo_ds",
Collections.singleton("readwrite_ds")));
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
+ DataSourceMapperContainedRule dataSourceMapperContainedRule =
mock(DataSourceMapperContainedRule.class, RETURNS_DEEP_STUBS);
+
when(dataSourceMapperContainedRule.getDataSourceMapperRule().getDataSourceMapper()).thenReturn(Collections.singletonMap("foo_ds",
Collections.singleton("readwrite_ds")));
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.singleton(dataSourceMapperContainedRule));
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class, RETURNS_DEEP_STUBS);
when(dataNodeContainedRule.getDataNodeRule().getAllDataNodes()).thenReturn(Collections.singletonMap("foo_ds",
Collections.singleton(new DataNode("readwrite_ds.tbl"))));
when(database.getRuleMetaData().findRules(DataNodeContainedRule.class)).thenReturn(Collections.singleton(dataNodeContainedRule));
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 fb1fbec8ae8..8a740eaf254 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
@@ -35,7 +35,7 @@ public final class ShadowDataNodeBuilder implements
DataNodeBuilder<ShadowRule>
public Collection<DataNode> build(final Collection<DataNode> dataNodes,
final ShadowRule rule) {
Collection<DataNode> result = new LinkedList<>();
for (DataNode each : dataNodes) {
- result.addAll(DataNodeUtils.buildDataNode(each,
rule.getDataSourceMapper()));
+ result.addAll(DataNodeUtils.buildDataNode(each,
rule.getDataSourceMapperRule().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/ShadowDataSourceMapperRule.java
new file mode 100644
index 00000000000..dc5b13de7df
--- /dev/null
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowDataSourceMapperRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.shadow.rule;
+
+import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+/**
+ * Shadow data source mapper rule.
+ */
+@RequiredArgsConstructor
+public final class ShadowDataSourceMapperRule implements DataSourceMapperRule {
+
+ private final Map<String, ShadowDataSourceRule> shadowDataSourceMappings;
+
+ @Override
+ public Map<String, Collection<String>> getDataSourceMapper() {
+ Map<String, Collection<String>> result = new LinkedHashMap<>();
+ shadowDataSourceMappings.forEach((key, value) -> result.put(key,
createShadowDataSources(value)));
+ return result;
+ }
+
+ private Collection<String> createShadowDataSources(final
ShadowDataSourceRule shadowDataSourceRule) {
+ Collection<String> result = new LinkedList<>();
+ result.add(shadowDataSourceRule.getProductionDataSource());
+ result.add(shadowDataSourceRule.getShadowDataSource());
+ return result;
+ }
+}
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 83a8b662f81..594158e5aba 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
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.shadow.rule;
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
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;
@@ -41,7 +41,7 @@ import java.util.Optional;
* Databases shadow rule.
*/
@Getter
-public final class ShadowRule implements DatabaseRule, DataSourceContainedRule
{
+public final class ShadowRule implements DatabaseRule,
DataSourceMapperContainedRule {
private final ShadowRuleConfiguration configuration;
@@ -55,6 +55,8 @@ public final class ShadowRule implements DatabaseRule,
DataSourceContainedRule {
private final ShadowAlgorithm defaultShadowAlgorithm;
+ private final ShadowDataSourceMapperRule dataSourceMapperRule;
+
public ShadowRule(final ShadowRuleConfiguration ruleConfig) {
configuration = ruleConfig;
initShadowDataSourceMappings(ruleConfig.getDataSources());
@@ -64,6 +66,7 @@ public final class ShadowRule implements DatabaseRule,
DataSourceContainedRule {
hintShadowAlgorithmNames.add(ruleConfig.getDefaultShadowAlgorithmName());
}
initShadowTableRules(ruleConfig.getTables());
+ dataSourceMapperRule = new
ShadowDataSourceMapperRule(shadowDataSourceMappings);
}
private void initShadowDataSourceMappings(final
Collection<ShadowDataSourceConfiguration> dataSources) {
@@ -232,18 +235,4 @@ public final class ShadowRule implements DatabaseRule,
DataSourceContainedRule {
ShadowDataSourceRule shadowDataSourceRule =
shadowDataSourceMappings.get(actualDataSourceName);
return null == shadowDataSourceRule ? Optional.empty() :
Optional.of(shadowDataSourceRule.getProductionDataSource());
}
-
- @Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new LinkedHashMap<>();
- shadowDataSourceMappings.forEach((key, value) -> result.put(key,
createShadowDataSources(value)));
- return result;
- }
-
- private Collection<String> createShadowDataSources(final
ShadowDataSourceRule shadowDataSourceRule) {
- Collection<String> result = new LinkedList<>();
- result.add(shadowDataSourceRule.getProductionDataSource());
- result.add(shadowDataSourceRule.getShadowDataSource());
- return result;
- }
}
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 d1a87edcff0..44609bdd480 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
@@ -19,14 +19,12 @@ package
org.apache.shardingsphere.shadow.distsql.handler.checker;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.DistSQLException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.InvalidRuleConfigurationException;
-import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+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.DataSourceMapperContainedRule;
import java.util.Collection;
import java.util.Collections;
@@ -39,17 +37,7 @@ import java.util.stream.Collectors;
* Shadow rule statement checker.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class ShadowRuleStatementChecker {
-
- /**
- * Check if the rule configuration exists.
- *
- * @param databaseName database name
- * @param ruleConfig rule configuration
- */
- public static void checkRuleConfigurationExists(final String databaseName,
final ShadowRuleConfiguration ruleConfig) {
- ShardingSpherePreconditions.checkNotNull(ruleConfig, () -> new
MissingRequiredRuleException("shadow", databaseName));
- }
+public final class ShadowRuleStatementChecker {
/**
* Check if storage units exist in meta data.
@@ -126,7 +114,7 @@ public class ShadowRuleStatementChecker {
}
private static Collection<String> getLogicDataSources(final
ShardingSphereDatabase database) {
- return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream()
- .map(each ->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
+ return
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class).stream()
+ .map(each ->
each.getDataSourceMapperRule().getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
}
}
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 4f18ee7beb0..a8d87c02405 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
@@ -31,7 +31,7 @@ public final class ShadowCountResultRowBuilder implements
CountResultRowBuilder<
@Override
public Collection<LocalDataQueryResultRow> generateRows(final ShadowRule
rule, final String databaseName) {
- return Collections.singleton(new LocalDataQueryResultRow("shadow",
databaseName, rule.getDataSourceMapper().size()));
+ return Collections.singleton(new LocalDataQueryResultRow("shadow",
databaseName, rule.getDataSourceMapperRule().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 cba765be737..621523787e6 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.handler.exception.storageunit.MissingRe
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
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;
@@ -48,6 +48,7 @@ import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -71,7 +72,7 @@ class CreateShadowRuleExecutorTest {
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
when(database.getName()).thenReturn("shadow_db");
when(currentConfig.getDataSources()).thenReturn(Collections.singleton(new
ShadowDataSourceConfiguration("initRuleName", "initDs0", "initDs0Shadow")));
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.emptyList());
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.emptyList());
executor.setDatabase(database);
}
@@ -93,9 +94,9 @@ class CreateShadowRuleExecutorTest {
@Test
void assertExecuteWithDuplicateLogicResource() {
- DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
-
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds",
Collections.singleton("ds_0")));
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
+ DataSourceMapperContainedRule dataSourceMapperContainedRule =
mock(DataSourceMapperContainedRule.class, RETURNS_DEEP_STUBS);
+
when(dataSourceMapperContainedRule.getDataSourceMapperRule().getDataSourceMapper()).thenReturn(Collections.singletonMap("duplicate_ds",
Collections.singleton("ds_0")));
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.singleton(dataSourceMapperContainedRule));
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/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 2317968a7bd..d84b91c579a 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
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode;
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.infra.algorithm.keygen.core.KeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -335,8 +335,8 @@ public final class ShardingTableRuleStatementChecker {
}
private static Collection<String> getLogicDataSources(final
ShardingSphereDatabase database) {
- return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream()
- .map(each ->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
+ return
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class).stream()
+ .map(each ->
each.getDataSourceMapperRule().getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
}
private static void checkTables(final String databaseName, final
Collection<AbstractTableRuleSegment> rules, final ShardingRuleConfiguration
currentRuleConfig, final boolean isCreate,
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 aed275c7f9c..76bab6b8e9a 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,7 +26,8 @@ import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.c
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule;
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;
@@ -294,7 +295,7 @@ class CreateShardingTableRuleExecutorTest {
return (DistSQLStatement) visitor.visit(parseASTNode.getRootNode());
}
- private static class MockDataSourceContainedRule implements
DataSourceContainedRule {
+ private static class MockDataSourceContainedRule implements
DataSourceMapperContainedRule {
@Override
public RuleConfiguration getConfiguration() {
@@ -302,8 +303,10 @@ class CreateShardingTableRuleExecutorTest {
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- return Collections.singletonMap("logic_ds", null);
+ public DataSourceMapperRule getDataSourceMapperRule() {
+ DataSourceMapperRule result = mock(DataSourceMapperRule.class);
+
when(result.getDataSourceMapper()).thenReturn(Collections.singletonMap("logic_ds",
null));
+ return result;
}
}
}
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 0742ffe6baa..70710c21290 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
@@ -23,7 +23,7 @@ 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.datanode.DataNodeContainedRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import java.util.Collection;
import java.util.LinkedHashMap;
@@ -106,8 +106,8 @@ public final class RuleMetaData {
public Map<String, Collection<Class<? extends ShardingSphereRule>>>
getInUsedStorageUnitNameAndRulesMap() {
Map<String, Collection<Class<? extends ShardingSphereRule>>> result =
new LinkedHashMap<>();
for (ShardingSphereRule each : rules) {
- if (each instanceof DataSourceContainedRule) {
- mergeInUsedStorageUnitNameAndRules(result,
getInUsedStorageUnitNameAndRulesMap(each,
getInUsedStorageUnitNames((DataSourceContainedRule) each)));
+ if (each instanceof DataSourceMapperContainedRule) {
+ mergeInUsedStorageUnitNameAndRules(result,
getInUsedStorageUnitNameAndRulesMap(each,
getInUsedStorageUnitNames((DataSourceMapperContainedRule) each)));
} else if (each instanceof DataNodeContainedRule) {
mergeInUsedStorageUnitNameAndRules(result,
getInUsedStorageUnitNameAndRulesMap(each,
getInUsedStorageUnitNames((DataNodeContainedRule) each)));
}
@@ -126,8 +126,8 @@ public final class RuleMetaData {
return result;
}
- private Collection<String> getInUsedStorageUnitNames(final
DataSourceContainedRule rule) {
- return
rule.getDataSourceMapper().values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
+ private Collection<String> getInUsedStorageUnitNames(final
DataSourceMapperContainedRule rule) {
+ return
rule.getDataSourceMapperRule().getDataSourceMapper().values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
}
private Collection<String> getInUsedStorageUnitNames(final
DataNodeContainedRule rule) {
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperContainedRule.java
similarity index 71%
copy from
infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
copy to
infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperContainedRule.java
index fb49a376a52..b2316a174e1 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperContainedRule.java
@@ -15,22 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.rule.identifier.type;
+package org.apache.shardingsphere.infra.rule.identifier.type.datasource;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import java.util.Collection;
-import java.util.Map;
-
/**
- * ShardingSphere rule which contains data source.
+ * ShardingSphere rule which contains data source mapper.
*/
-public interface DataSourceContainedRule extends ShardingSphereRule {
+public interface DataSourceMapperContainedRule extends ShardingSphereRule {
/**
- * Get data source mapper.
- *
- * @return data source mapper
+ * Get data source mapper rule.
+ *
+ * @return data source mapper rule
*/
- Map<String, Collection<String>> getDataSourceMapper();
+ DataSourceMapperRule getDataSourceMapperRule();
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperRule.java
similarity index 80%
rename from
infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
rename to
infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperRule.java
index fb49a376a52..0f51a83d11b 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/datasource/DataSourceMapperRule.java
@@ -15,17 +15,15 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.rule.identifier.type;
-
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+package org.apache.shardingsphere.infra.rule.identifier.type.datasource;
import java.util.Collection;
import java.util.Map;
/**
- * ShardingSphere rule which contains data source.
+ * Data source mapper rule.
*/
-public interface DataSourceContainedRule extends ShardingSphereRule {
+public interface DataSourceMapperRule {
/**
* Get data source mapper.
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 7f784f6ceb7..0ca49a1900c 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,7 +19,7 @@ package org.apache.shardingsphere.infra.datanode;
import org.apache.shardingsphere.infra.fixture.FixtureRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeRule;
import org.junit.jupiter.api.Test;
@@ -136,8 +136,8 @@ class DataNodesTest {
}
private ShardingSphereRule mockDataSourceContainedRule() {
- DataSourceContainedRule result = mock(FixtureRule.class);
-
when(result.getDataSourceMapper()).thenReturn(READ_WRITE_SPLITTING_DATASOURCE_MAP);
+ DataSourceMapperContainedRule result = mock(FixtureRule.class,
RETURNS_DEEP_STUBS);
+
when(result.getDataSourceMapperRule().getDataSourceMapper()).thenReturn(READ_WRITE_SPLITTING_DATASOURCE_MAP);
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 e74abb3daf4..fab15e1999e 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
@@ -30,7 +30,7 @@ public final class DataNodeBuilderFixture implements
DataNodeBuilder<FixtureRule
public Collection<DataNode> build(final Collection<DataNode> dataNodes,
final FixtureRule rule) {
Collection<DataNode> result = new LinkedList<>();
for (DataNode each : dataNodes) {
- result.addAll(DataNodeUtils.buildDataNode(each,
rule.getDataSourceMapper()));
+ result.addAll(DataNodeUtils.buildDataNode(each,
rule.getDataSourceMapperRule().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 35a9971bd98..81dcaba77f7 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
@@ -19,15 +19,12 @@ 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.DataSourceContainedRule;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule;
import static org.mockito.Mockito.mock;
-public final class FixtureRule implements DatabaseRule,
DataSourceContainedRule {
+public final class FixtureRule implements DatabaseRule,
DataSourceMapperContainedRule {
@Override
public RuleConfiguration getConfiguration() {
@@ -35,7 +32,7 @@ public final class FixtureRule implements DatabaseRule,
DataSourceContainedRule
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- return Collections.emptyMap();
+ public DataSourceMapperRule getDataSourceMapperRule() {
+ return mock(DataSourceMapperRule.class);
}
}
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 324e0dfecd7..77a2c1ca1fb 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
@@ -25,7 +25,7 @@ import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaDa
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.MutableDataNodeRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -151,7 +151,7 @@ class ShardingSphereDatabaseTest {
ResourceMetaData resourceMetaData = new
ResourceMetaData(Collections.singletonMap("ds", new MockedDataSource()));
Collection<ShardingSphereRule> rules = new LinkedList<>();
rules.add(mock(MutableDataNodeRule.class, RETURNS_DEEP_STUBS));
- rules.add(mock(DataSourceContainedRule.class, RETURNS_DEEP_STUBS));
+ rules.add(mock(DataSourceMapperContainedRule.class,
RETURNS_DEEP_STUBS));
rules.add(mock(TableMapperContainedRule.class, RETURNS_DEEP_STUBS));
RuleMetaData ruleMetaData = new RuleMetaData(rules);
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db",
mock(DatabaseType.class), resourceMetaData, ruleMetaData,
Collections.emptyMap());
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 dfb22e76ee4..1994724c5cb 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,7 +23,7 @@ import
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilderMaterial;
import
org.apache.shardingsphere.infra.rule.identifier.type.datanode.DataNodeContainedRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.Test;
@@ -50,7 +50,7 @@ class SchemaMetaDataUtilsTest {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class, RETURNS_DEEP_STUBS);
when(dataNodeContainedRule.getDataNodeRule().getDataNodesByTableName("t_order")).thenReturn(mockShardingDataNodes());
GenericSchemaBuilderMaterial material = new
GenericSchemaBuilderMaterial(mock(DatabaseType.class), mockStorageTypes(),
mockDataSourceMap(),
- Arrays.asList(dataNodeContainedRule,
mock(DataSourceContainedRule.class)), mock(ConfigurationProperties.class),
"sharding_db");
+ Arrays.asList(dataNodeContainedRule,
mock(DataSourceMapperContainedRule.class)),
mock(ConfigurationProperties.class), "sharding_db");
Collection<MetaDataLoaderMaterial> actual =
SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_order"),
material, true);
assertThat(actual.size(), is(2));
Iterator<MetaDataLoaderMaterial> iterator = actual.iterator();
@@ -67,7 +67,7 @@ class SchemaMetaDataUtilsTest {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class, RETURNS_DEEP_STUBS);
when(dataNodeContainedRule.getDataNodeRule().getDataNodesByTableName("t_order")).thenReturn(mockShardingDataNodes());
GenericSchemaBuilderMaterial material = new
GenericSchemaBuilderMaterial(mock(DatabaseType.class), mockStorageTypes(),
mockDataSourceMap(),
- Arrays.asList(dataNodeContainedRule,
mock(DataSourceContainedRule.class)), mock(ConfigurationProperties.class),
"sharding_db");
+ Arrays.asList(dataNodeContainedRule,
mock(DataSourceMapperContainedRule.class)),
mock(ConfigurationProperties.class), "sharding_db");
Collection<MetaDataLoaderMaterial> actual =
SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_order"),
material, false);
assertThat(actual.size(), is(1));
Iterator<MetaDataLoaderMaterial> iterator = actual.iterator();
@@ -81,7 +81,7 @@ class SchemaMetaDataUtilsTest {
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class, RETURNS_DEEP_STUBS);
when(dataNodeContainedRule.getDataNodeRule().getDataNodesByTableName("t_single")).thenReturn(mockSingleTableDataNodes());
GenericSchemaBuilderMaterial material = new
GenericSchemaBuilderMaterial(mock(DatabaseType.class), mockStorageTypes(),
mockDataSourceMap(),
- Arrays.asList(dataNodeContainedRule,
mock(DataSourceContainedRule.class)), mock(ConfigurationProperties.class),
"public");
+ Arrays.asList(dataNodeContainedRule,
mock(DataSourceMapperContainedRule.class)),
mock(ConfigurationProperties.class), "public");
Collection<MetaDataLoaderMaterial> actual =
SchemaMetaDataUtils.getMetaDataLoaderMaterials(Collections.singleton("t_single"),
material, false);
assertThat(actual.size(), is(1));
Iterator<MetaDataLoaderMaterial> iterator = actual.iterator();
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 dce2057db55..eba2354762b 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.datasource.pool.props.domain.DataSourcePo
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import java.sql.SQLException;
@@ -109,7 +109,8 @@ public final class RegisterStorageUnitExecutor implements
DistSQLUpdateExecutor<
}
private Collection<String> getLogicalDataSourceNames() {
- return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream().map(each
->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toList());
+ return
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class).stream()
+ .map(each ->
each.getDataSourceMapperRule().getDataSourceMapper().keySet()).flatMap(Collection::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 b8356d97f2f..a2ab2d5cd7f 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.segment.URLBasedDataSourceSegment;
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
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 @@ class RegisterStorageUnitExecutorTest {
void
assertExecuteUpdateWithDuplicateStorageUnitNamesWithDataSourceContainedRule() {
ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
when(contextManager.getMetaDataContexts()).thenReturn(mock(MetaDataContexts.class,
RETURNS_DEEP_STUBS));
- DataSourceContainedRule rule = mock(DataSourceContainedRule.class);
-
when(rule.getDataSourceMapper()).thenReturn(Collections.singletonMap("ds_0",
Collections.emptyList()));
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(rule));
+ DataSourceMapperContainedRule rule =
mock(DataSourceMapperContainedRule.class, RETURNS_DEEP_STUBS);
+
when(rule.getDataSourceMapperRule().getDataSourceMapper()).thenReturn(Collections.singletonMap("ds_0",
Collections.emptyList()));
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.singleton(rule));
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 151ad7fd2ca..dcfdb554e22 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,7 +29,7 @@ import
org.apache.shardingsphere.infra.metadata.database.resource.node.StorageNo
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
@@ -108,8 +108,8 @@ class UnregisterStorageUnitExecutorTest {
@Test
void assertExecuteUpdateWithStorageUnitInUsed() {
- ShardingSphereRule rule = mock(ShardingSphereRule.class,
withSettings().extraInterfaces(DataSourceContainedRule.class));
- when(((DataSourceContainedRule)
rule).getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton("foo_ds")));
+ ShardingSphereRule rule = mock(ShardingSphereRule.class,
withSettings().extraInterfaces(DataSourceMapperContainedRule.class).defaultAnswer(RETURNS_DEEP_STUBS));
+ when(((DataSourceMapperContainedRule)
rule).getDataSourceMapperRule().getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton("foo_ds")));
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)));
}
@@ -137,8 +137,8 @@ class UnregisterStorageUnitExecutorTest {
@Test
void assertExecuteUpdateWithStorageUnitInUsedWithIfExists() {
- ShardingSphereRule rule = mock(ShardingSphereRule.class,
withSettings().extraInterfaces(DataSourceContainedRule.class));
- when(((DataSourceContainedRule)
rule).getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton("foo_ds")));
+ ShardingSphereRule rule = mock(ShardingSphereRule.class,
withSettings().extraInterfaces(DataSourceMapperContainedRule.class).defaultAnswer(RETURNS_DEEP_STUBS));
+ when(((DataSourceMapperContainedRule)
rule).getDataSourceMapperRule().getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton("foo_ds")));
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/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 522f411fe6e..5c6886dddc9 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,7 +25,7 @@ import
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.table.TableMapperContainedRule;
import org.apache.shardingsphere.single.api.constant.SingleTableConstants;
@@ -55,16 +55,16 @@ public final class SingleTableLoadUtils {
public static Map<String, DataSource> getAggregatedDataSourceMap(final
Map<String, DataSource> dataSourceMap, final Collection<ShardingSphereRule>
builtRules) {
Map<String, DataSource> result = new LinkedHashMap<>(dataSourceMap);
for (ShardingSphereRule each : builtRules) {
- if (each instanceof DataSourceContainedRule) {
- result = getAggregatedDataSourceMap(result,
(DataSourceContainedRule) each);
+ if (each instanceof DataSourceMapperContainedRule) {
+ result = getAggregatedDataSourceMap(result,
(DataSourceMapperContainedRule) each);
}
}
return result;
}
- private static Map<String, DataSource> getAggregatedDataSourceMap(final
Map<String, DataSource> dataSourceMap, final DataSourceContainedRule builtRule)
{
+ private static Map<String, DataSource> getAggregatedDataSourceMap(final
Map<String, DataSource> dataSourceMap, final DataSourceMapperContainedRule
builtRule) {
Map<String, DataSource> result = new LinkedHashMap<>();
- for (Entry<String, Collection<String>> entry :
builtRule.getDataSourceMapper().entrySet()) {
+ for (Entry<String, Collection<String>> entry :
builtRule.getDataSourceMapperRule().getDataSourceMapper().entrySet()) {
for (String each : entry.getValue()) {
if (dataSourceMap.containsKey(each)) {
result.putIfAbsent(entry.getKey(),
dataSourceMap.remove(each));
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 be904dda8b1..c29d521d60b 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.exception.dialect.exception.syntax.table.
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.api.constant.SingleTableConstants;
import org.apache.shardingsphere.single.datanode.SingleTableDataNodeLoader;
@@ -146,8 +146,8 @@ public final class LoadSingleTableExecutor implements
DatabaseRuleCreateExecutor
}
private Collection<String> getLogicDataSources(final
ShardingSphereDatabase database) {
- return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream()
- .map(each ->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toSet());
+ return
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class).stream()
+ .map(each ->
each.getDataSourceMapperRule().getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toSet());
}
@Override
diff --git
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
index d47908d855c..208b1a10be4 100644
---
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
+++
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutorTest.java
@@ -22,7 +22,7 @@ import
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.distsql.segment.SingleTableSegment;
@@ -59,7 +59,7 @@ class LoadSingleTableExecutorTest {
@BeforeEach
void setUp() {
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.emptyList());
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.emptyList());
when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
when(database.getSchema("foo_db")).thenReturn(schema);
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
index d6ad738b93e..f2d5a4f58e5 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShadowRuleConfigurationImportChecker.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.check
import
org.apache.shardingsphere.distsql.handler.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRequiredStorageUnitsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
@@ -74,8 +74,8 @@ public final class ShadowRuleConfigurationImportChecker {
}
private Collection<String> getLogicDataSources(final
ShardingSphereDatabase database) {
- return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream()
- .map(each ->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
+ return
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class).stream()
+ .map(each ->
each.getDataSourceMapperRule().getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
}
private void checkTables(final ShadowRuleConfiguration currentRuleConfig,
final String databaseName) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
index b4040f1c8fc..49fa8fbfa12 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/checker/ShardingRuleConfigurationImportChecker.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode;
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import
org.apache.shardingsphere.infra.algorithm.keygen.core.KeyGenerateAlgorithm;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
@@ -100,8 +100,8 @@ public final class ShardingRuleConfigurationImportChecker {
}
private Collection<String> getLogicResources(final ShardingSphereDatabase
database) {
- return
database.getRuleMetaData().findRules(DataSourceContainedRule.class).stream()
- .map(each ->
each.getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
+ return
database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class).stream()
+ .map(each ->
each.getDataSourceMapperRule().getDataSourceMapper().keySet()).flatMap(Collection::stream).collect(Collectors.toCollection(LinkedHashSet::new));
}
private void checkShardingAlgorithms(final
Collection<AlgorithmConfiguration> algorithmConfigs) {
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
index 333facc9d01..648fa97c1d0 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutorTest.java
@@ -30,7 +30,8 @@ import
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.
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.DataSourceContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperContainedRule;
+import
org.apache.shardingsphere.infra.rule.identifier.type.datasource.DataSourceMapperRule;
import
org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -142,8 +143,10 @@ class ImportDatabaseConfigurationExecutorTest {
when(database.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class,
"FIXTURE"));
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
- DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
+ DataSourceMapperContainedRule dataSourceMapperContainedRule =
mock(DataSourceMapperContainedRule.class);
+ DataSourceMapperRule dataSourceMapperRule =
mock(DataSourceMapperRule.class);
+
when(dataSourceMapperContainedRule.getDataSourceMapperRule()).thenReturn(dataSourceMapperRule);
+
when(database.getRuleMetaData().findRules(DataSourceMapperContainedRule.class)).thenReturn(Collections.singleton(dataSourceMapperContainedRule));
when(result.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap(databaseName,
database));
when(result.getMetaDataContexts().getMetaData().getDatabase(databaseName)).thenReturn(database);
when(result.getMetaDataContexts().getMetaData().getProps()).thenReturn(new
ConfigurationProperties(createProperties()));