Rename YamlDataNode to RepositoryTuple (#31029)
* Code format for DataSourceState
* Code format for ClasspathResourceDirectoryReader
* Rename YamlDataNode to RepositoryTuple
* Rename YamlDataNode to RepositoryTuple
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapper.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapper.java
index 0c77405..42e5d80 100644
--- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapper.java
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapper.java
@@ -23,7 +23,7 @@
import org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration;
import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
import java.util.Collection;
@@ -40,11 +40,10 @@
private final RuleNodePath broadcastRuleNodePath = new BroadcastRuleNodePathProvider().getRuleNodePath();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final BroadcastRuleConfiguration data) {
- if (data.getTables().isEmpty()) {
- return Collections.emptyList();
- }
- return Collections.singleton(new YamlDataNode(BroadcastRuleNodePathProvider.TABLES, YamlEngine.marshal(swapToTablesYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final BroadcastRuleConfiguration data) {
+ return data.getTables().isEmpty()
+ ? Collections.emptyList()
+ : Collections.singleton(new RepositoryTuple(BroadcastRuleNodePathProvider.TABLES, YamlEngine.marshal(swapToTablesYamlConfiguration(data))));
}
private YamlBroadcastRuleConfiguration swapToTablesYamlConfiguration(final BroadcastRuleConfiguration data) {
@@ -54,12 +53,11 @@
}
@Override
- public Optional<BroadcastRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- List<YamlDataNode> validDataNodes = dataNodes.stream().filter(each -> broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
- for (YamlDataNode each : validDataNodes) {
+ public Optional<BroadcastRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ List<RepositoryTuple> validTuples = repositoryTuples.stream().filter(each -> broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ for (RepositoryTuple each : validTuples) {
if (broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())) {
- YamlBroadcastRuleConfiguration yamlBroadcastRuleConfig = YamlEngine.unmarshal(each.getValue(), YamlBroadcastRuleConfiguration.class);
- return Optional.of(new BroadcastRuleConfiguration(yamlBroadcastRuleConfig.getTables()));
+ return Optional.of(new BroadcastRuleConfiguration(YamlEngine.unmarshal(each.getValue(), YamlBroadcastRuleConfiguration.class).getTables()));
}
}
return Optional.empty();
diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapperTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapperTest.java
index f392728..220b61d 100644
--- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapperTest.java
+++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/YamlBroadcastDataNodeRuleConfigurationSwapperTest.java
@@ -18,18 +18,19 @@
package org.apache.shardingsphere.broadcast.yaml.swapper;
import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class YamlBroadcastDataNodeRuleConfigurationSwapperTest {
@@ -37,17 +38,14 @@
@Test
void assertSwapEmptyConfigToDataNodes() {
- BroadcastRuleConfiguration config = new BroadcastRuleConfiguration(Collections.emptyList());
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(0));
+ assertTrue(swapper.swapToRepositoryTuples(new BroadcastRuleConfiguration(Collections.emptyList())).isEmpty());
}
@Test
void assertSwapFullConfigToDataNodes() {
- BroadcastRuleConfiguration config = createMaximumBroadcastRule();
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(1));
- Iterator<YamlDataNode> iterator = result.iterator();
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(createMaximumBroadcastRule());
+ assertThat(actual.size(), is(1));
+ Iterator<RepositoryTuple> iterator = actual.iterator();
assertThat(iterator.next().getKey(), is("tables"));
}
@@ -57,19 +55,16 @@
@Test
void assertSwapToObjectEmpty() {
- Collection<YamlDataNode> config = new LinkedList<>();
- assertFalse(swapper.swapToObject(config).isPresent());
+ assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
}
@Test
void assertSwapToObject() {
- Collection<YamlDataNode> config = new LinkedList<>();
- config.add(new YamlDataNode("/metadata/foo_db/rules/broadcast/tables", "tables:\n"
- + "- foo_table\n"
- + "- foo_table2\n"));
- BroadcastRuleConfiguration result = swapper.swapToObject(config).get();
- assertThat(result.getTables().size(), is(2));
- Iterator<String> iterator = result.getTables().iterator();
+ Optional<BroadcastRuleConfiguration> actual = swapper.swapToObject(
+ Collections.singleton(new RepositoryTuple("/metadata/foo_db/rules/broadcast/tables", "tables:\n" + "- foo_table\n" + "- foo_table2\n")));
+ assertTrue(actual.isPresent());
+ assertThat(actual.get().getTables().size(), is(2));
+ Iterator<String> iterator = actual.get().getTables().iterator();
assertThat(iterator.next(), is("foo_table"));
assertThat(iterator.next(), is("foo_table2"));
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapper.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapper.java
index 9df25c0..e17592b 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapper.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapper.java
@@ -26,7 +26,7 @@
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
@@ -52,28 +52,28 @@
private final RuleNodePath encryptRuleNodePath = new EncryptRuleNodePathProvider().getRuleNodePath();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final EncryptRuleConfiguration data) {
- Collection<YamlDataNode> result = new LinkedList<>();
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final EncryptRuleConfiguration data) {
+ Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, AlgorithmConfiguration> entry : data.getEncryptors().entrySet()) {
- result.add(new YamlDataNode(encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getPath(entry.getKey()),
- YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(entry.getValue()))));
+ result.add(new RepositoryTuple(
+ encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getPath(entry.getKey()), YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(entry.getValue()))));
}
for (EncryptTableRuleConfiguration each : data.getTables()) {
- result.add(new YamlDataNode(encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getPath(each.getName()),
- YamlEngine.marshal(tableSwapper.swapToYamlConfiguration(each))));
+ result.add(new RepositoryTuple(
+ encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getPath(each.getName()), YamlEngine.marshal(tableSwapper.swapToYamlConfiguration(each))));
}
return result;
}
@Override
- public Optional<EncryptRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- List<YamlDataNode> validDataNodes = dataNodes.stream().filter(each -> encryptRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
- if (validDataNodes.isEmpty()) {
+ public Optional<EncryptRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ List<RepositoryTuple> validTuples = repositoryTuples.stream().filter(each -> encryptRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ if (validTuples.isEmpty()) {
return Optional.empty();
}
Collection<EncryptTableRuleConfiguration> tables = new LinkedList<>();
Map<String, AlgorithmConfiguration> encryptors = new LinkedHashMap<>();
- for (YamlDataNode each : validDataNodes) {
+ for (RepositoryTuple each : validTuples) {
encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getName(each.getKey())
.ifPresent(optional -> tables.add(tableSwapper.swapToObject(YamlEngine.unmarshal(each.getValue(), YamlEncryptTableRuleConfiguration.class))));
encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getName(each.getKey())
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapperTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapperTest.java
index 213815c..ee4fdc8 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapperTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/YamlEncryptDataNodeRuleConfigurationSwapperTest.java
@@ -22,18 +22,20 @@
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.junit.jupiter.api.Test;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class YamlEncryptDataNodeRuleConfigurationSwapperTest {
@@ -41,53 +43,48 @@
@Test
void assertSwapEmptyConfigToDataNodes() {
- EncryptRuleConfiguration config = new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap());
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(0));
+ assertTrue(swapper.swapToRepositoryTuples(new EncryptRuleConfiguration(Collections.emptyList(), Collections.emptyMap())).isEmpty());
}
@Test
void assertSwapFullConfigToDataNodes() {
- EncryptRuleConfiguration config = createMaximumEncryptRule();
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(2));
- Iterator<YamlDataNode> iterator = result.iterator();
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(createMaximumEncryptRule());
+ assertThat(actual.size(), is(2));
+ Iterator<RepositoryTuple> iterator = actual.iterator();
assertThat(iterator.next().getKey(), is("encryptors/FOO"));
assertThat(iterator.next().getKey(), is("tables/foo"));
}
private EncryptRuleConfiguration createMaximumEncryptRule() {
- Collection<EncryptTableRuleConfiguration> tables = new LinkedList<>();
- tables.add(new EncryptTableRuleConfiguration("foo", Collections.singleton(new EncryptColumnRuleConfiguration("foo_column", new EncryptColumnItemRuleConfiguration("FIXTURE", "FOO")))));
+ Collection<EncryptTableRuleConfiguration> tables = Collections.singleton(
+ new EncryptTableRuleConfiguration("foo", Collections.singleton(new EncryptColumnRuleConfiguration("foo_column", new EncryptColumnItemRuleConfiguration("FIXTURE", "FOO")))));
return new EncryptRuleConfiguration(tables, Collections.singletonMap("FOO", new AlgorithmConfiguration("FOO", new Properties())));
}
@Test
void assertSwapToObjectEmpty() {
- Collection<YamlDataNode> config = new LinkedList<>();
- assertFalse(swapper.swapToObject(config).isPresent());
+ assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
}
@Test
void assertSwapToObject() {
- Collection<YamlDataNode> config = new LinkedList<>();
- config.add(new YamlDataNode("/metadata/foo_db/rules/encrypt/tables/foo/versions/0", "columns:\n"
+ Collection<RepositoryTuple> repositoryTuples = Arrays.asList(new RepositoryTuple("/metadata/foo_db/rules/encrypt/tables/foo/versions/0", "columns:\n"
+ " foo_column:\n"
+ " cipher:\n"
+ " encryptorName: FOO\n"
+ " name: FIXTURE\n"
+ " name: foo_column\n"
- + "name: foo\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/encrypt/encryptors/FOO/versions/0", "type: FOO\n"));
- EncryptRuleConfiguration result = swapper.swapToObject(config).get();
- assertThat(result.getTables().size(), is(1));
- assertThat(result.getTables().iterator().next().getName(), is("foo"));
- assertThat(result.getTables().iterator().next().getColumns().size(), is(1));
- assertThat(result.getTables().iterator().next().getColumns().iterator().next().getName(), is("foo_column"));
- assertThat(result.getTables().iterator().next().getColumns().iterator().next().getCipher().getName(), is("FIXTURE"));
- assertThat(result.getTables().iterator().next().getColumns().iterator().next().getCipher().getEncryptorName(), is("FOO"));
- assertThat(result.getEncryptors().size(), is(1));
- assertThat(result.getEncryptors().get("FOO").getType(), is("FOO"));
- assertThat(result.getEncryptors().get("FOO").getProps().size(), is(0));
+ + "name: foo\n"), new RepositoryTuple("/metadata/foo_db/rules/encrypt/encryptors/FOO/versions/0", "type: FOO\n"));
+ Optional<EncryptRuleConfiguration> actual = swapper.swapToObject(repositoryTuples);
+ assertTrue(actual.isPresent());
+ assertThat(actual.get().getTables().size(), is(1));
+ assertThat(actual.get().getTables().iterator().next().getName(), is("foo"));
+ assertThat(actual.get().getTables().iterator().next().getColumns().size(), is(1));
+ assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getName(), is("foo_column"));
+ assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getCipher().getName(), is("FIXTURE"));
+ assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getCipher().getEncryptorName(), is("FOO"));
+ assertThat(actual.get().getEncryptors().size(), is(1));
+ assertThat(actual.get().getEncryptors().get("FOO").getType(), is("FOO"));
+ assertThat(actual.get().getEncryptors().get("FOO").getProps().size(), is(0));
}
}
diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapper.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapper.java
index dc7f8a7..a9ca6dd 100644
--- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapper.java
+++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapper.java
@@ -20,7 +20,7 @@
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
@@ -52,27 +52,27 @@
private final RuleNodePath maskRuleNodePath = new MaskRuleNodePathProvider().getRuleNodePath();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final MaskRuleConfiguration data) {
- Collection<YamlDataNode> result = new LinkedList<>();
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final MaskRuleConfiguration data) {
+ Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, AlgorithmConfiguration> entry : data.getMaskAlgorithms().entrySet()) {
- result.add(new YamlDataNode(maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getPath(entry.getKey()),
- YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(entry.getValue()))));
+ result.add(new RepositoryTuple(
+ maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getPath(entry.getKey()), YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(entry.getValue()))));
}
for (MaskTableRuleConfiguration each : data.getTables()) {
- result.add(new YamlDataNode(maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getPath(each.getName()), YamlEngine.marshal(tableSwapper.swapToYamlConfiguration(each))));
+ result.add(new RepositoryTuple(maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getPath(each.getName()), YamlEngine.marshal(tableSwapper.swapToYamlConfiguration(each))));
}
return result;
}
@Override
- public Optional<MaskRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- List<YamlDataNode> validDataNodes = dataNodes.stream().filter(each -> maskRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
- if (validDataNodes.isEmpty()) {
+ public Optional<MaskRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ List<RepositoryTuple> validTuples = repositoryTuples.stream().filter(each -> maskRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ if (validTuples.isEmpty()) {
return Optional.empty();
}
Collection<MaskTableRuleConfiguration> tables = new LinkedList<>();
Map<String, AlgorithmConfiguration> algorithms = new LinkedHashMap<>();
- for (YamlDataNode each : validDataNodes) {
+ for (RepositoryTuple each : validTuples) {
maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getName(each.getKey())
.ifPresent(optional -> tables.add(tableSwapper.swapToObject(YamlEngine.unmarshal(each.getValue(), YamlMaskTableRuleConfiguration.class))));
maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getName(each.getKey())
diff --git a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapperTest.java b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapperTest.java
index fa0d974..69aaf9b 100644
--- a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapperTest.java
+++ b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/YamlMaskDataNodeRuleConfigurationSwapperTest.java
@@ -18,12 +18,13 @@
package org.apache.shardingsphere.mask.yaml.swapper;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.mask.api.config.MaskRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskColumnRuleConfiguration;
import org.apache.shardingsphere.mask.api.config.rule.MaskTableRuleConfiguration;
import org.junit.jupiter.api.Test;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -41,15 +42,15 @@
@Test
void assertSwapEmptyConfigurationToDataNodes() {
MaskRuleConfiguration config = new MaskRuleConfiguration(Collections.emptyList(), Collections.emptyMap());
- assertThat(new YamlMaskDataNodeRuleConfigurationSwapper().swapToDataNodes(config).size(), is(0));
+ assertThat(new YamlMaskDataNodeRuleConfigurationSwapper().swapToRepositoryTuples(config).size(), is(0));
}
@Test
void assertSwapFullConfigurationToDataNodes() {
MaskRuleConfiguration config = createMaximumMaskRule();
- Collection<YamlDataNode> actual = new YamlMaskDataNodeRuleConfigurationSwapper().swapToDataNodes(config);
+ Collection<RepositoryTuple> actual = new YamlMaskDataNodeRuleConfigurationSwapper().swapToRepositoryTuples(config);
assertThat(actual.size(), is(2));
- Iterator<YamlDataNode> iterator = actual.iterator();
+ Iterator<RepositoryTuple> iterator = actual.iterator();
assertThat(iterator.next().getKey(), is("mask_algorithms/FIXTURE"));
assertThat(iterator.next().getKey(), is("tables/foo"));
}
@@ -67,14 +68,12 @@
@Test
void assertSwapToObject() {
- Collection<YamlDataNode> config = new LinkedList<>();
- config.add(new YamlDataNode("/metadata/foo_db/rules/mask/tables/foo/versions/0", "columns:\n"
+ Collection<RepositoryTuple> repositoryTuples = Arrays.asList(new RepositoryTuple("/metadata/foo_db/rules/mask/tables/foo/versions/0", "columns:\n"
+ " foo_column:\n"
+ " logicColumn: foo_column\n"
+ " maskAlgorithm: FIXTURE\n"
- + "name: foo\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/mask/mask_algorithms/FIXTURE/versions/0", "type: FIXTURE\n"));
- Optional<MaskRuleConfiguration> actual = new YamlMaskDataNodeRuleConfigurationSwapper().swapToObject(config);
+ + "name: foo\n"), new RepositoryTuple("/metadata/foo_db/rules/mask/mask_algorithms/FIXTURE/versions/0", "type: FIXTURE\n"));
+ Optional<MaskRuleConfiguration> actual = new YamlMaskDataNodeRuleConfigurationSwapper().swapToObject(repositoryTuples);
assertTrue(actual.isPresent());
assertThat(actual.get().getTables().size(), is(1));
assertThat(actual.get().getTables().iterator().next().getName(), is("foo"));
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapper.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapper.java
index 6fd477d1..f6455ff 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapper.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapper.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
@@ -51,14 +51,14 @@
private final RuleNodePath readwriteSplittingRuleNodePath = new ReadwriteSplittingRuleNodePathProvider().getRuleNodePath();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final ReadwriteSplittingRuleConfiguration data) {
- Collection<YamlDataNode> result = new LinkedList<>();
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final ReadwriteSplittingRuleConfiguration data) {
+ Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, AlgorithmConfiguration> entry : data.getLoadBalancers().entrySet()) {
- result.add(new YamlDataNode(readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getPath(entry.getKey()),
+ result.add(new RepositoryTuple(readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getPath(entry.getKey()),
YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(entry.getValue()))));
}
for (ReadwriteSplittingDataSourceGroupRuleConfiguration each : data.getDataSourceGroups()) {
- result.add(new YamlDataNode(readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getPath(each.getName()),
+ result.add(new RepositoryTuple(readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getPath(each.getName()),
YamlEngine.marshal(swapToYamlConfiguration(each))));
}
return result;
@@ -74,14 +74,14 @@
}
@Override
- public Optional<ReadwriteSplittingRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- List<YamlDataNode> validDataNodes = dataNodes.stream().filter(each -> readwriteSplittingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
- if (validDataNodes.isEmpty()) {
+ public Optional<ReadwriteSplittingRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ List<RepositoryTuple> validRepositoryTuples = repositoryTuples.stream().filter(each -> readwriteSplittingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ if (validRepositoryTuples.isEmpty()) {
return Optional.empty();
}
Collection<ReadwriteSplittingDataSourceGroupRuleConfiguration> dataSourceGroups = new LinkedList<>();
Map<String, AlgorithmConfiguration> loadBalancerMap = new LinkedHashMap<>();
- for (YamlDataNode each : validDataNodes) {
+ for (RepositoryTuple each : validRepositoryTuples) {
readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
.ifPresent(optional -> dataSourceGroups.add(swapDataSourceGroup(optional, YamlEngine.unmarshal(each.getValue(), YamlReadwriteSplittingDataSourceGroupRuleConfiguration.class))));
readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getName(each.getKey())
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapperTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapperTest.java
index ab63cc7..378fd66 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapperTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/YamlReadwriteSplittingDataNodeRuleConfigurationSwapperTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.readwritesplitting.yaml.swapper;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration;
import org.apache.shardingsphere.readwritesplitting.api.transaction.TransactionalReadQueryStrategy;
@@ -28,12 +28,13 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class YamlReadwriteSplittingDataNodeRuleConfigurationSwapperTest {
@@ -41,49 +42,48 @@
@Test
void assertSwapToDataNodesLoadBalancersEmpty() {
- ReadwriteSplittingRuleConfiguration config = new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceGroupRuleConfiguration("group_0",
+ ReadwriteSplittingRuleConfiguration ruleConfig = new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceGroupRuleConfiguration("group_0",
"write_ds", Arrays.asList("read_ds_0", "read_ds_1"), null)), Collections.emptyMap());
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(1));
- assertThat(result.iterator().next().getKey(), is("data_sources/group_0"));
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(ruleConfig);
+ assertThat(actual.size(), is(1));
+ assertThat(actual.iterator().next().getKey(), is("data_sources/group_0"));
}
@Test
void assertSwapToDataNodesLoadBalancers() {
- ReadwriteSplittingRuleConfiguration config = new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceGroupRuleConfiguration("group_0",
+ ReadwriteSplittingRuleConfiguration ruleConfig = new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceGroupRuleConfiguration("group_0",
"write_ds", Arrays.asList("read_ds_0", "read_ds_1"), "random")), Collections.singletonMap("random", new AlgorithmConfiguration("random", new Properties())));
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(2));
- Iterator<YamlDataNode> iterator = result.iterator();
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(ruleConfig);
+ assertThat(actual.size(), is(2));
+ Iterator<RepositoryTuple> iterator = actual.iterator();
assertThat(iterator.next().getKey(), is("load_balancers/random"));
assertThat(iterator.next().getKey(), is("data_sources/group_0"));
}
@Test
void assertSwapToObjectEmpty() {
- Collection<YamlDataNode> config = new LinkedList<>();
- assertFalse(swapper.swapToObject(config).isPresent());
+ assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
}
@Test
void assertSwapToObject() {
- Collection<YamlDataNode> config = new LinkedList<>();
- config.add(new YamlDataNode("/metadata/foo_db/rules/readwrite_splitting/data_sources/group_0/versions/0", "loadBalancerName: random\n"
+ Collection<RepositoryTuple> repositoryTuples = Arrays.asList(new RepositoryTuple("/metadata/foo_db/rules/readwrite_splitting/data_sources/group_0/versions/0", "loadBalancerName: random\n"
+ "readDataSourceNames:\n"
+ "- read_ds_0\n"
+ "- read_ds_1\n"
+ "transactionalReadQueryStrategy: DYNAMIC\n"
- + "writeDataSourceName: write_ds\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/readwrite_splitting/load_balancers/random/versions/0", "type: random\n"));
- ReadwriteSplittingRuleConfiguration result = swapper.swapToObject(config).get();
- assertThat(result.getDataSourceGroups().size(), is(1));
- assertThat(result.getDataSourceGroups().iterator().next().getName(), is("group_0"));
- assertThat(result.getDataSourceGroups().iterator().next().getWriteDataSourceName(), is("write_ds"));
- assertThat(result.getDataSourceGroups().iterator().next().getReadDataSourceNames().size(), is(2));
- assertThat(result.getDataSourceGroups().iterator().next().getLoadBalancerName(), is("random"));
- assertThat(result.getDataSourceGroups().iterator().next().getTransactionalReadQueryStrategy(), is(TransactionalReadQueryStrategy.DYNAMIC));
- assertThat(result.getLoadBalancers().size(), is(1));
- assertThat(result.getLoadBalancers().get("random").getType(), is("random"));
- assertThat(result.getLoadBalancers().get("random").getProps().size(), is(0));
+ + "writeDataSourceName: write_ds\n"),
+ new RepositoryTuple("/metadata/foo_db/rules/readwrite_splitting/load_balancers/random/versions/0", "type: random\n"));
+ Optional<ReadwriteSplittingRuleConfiguration> actual = swapper.swapToObject(repositoryTuples);
+ assertTrue(actual.isPresent());
+ assertThat(actual.get().getDataSourceGroups().size(), is(1));
+ assertThat(actual.get().getDataSourceGroups().iterator().next().getName(), is("group_0"));
+ assertThat(actual.get().getDataSourceGroups().iterator().next().getWriteDataSourceName(), is("write_ds"));
+ assertThat(actual.get().getDataSourceGroups().iterator().next().getReadDataSourceNames().size(), is(2));
+ assertThat(actual.get().getDataSourceGroups().iterator().next().getLoadBalancerName(), is("random"));
+ assertThat(actual.get().getDataSourceGroups().iterator().next().getTransactionalReadQueryStrategy(), is(TransactionalReadQueryStrategy.DYNAMIC));
+ assertThat(actual.get().getLoadBalancers().size(), is(1));
+ assertThat(actual.get().getLoadBalancers().get("random").getType(), is("random"));
+ assertThat(actual.get().getLoadBalancers().get("random").getProps().size(), is(0));
}
}
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapper.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapper.java
index ab06b71..7510b36 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapper.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapper.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
@@ -53,21 +53,21 @@
private final RuleNodePath shadowRuleNodePath = new ShadowRuleNodePathProvider().getRuleNodePath();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final ShadowRuleConfiguration data) {
- Collection<YamlDataNode> result = new LinkedList<>();
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final ShadowRuleConfiguration data) {
+ Collection<RepositoryTuple> result = new LinkedList<>();
for (Entry<String, AlgorithmConfiguration> entry : data.getShadowAlgorithms().entrySet()) {
- result.add(new YamlDataNode(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.ALGORITHMS).getPath(entry.getKey()),
+ result.add(new RepositoryTuple(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.ALGORITHMS).getPath(entry.getKey()),
YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(entry.getValue()))));
}
if (!Strings.isNullOrEmpty(data.getDefaultShadowAlgorithmName())) {
- result.add(new YamlDataNode(shadowRuleNodePath.getUniqueItem(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM).getPath(), data.getDefaultShadowAlgorithmName()));
+ result.add(new RepositoryTuple(shadowRuleNodePath.getUniqueItem(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM).getPath(), data.getDefaultShadowAlgorithmName()));
}
for (ShadowDataSourceConfiguration each : data.getDataSources()) {
- result.add(new YamlDataNode(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getPath(each.getName()),
+ result.add(new RepositoryTuple(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getPath(each.getName()),
YamlEngine.marshal(swapToDataSourceYamlConfiguration(each))));
}
for (Entry<String, ShadowTableConfiguration> entry : data.getTables().entrySet()) {
- result.add(new YamlDataNode(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getPath(entry.getKey()),
+ result.add(new RepositoryTuple(shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getPath(entry.getKey()),
YamlEngine.marshal(tableSwapper.swapToYamlConfiguration(entry.getValue()))));
}
return result;
@@ -81,13 +81,13 @@
}
@Override
- public Optional<ShadowRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- List<YamlDataNode> validDataNodes = dataNodes.stream().filter(each -> shadowRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
- if (validDataNodes.isEmpty()) {
+ public Optional<ShadowRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ List<RepositoryTuple> validRepositoryTuples = repositoryTuples.stream().filter(each -> shadowRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ if (validRepositoryTuples.isEmpty()) {
return Optional.empty();
}
ShadowRuleConfiguration result = new ShadowRuleConfiguration();
- for (YamlDataNode each : validDataNodes) {
+ for (RepositoryTuple each : validRepositoryTuples) {
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
.ifPresent(optional -> result.getDataSources().add(swapDataSource(optional, YamlEngine.unmarshal(each.getValue(), YamlShadowDataSourceConfiguration.class))));
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getName(each.getKey())
diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapperTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapperTest.java
index 14b9636..c879da0 100644
--- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapperTest.java
+++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/YamlShadowDataNodeRuleConfigurationSwapperTest.java
@@ -18,23 +18,26 @@
package org.apache.shardingsphere.shadow.yaml.swapper;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
import org.junit.jupiter.api.Test;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class YamlShadowDataNodeRuleConfigurationSwapperTest {
@@ -42,17 +45,14 @@
@Test
void assertSwapEmptyConfigToDataNodes() {
- ShadowRuleConfiguration config = new ShadowRuleConfiguration();
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(0));
+ assertTrue(swapper.swapToRepositoryTuples(new ShadowRuleConfiguration()).isEmpty());
}
@Test
void assertSwapFullConfigToDataNodes() {
- ShadowRuleConfiguration config = createMaximumShadowRule();
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(4));
- Iterator<YamlDataNode> iterator = result.iterator();
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(createMaximumShadowRule());
+ assertThat(actual.size(), is(4));
+ Iterator<RepositoryTuple> iterator = actual.iterator();
assertThat(iterator.next().getKey(), is("algorithms/FIXTURE"));
assertThat(iterator.next().getKey(), is("default_algorithm_name"));
assertThat(iterator.next().getKey(), is("data_sources/foo"));
@@ -76,34 +76,33 @@
@Test
void assertSwapToObjectEmpty() {
- Collection<YamlDataNode> config = new LinkedList<>();
- assertFalse(swapper.swapToObject(config).isPresent());
+ assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
}
@Test
void assertSwapToObject() {
- Collection<YamlDataNode> config = new LinkedList<>();
- config.add(new YamlDataNode("/metadata/foo_db/rules/shadow/data_sources/foo_db/versions/0", "productionDataSourceName: ds_0\n"
- + "shadowDataSourceName: ds_1\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/shadow/tables/foo_table/versions/0", "dataSourceNames:\n"
- + "- ds_0\n"
- + "shadowAlgorithmNames:\n"
- + "- FIXTURE\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/shadow/algorithms/FIXTURE/versions/0", "type: FIXTURE\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/shadow/default_algorithm_name/versions/0", "FIXTURE"));
- ShadowRuleConfiguration result = swapper.swapToObject(config).get();
- assertThat(result.getDataSources().size(), is(1));
- assertThat(result.getDataSources().iterator().next().getName(), is("foo_db"));
- assertThat(result.getDataSources().iterator().next().getProductionDataSourceName(), is("ds_0"));
- assertThat(result.getDataSources().iterator().next().getShadowDataSourceName(), is("ds_1"));
- assertThat(result.getTables().size(), is(1));
- assertThat(result.getTables().get("foo_table").getDataSourceNames().size(), is(1));
- assertThat(result.getTables().get("foo_table").getDataSourceNames().iterator().next(), is("ds_0"));
- assertThat(result.getTables().get("foo_table").getShadowAlgorithmNames().size(), is(1));
- assertThat(result.getTables().get("foo_table").getShadowAlgorithmNames().iterator().next(), is("FIXTURE"));
- assertThat(result.getShadowAlgorithms().size(), is(1));
- assertThat(result.getShadowAlgorithms().get("FIXTURE").getType(), is("FIXTURE"));
- assertThat(result.getShadowAlgorithms().get("FIXTURE").getProps().size(), is(0));
- assertThat(result.getDefaultShadowAlgorithmName(), is("FIXTURE"));
+ Collection<RepositoryTuple> repositoryTuples = Arrays.asList(
+ new RepositoryTuple("/metadata/foo_db/rules/shadow/data_sources/foo_db/versions/0", "productionDataSourceName: ds_0\nshadowDataSourceName: ds_1\n"),
+ new RepositoryTuple("/metadata/foo_db/rules/shadow/tables/foo_table/versions/0", "dataSourceNames:\n"
+ + "- ds_0\n"
+ + "shadowAlgorithmNames:\n"
+ + "- FIXTURE\n"),
+ new RepositoryTuple("/metadata/foo_db/rules/shadow/algorithms/FIXTURE/versions/0", "type: FIXTURE\n"),
+ new RepositoryTuple("/metadata/foo_db/rules/shadow/default_algorithm_name/versions/0", "FIXTURE"));
+ Optional<ShadowRuleConfiguration> actual = swapper.swapToObject(repositoryTuples);
+ assertTrue(actual.isPresent());
+ assertThat(actual.get().getDataSources().size(), is(1));
+ assertThat(actual.get().getDataSources().iterator().next().getName(), is("foo_db"));
+ assertThat(actual.get().getDataSources().iterator().next().getProductionDataSourceName(), is("ds_0"));
+ assertThat(actual.get().getDataSources().iterator().next().getShadowDataSourceName(), is("ds_1"));
+ assertThat(actual.get().getTables().size(), is(1));
+ assertThat(actual.get().getTables().get("foo_table").getDataSourceNames().size(), is(1));
+ assertThat(actual.get().getTables().get("foo_table").getDataSourceNames().iterator().next(), is("ds_0"));
+ assertThat(actual.get().getTables().get("foo_table").getShadowAlgorithmNames().size(), is(1));
+ assertThat(actual.get().getTables().get("foo_table").getShadowAlgorithmNames().iterator().next(), is("FIXTURE"));
+ assertThat(actual.get().getShadowAlgorithms().size(), is(1));
+ assertThat(actual.get().getShadowAlgorithms().get("FIXTURE").getType(), is("FIXTURE"));
+ assertThat(actual.get().getShadowAlgorithms().get("FIXTURE").getProps().size(), is(0));
+ assertThat(actual.get().getDefaultShadowAlgorithmName(), is("FIXTURE"));
}
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapper.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapper.java
index 99e976d..3d44648 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapper.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapper.java
@@ -20,7 +20,7 @@
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
@@ -73,78 +73,78 @@
private final RuleNodePath shardingRuleNodePath = new ShardingRuleNodePathProvider().getRuleNodePath();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final ShardingRuleConfiguration data) {
- Collection<YamlDataNode> result = new LinkedList<>();
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final ShardingRuleConfiguration data) {
+ Collection<RepositoryTuple> result = new LinkedList<>();
swapAlgorithms(data, result);
swapStrategies(data, result);
if (null != data.getDefaultShardingColumn()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_SHARDING_COLUMN).getPath(), data.getDefaultShardingColumn()));
+ result.add(new RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_SHARDING_COLUMN).getPath(), data.getDefaultShardingColumn()));
}
if (null != data.getShardingCache()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.SHARDING_CACHE).getPath(),
+ result.add(new RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.SHARDING_CACHE).getPath(),
YamlEngine.marshal(shardingCacheSwapper.swapToYamlConfiguration(data.getShardingCache()))));
}
swapTableRules(data, result);
return result;
}
- private void swapAlgorithms(final ShardingRuleConfiguration data, final Collection<YamlDataNode> result) {
+ private void swapAlgorithms(final ShardingRuleConfiguration data, final Collection<RepositoryTuple> repositoryTuples) {
for (Entry<String, AlgorithmConfiguration> each : data.getShardingAlgorithms().entrySet()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.ALGORITHMS).getPath(each.getKey()),
- YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(each.getValue()))));
+ repositoryTuples.add(new RepositoryTuple(
+ shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.ALGORITHMS).getPath(each.getKey()), YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(each.getValue()))));
}
for (Entry<String, AlgorithmConfiguration> each : data.getKeyGenerators().entrySet()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.KEY_GENERATORS).getPath(each.getKey()),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.KEY_GENERATORS).getPath(each.getKey()),
YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(each.getValue()))));
}
for (Entry<String, AlgorithmConfiguration> each : data.getAuditors().entrySet()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUDITORS).getPath(each.getKey()),
- YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(each.getValue()))));
+ repositoryTuples.add(new RepositoryTuple(
+ shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUDITORS).getPath(each.getKey()), YamlEngine.marshal(algorithmSwapper.swapToYamlConfiguration(each.getValue()))));
}
}
- private void swapStrategies(final ShardingRuleConfiguration data, final Collection<YamlDataNode> result) {
+ private void swapStrategies(final ShardingRuleConfiguration data, final Collection<RepositoryTuple> repositoryTuples) {
if (null != data.getDefaultDatabaseShardingStrategy()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY).getPath(),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY).getPath(),
YamlEngine.marshal(shardingStrategySwapper.swapToYamlConfiguration(data.getDefaultDatabaseShardingStrategy()))));
}
if (null != data.getDefaultTableShardingStrategy()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY).getPath(),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY).getPath(),
YamlEngine.marshal(shardingStrategySwapper.swapToYamlConfiguration(data.getDefaultTableShardingStrategy()))));
}
if (null != data.getDefaultKeyGenerateStrategy()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_KEY_GENERATE_STRATEGY).getPath(),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_KEY_GENERATE_STRATEGY).getPath(),
YamlEngine.marshal(keyGenerateStrategySwapper.swapToYamlConfiguration(data.getDefaultKeyGenerateStrategy()))));
}
if (null != data.getDefaultAuditStrategy()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_AUDIT_STRATEGY).getPath(),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_AUDIT_STRATEGY).getPath(),
YamlEngine.marshal(auditStrategySwapper.swapToYamlConfiguration(data.getDefaultAuditStrategy()))));
}
}
- private void swapTableRules(final ShardingRuleConfiguration data, final Collection<YamlDataNode> result) {
+ private void swapTableRules(final ShardingRuleConfiguration data, final Collection<RepositoryTuple> repositoryTuples) {
for (ShardingTableRuleConfiguration each : data.getTables()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getPath(each.getLogicTable()),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getPath(each.getLogicTable()),
YamlEngine.marshal(tableSwapper.swapToYamlConfiguration(each))));
}
for (ShardingAutoTableRuleConfiguration each : data.getAutoTables()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getPath(each.getLogicTable()),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getPath(each.getLogicTable()),
YamlEngine.marshal(autoTableSwapper.swapToYamlConfiguration(each))));
}
for (ShardingTableReferenceRuleConfiguration each : data.getBindingTableGroups()) {
- result.add(new YamlDataNode(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.BINDING_TABLES).getPath(each.getName()),
+ repositoryTuples.add(new RepositoryTuple(shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.BINDING_TABLES).getPath(each.getName()),
YamlShardingTableReferenceRuleConfigurationConverter.convertToYamlString(each)));
}
}
@Override
- public Optional<ShardingRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- List<YamlDataNode> validDataNodes = dataNodes.stream().filter(each -> shardingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
- if (validDataNodes.isEmpty()) {
+ public Optional<ShardingRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ List<RepositoryTuple> validRepositoryTuples = repositoryTuples.stream().filter(each -> shardingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+ if (validRepositoryTuples.isEmpty()) {
return Optional.empty();
}
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
- for (YamlDataNode each : validDataNodes) {
+ for (RepositoryTuple each : validRepositoryTuples) {
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getName(each.getKey())
.ifPresent(optional -> result.getTables().add(tableSwapper.swapToObject(YamlEngine.unmarshal(each.getValue(), YamlTableRuleConfiguration.class))));
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getName(each.getKey())
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapperTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapperTest.java
index 2f34011..d80d438 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapperTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/YamlShardingDataNodeRuleConfigurationSwapperTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.yaml.swapper;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
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.ShardingTableReferenceRuleConfiguration;
@@ -49,17 +49,14 @@
@Test
void assertSwapEmptyConfigToDataNodes() {
- ShardingRuleConfiguration config = new ShardingRuleConfiguration();
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(0));
+ assertTrue(swapper.swapToRepositoryTuples(new ShardingRuleConfiguration()).isEmpty());
}
@Test
void assertSwapFullConfigToDataNodes() {
- ShardingRuleConfiguration config = createMaximumShardingRule();
- Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
- assertThat(result.size(), is(15));
- Iterator<YamlDataNode> iterator = result.iterator();
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(createMaximumShardingRule());
+ assertThat(actual.size(), is(15));
+ Iterator<RepositoryTuple> iterator = actual.iterator();
assertThat(iterator.next().getKey(), is("algorithms/core_standard_fixture"));
assertThat(iterator.next().getKey(), is("algorithms/hash_mod"));
assertThat(iterator.next().getKey(), is("key_generators/uuid"));
@@ -115,14 +112,13 @@
@Test
void assertSwapToObjectEmpty() {
- Collection<YamlDataNode> config = new LinkedList<>();
- assertFalse(swapper.swapToObject(config).isPresent());
+ assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
}
@Test
void assertSwapToObject() {
- Collection<YamlDataNode> config = new LinkedList<>();
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/tables/LOGIC_TABLE/versions/0", "actualDataNodes: ds_${0..1}.table_${0..2}\n"
+ Collection<RepositoryTuple> repositoryTuples = new LinkedList<>();
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/tables/LOGIC_TABLE/versions/0", "actualDataNodes: ds_${0..1}.table_${0..2}\n"
+ "auditStrategy:\n"
+ " allowHintDisable: false\n"
+ " auditorNames:\n"
@@ -139,7 +135,7 @@
+ " standard:\n"
+ " shardingAlgorithmName: table_inline\n"
+ " shardingColumn: order_id\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/tables/SUB_LOGIC_TABLE/versions/0", "actualDataNodes: ds_${0..1}.sub_table_${0..2}\n"
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/tables/SUB_LOGIC_TABLE/versions/0", "actualDataNodes: ds_${0..1}.sub_table_${0..2}\n"
+ "databaseStrategy:\n"
+ " standard:\n"
+ " shardingAlgorithmName: database_inline\n"
@@ -152,7 +148,7 @@
+ " standard:\n"
+ " shardingAlgorithmName: table_inline\n"
+ " shardingColumn: order_id\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/auto_tables/auto_table/versions/0", "actualDataSources: ds_1,ds_2\n"
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/auto_tables/auto_table/versions/0", "actualDataSources: ds_1,ds_2\n"
+ "auditStrategy:\n"
+ " allowHintDisable: true\n"
+ " auditorNames:\n"
@@ -165,87 +161,87 @@
+ " standard:\n"
+ " shardingAlgorithmName: hash_mod\n"
+ " shardingColumn: user_id\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/binding_tables/foo/versions/0", "foo:LOGIC_TABLE,SUB_LOGIC_TABLE"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/default_strategies/default_database_strategy/versions/0", "standard:\n"
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/binding_tables/foo/versions/0", "foo:LOGIC_TABLE,SUB_LOGIC_TABLE"));
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/default_strategies/default_database_strategy/versions/0", "standard:\n"
+ " shardingAlgorithmName: standard\n"
+ " shardingColumn: ds_id\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/default_strategies/default_table_strategy/versions/0", "standard:\n"
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/default_strategies/default_table_strategy/versions/0", "standard:\n"
+ " shardingAlgorithmName: standard\n"
+ " shardingColumn: table_id\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/default_strategies/default_key_generate_strategy/versions/0", "column: id\n"
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/default_strategies/default_key_generate_strategy/versions/0", "column: id\n"
+ "keyGeneratorName: default\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/default_strategies/default_audit_strategy/versions/0", "allowHintDisable: false\n"
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/default_strategies/default_audit_strategy/versions/0", "allowHintDisable: false\n"
+ "auditorNames:\n"
+ "- audit_algorithm\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/algorithms/core_standard_fixture/versions/0", "type: CORE.STANDARD.FIXTURE\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/algorithms/hash_mod/versions/0", "props:\n"
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/algorithms/core_standard_fixture/versions/0", "type: CORE.STANDARD.FIXTURE\n"));
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/algorithms/hash_mod/versions/0", "props:\n"
+ " sharding-count: '4'\n"
+ "type: hash_mod\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/key_generators/uuid/versions/0", "type: UUID\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/key_generators/default/versions/0", "type: UUID\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/key_generators/auto_increment/versions/0", "type: AUTO_INCREMENT.FIXTURE\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/auditors/audit_algorithm/versions/0", "type: DML_SHARDING_CONDITIONS\n"));
- config.add(new YamlDataNode("/metadata/foo_db/rules/sharding/default_strategies/default_sharding_column/versions/0", "table_id"));
- Optional<ShardingRuleConfiguration> shardingRuleConfig = swapper.swapToObject(config);
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/key_generators/uuid/versions/0", "type: UUID\n"));
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/key_generators/default/versions/0", "type: UUID\n"));
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/key_generators/auto_increment/versions/0", "type: AUTO_INCREMENT.FIXTURE\n"));
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/auditors/audit_algorithm/versions/0", "type: DML_SHARDING_CONDITIONS\n"));
+ repositoryTuples.add(new RepositoryTuple("/metadata/foo_db/rules/sharding/default_strategies/default_sharding_column/versions/0", "table_id"));
+ Optional<ShardingRuleConfiguration> shardingRuleConfig = swapper.swapToObject(repositoryTuples);
assertTrue(shardingRuleConfig.isPresent());
- ShardingRuleConfiguration result = shardingRuleConfig.get();
- assertThat(result.getTables().size(), is(2));
- assertThat(result.getTables().iterator().next().getLogicTable(), is("LOGIC_TABLE"));
- assertThat(result.getTables().iterator().next().getActualDataNodes(), is("ds_${0..1}.table_${0..2}"));
- assertInstanceOf(StandardShardingStrategyConfiguration.class, result.getTables().iterator().next().getDatabaseShardingStrategy());
- assertThat(((StandardShardingStrategyConfiguration) result.getTables().iterator().next().getDatabaseShardingStrategy()).getShardingColumn(), is("user_id"));
- assertThat(result.getTables().iterator().next().getDatabaseShardingStrategy().getShardingAlgorithmName(), is("database_inline"));
- assertThat(result.getTables().iterator().next().getDatabaseShardingStrategy().getType(), is("STANDARD"));
- assertInstanceOf(StandardShardingStrategyConfiguration.class, result.getTables().iterator().next().getTableShardingStrategy());
- assertThat(((StandardShardingStrategyConfiguration) result.getTables().iterator().next().getTableShardingStrategy()).getShardingColumn(), is("order_id"));
- assertThat(result.getTables().iterator().next().getTableShardingStrategy().getShardingAlgorithmName(), is("table_inline"));
- assertThat(result.getTables().iterator().next().getTableShardingStrategy().getType(), is("STANDARD"));
- assertThat(result.getTables().iterator().next().getKeyGenerateStrategy().getColumn(), is("id"));
- assertThat(result.getTables().iterator().next().getKeyGenerateStrategy().getKeyGeneratorName(), is("uuid"));
- assertThat(result.getTables().iterator().next().getAuditStrategy().getAuditorNames().size(), is(1));
- assertThat(result.getTables().iterator().next().getAuditStrategy().getAuditorNames().iterator().next(), is("audit_algorithm"));
- assertFalse(result.getTables().iterator().next().getAuditStrategy().isAllowHintDisable());
- assertThat(result.getAutoTables().size(), is(1));
- assertThat(result.getAutoTables().iterator().next().getLogicTable(), is("auto_table"));
- assertThat(result.getAutoTables().iterator().next().getActualDataSources(), is("ds_1,ds_2"));
- assertInstanceOf(StandardShardingStrategyConfiguration.class, result.getAutoTables().iterator().next().getShardingStrategy());
- assertThat(((StandardShardingStrategyConfiguration) result.getAutoTables().iterator().next().getShardingStrategy()).getShardingColumn(), is("user_id"));
- assertThat(result.getAutoTables().iterator().next().getShardingStrategy().getShardingAlgorithmName(), is("hash_mod"));
- assertThat(result.getAutoTables().iterator().next().getShardingStrategy().getType(), is("STANDARD"));
- assertThat(result.getAutoTables().iterator().next().getKeyGenerateStrategy().getColumn(), is("id"));
- assertThat(result.getAutoTables().iterator().next().getKeyGenerateStrategy().getKeyGeneratorName(), is("auto_increment"));
- assertThat(result.getAutoTables().iterator().next().getAuditStrategy().getAuditorNames().size(), is(1));
- assertThat(result.getAutoTables().iterator().next().getAuditStrategy().getAuditorNames().iterator().next(), is("audit_algorithm"));
- assertTrue(result.getAutoTables().iterator().next().getAuditStrategy().isAllowHintDisable());
- assertThat(result.getBindingTableGroups().size(), is(1));
- assertThat(result.getBindingTableGroups().iterator().next().getName(), is("foo"));
- assertThat(result.getBindingTableGroups().iterator().next().getReference(), is("LOGIC_TABLE,SUB_LOGIC_TABLE"));
- assertInstanceOf(StandardShardingStrategyConfiguration.class, result.getDefaultDatabaseShardingStrategy());
- assertThat(((StandardShardingStrategyConfiguration) result.getDefaultDatabaseShardingStrategy()).getType(), is("STANDARD"));
- assertThat(((StandardShardingStrategyConfiguration) result.getDefaultDatabaseShardingStrategy()).getShardingColumn(), is("ds_id"));
- assertThat(result.getDefaultDatabaseShardingStrategy().getShardingAlgorithmName(), is("standard"));
- assertInstanceOf(StandardShardingStrategyConfiguration.class, result.getDefaultTableShardingStrategy());
- assertThat(((StandardShardingStrategyConfiguration) result.getDefaultTableShardingStrategy()).getType(), is("STANDARD"));
- assertThat(((StandardShardingStrategyConfiguration) result.getDefaultTableShardingStrategy()).getShardingColumn(), is("table_id"));
- assertThat(result.getDefaultTableShardingStrategy().getShardingAlgorithmName(), is("standard"));
- assertThat(result.getDefaultKeyGenerateStrategy().getColumn(), is("id"));
- assertThat(result.getDefaultKeyGenerateStrategy().getKeyGeneratorName(), is("default"));
- assertThat(result.getDefaultAuditStrategy().getAuditorNames().size(), is(1));
- assertThat(result.getDefaultAuditStrategy().getAuditorNames().iterator().next(), is("audit_algorithm"));
- assertFalse(result.getDefaultAuditStrategy().isAllowHintDisable());
- assertThat(result.getDefaultShardingColumn(), is("table_id"));
- assertThat(result.getShardingAlgorithms().size(), is(2));
- assertThat(result.getShardingAlgorithms().get("core_standard_fixture").getType(), is("CORE.STANDARD.FIXTURE"));
- assertThat(result.getShardingAlgorithms().get("hash_mod").getType(), is("hash_mod"));
- assertThat(result.getShardingAlgorithms().get("hash_mod").getProps().size(), is(1));
- assertThat(result.getShardingAlgorithms().get("hash_mod").getProps().get("sharding-count"), is("4"));
- assertThat(result.getKeyGenerators().size(), is(3));
- assertThat(result.getKeyGenerators().get("uuid").getType(), is("UUID"));
- assertThat(result.getKeyGenerators().get("uuid").getProps().size(), is(0));
- assertThat(result.getKeyGenerators().get("auto_increment").getType(), is("AUTO_INCREMENT.FIXTURE"));
- assertThat(result.getAuditors().size(), is(1));
- assertThat(result.getAuditors().get("audit_algorithm").getType(), is("DML_SHARDING_CONDITIONS"));
- assertThat(result.getAuditors().get("audit_algorithm").getProps().size(), is(0));
- assertNull(result.getShardingCache());
+ ShardingRuleConfiguration actual = shardingRuleConfig.get();
+ assertThat(actual.getTables().size(), is(2));
+ assertThat(actual.getTables().iterator().next().getLogicTable(), is("LOGIC_TABLE"));
+ assertThat(actual.getTables().iterator().next().getActualDataNodes(), is("ds_${0..1}.table_${0..2}"));
+ assertInstanceOf(StandardShardingStrategyConfiguration.class, actual.getTables().iterator().next().getDatabaseShardingStrategy());
+ assertThat(((StandardShardingStrategyConfiguration) actual.getTables().iterator().next().getDatabaseShardingStrategy()).getShardingColumn(), is("user_id"));
+ assertThat(actual.getTables().iterator().next().getDatabaseShardingStrategy().getShardingAlgorithmName(), is("database_inline"));
+ assertThat(actual.getTables().iterator().next().getDatabaseShardingStrategy().getType(), is("STANDARD"));
+ assertInstanceOf(StandardShardingStrategyConfiguration.class, actual.getTables().iterator().next().getTableShardingStrategy());
+ assertThat(((StandardShardingStrategyConfiguration) actual.getTables().iterator().next().getTableShardingStrategy()).getShardingColumn(), is("order_id"));
+ assertThat(actual.getTables().iterator().next().getTableShardingStrategy().getShardingAlgorithmName(), is("table_inline"));
+ assertThat(actual.getTables().iterator().next().getTableShardingStrategy().getType(), is("STANDARD"));
+ assertThat(actual.getTables().iterator().next().getKeyGenerateStrategy().getColumn(), is("id"));
+ assertThat(actual.getTables().iterator().next().getKeyGenerateStrategy().getKeyGeneratorName(), is("uuid"));
+ assertThat(actual.getTables().iterator().next().getAuditStrategy().getAuditorNames().size(), is(1));
+ assertThat(actual.getTables().iterator().next().getAuditStrategy().getAuditorNames().iterator().next(), is("audit_algorithm"));
+ assertFalse(actual.getTables().iterator().next().getAuditStrategy().isAllowHintDisable());
+ assertThat(actual.getAutoTables().size(), is(1));
+ assertThat(actual.getAutoTables().iterator().next().getLogicTable(), is("auto_table"));
+ assertThat(actual.getAutoTables().iterator().next().getActualDataSources(), is("ds_1,ds_2"));
+ assertInstanceOf(StandardShardingStrategyConfiguration.class, actual.getAutoTables().iterator().next().getShardingStrategy());
+ assertThat(((StandardShardingStrategyConfiguration) actual.getAutoTables().iterator().next().getShardingStrategy()).getShardingColumn(), is("user_id"));
+ assertThat(actual.getAutoTables().iterator().next().getShardingStrategy().getShardingAlgorithmName(), is("hash_mod"));
+ assertThat(actual.getAutoTables().iterator().next().getShardingStrategy().getType(), is("STANDARD"));
+ assertThat(actual.getAutoTables().iterator().next().getKeyGenerateStrategy().getColumn(), is("id"));
+ assertThat(actual.getAutoTables().iterator().next().getKeyGenerateStrategy().getKeyGeneratorName(), is("auto_increment"));
+ assertThat(actual.getAutoTables().iterator().next().getAuditStrategy().getAuditorNames().size(), is(1));
+ assertThat(actual.getAutoTables().iterator().next().getAuditStrategy().getAuditorNames().iterator().next(), is("audit_algorithm"));
+ assertTrue(actual.getAutoTables().iterator().next().getAuditStrategy().isAllowHintDisable());
+ assertThat(actual.getBindingTableGroups().size(), is(1));
+ assertThat(actual.getBindingTableGroups().iterator().next().getName(), is("foo"));
+ assertThat(actual.getBindingTableGroups().iterator().next().getReference(), is("LOGIC_TABLE,SUB_LOGIC_TABLE"));
+ assertInstanceOf(StandardShardingStrategyConfiguration.class, actual.getDefaultDatabaseShardingStrategy());
+ assertThat(((StandardShardingStrategyConfiguration) actual.getDefaultDatabaseShardingStrategy()).getType(), is("STANDARD"));
+ assertThat(((StandardShardingStrategyConfiguration) actual.getDefaultDatabaseShardingStrategy()).getShardingColumn(), is("ds_id"));
+ assertThat(actual.getDefaultDatabaseShardingStrategy().getShardingAlgorithmName(), is("standard"));
+ assertInstanceOf(StandardShardingStrategyConfiguration.class, actual.getDefaultTableShardingStrategy());
+ assertThat(((StandardShardingStrategyConfiguration) actual.getDefaultTableShardingStrategy()).getType(), is("STANDARD"));
+ assertThat(((StandardShardingStrategyConfiguration) actual.getDefaultTableShardingStrategy()).getShardingColumn(), is("table_id"));
+ assertThat(actual.getDefaultTableShardingStrategy().getShardingAlgorithmName(), is("standard"));
+ assertThat(actual.getDefaultKeyGenerateStrategy().getColumn(), is("id"));
+ assertThat(actual.getDefaultKeyGenerateStrategy().getKeyGeneratorName(), is("default"));
+ assertThat(actual.getDefaultAuditStrategy().getAuditorNames().size(), is(1));
+ assertThat(actual.getDefaultAuditStrategy().getAuditorNames().iterator().next(), is("audit_algorithm"));
+ assertFalse(actual.getDefaultAuditStrategy().isAllowHintDisable());
+ assertThat(actual.getDefaultShardingColumn(), is("table_id"));
+ assertThat(actual.getShardingAlgorithms().size(), is(2));
+ assertThat(actual.getShardingAlgorithms().get("core_standard_fixture").getType(), is("CORE.STANDARD.FIXTURE"));
+ assertThat(actual.getShardingAlgorithms().get("hash_mod").getType(), is("hash_mod"));
+ assertThat(actual.getShardingAlgorithms().get("hash_mod").getProps().size(), is(1));
+ assertThat(actual.getShardingAlgorithms().get("hash_mod").getProps().get("sharding-count"), is("4"));
+ assertThat(actual.getKeyGenerators().size(), is(3));
+ assertThat(actual.getKeyGenerators().get("uuid").getType(), is("UUID"));
+ assertThat(actual.getKeyGenerators().get("uuid").getProps().size(), is(0));
+ assertThat(actual.getKeyGenerators().get("auto_increment").getType(), is("AUTO_INCREMENT.FIXTURE"));
+ assertThat(actual.getAuditors().size(), is(1));
+ assertThat(actual.getAuditors().get("audit_algorithm").getType(), is("DML_SHARDING_CONDITIONS"));
+ assertThat(actual.getAuditors().get("audit_algorithm").getProps().size(), is(0));
+ assertNull(actual.getShardingCache());
}
}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeGlobalRuleConfigurationSwapperEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeGlobalRuleConfigurationSwapperEngine.java
index ece8a4e..24f6b30 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeGlobalRuleConfigurationSwapperEngine.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeGlobalRuleConfigurationSwapperEngine.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import java.util.Collection;
import java.util.LinkedList;
@@ -45,14 +45,14 @@
/**
* Swap from YAML global rule configurations to rule configurations.
*
- * @param dataNodes YAML data nodes
+ * @param repositoryTuples repository tuples
* @return global rule configurations
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public Collection<RuleConfiguration> swapToRuleConfigurations(final Collection<YamlDataNode> dataNodes) {
+ public Collection<RuleConfiguration> swapToRuleConfigurations(final Collection<RepositoryTuple> repositoryTuples) {
Collection<RuleConfiguration> result = new LinkedList<>();
for (YamlDataNodeGlobalRuleConfigurationSwapper each : OrderedSPILoader.getServices(YamlDataNodeGlobalRuleConfigurationSwapper.class)) {
- each.swapToObject(dataNodes).ifPresent(optional -> result.add((RuleConfiguration) optional));
+ each.swapToObject(repositoryTuples).ifPresent(optional -> result.add((RuleConfiguration) optional));
}
return result;
}
@@ -61,14 +61,14 @@
* Swap from single YAML global rule configuration to rule configurations.
*
* @param ruleName rule name
- * @param dataNodes YAML data nodes
+ * @param repositoryTuples repository tuples
* @return global rule configuration
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public Optional<RuleConfiguration> swapSingleRuleToRuleConfiguration(final String ruleName, final Collection<YamlDataNode> dataNodes) {
+ public Optional<RuleConfiguration> swapSingleRuleToRuleConfiguration(final String ruleName, final Collection<RepositoryTuple> repositoryTuples) {
for (YamlDataNodeGlobalRuleConfigurationSwapper each : OrderedSPILoader.getServices(YamlDataNodeGlobalRuleConfigurationSwapper.class)) {
if (ruleName.equals(each.getRuleTagName().toLowerCase())) {
- return each.swapToObject(dataNodes);
+ return each.swapToObject(repositoryTuples);
}
}
return Optional.empty();
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeRuleConfigurationSwapperEngine.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeRuleConfigurationSwapperEngine.java
index f0de6d8..f7ded20 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeRuleConfigurationSwapperEngine.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlDataNodeRuleConfigurationSwapperEngine.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import java.util.Collection;
import java.util.LinkedList;
@@ -44,14 +44,14 @@
/**
* Swap from YAML rule configurations to rule configurations.
*
- * @param dataNodes YAML data nodes
+ * @param repositoryTuples repository tuples
* @return rule configurations
*/
@SuppressWarnings({"unchecked", "rawtypes"})
- public Collection<RuleConfiguration> swapToRuleConfigurations(final Collection<YamlDataNode> dataNodes) {
+ public Collection<RuleConfiguration> swapToRuleConfigurations(final Collection<RepositoryTuple> repositoryTuples) {
Collection<RuleConfiguration> result = new LinkedList<>();
for (YamlDataNodeRuleConfigurationSwapper each : OrderedSPILoader.getServices(YamlDataNodeRuleConfigurationSwapper.class)) {
- each.swapToObject(dataNodes).ifPresent(optional -> result.add((RuleConfiguration) optional));
+ each.swapToObject(repositoryTuples).ifPresent(optional -> result.add((RuleConfiguration) optional));
}
return result;
}
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/datanode/YamlDataNode.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/datanode/RepositoryTuple.java
similarity index 94%
rename from infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/datanode/YamlDataNode.java
rename to infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/datanode/RepositoryTuple.java
index e3c2563..4e64cba 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/datanode/YamlDataNode.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/datanode/RepositoryTuple.java
@@ -21,11 +21,11 @@
import lombok.RequiredArgsConstructor;
/**
- * YAML data node.
+ * Repository tuple.
*/
@RequiredArgsConstructor
@Getter
-public final class YamlDataNode {
+public final class RepositoryTuple {
private final String key;
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/swapper/YamlDataNodeConfigurationSwapper.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/swapper/YamlDataNodeConfigurationSwapper.java
index 9ed5b0c..c16b694 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/swapper/YamlDataNodeConfigurationSwapper.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/yaml/swapper/YamlDataNodeConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.infra.util.yaml.swapper;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import java.util.Collection;
import java.util.Optional;
@@ -30,18 +30,18 @@
public interface YamlDataNodeConfigurationSwapper<T> {
/**
- * Swap to YAML data node.
+ * Swap to repository tuples.
*
* @param data data to be swapped
- * @return YAML data nodes
+ * @return repository tuples
*/
- Collection<YamlDataNode> swapToDataNodes(T data);
+ Collection<RepositoryTuple> swapToRepositoryTuples(T data);
/**
- * Swap from data node to object.
+ * Swap from repository tuple to object.
*
- * @param dataNodes data nodes
+ * @param repositoryTuples repository tuples
* @return swapped object
*/
- Optional<T> swapToObject(Collection<YamlDataNode> dataNodes);
+ Optional<T> swapToObject(Collection<RepositoryTuple> repositoryTuples);
}
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapper.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapper.java
index 33afdbd..1337230 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapper.java
+++ b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapper.java
@@ -25,7 +25,7 @@
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
@@ -46,8 +46,8 @@
private final YamlAlgorithmConfigurationSwapper algorithmSwapper = new YamlAlgorithmConfigurationSwapper();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final AuthorityRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final AuthorityRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlAuthorityRuleConfiguration swapToYamlConfiguration(final AuthorityRuleConfiguration data) {
@@ -60,13 +60,11 @@
}
@Override
- public Optional<AuthorityRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<AuthorityRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlAuthorityRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlAuthorityRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapperTest.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapperTest.java
index e726e30..ca38c14 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/YamlAuthorityDataNodeRuleConfigurationSwapperTest.java
@@ -20,7 +20,7 @@
import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.junit.jupiter.api.Test;
import java.util.Collection;
@@ -38,16 +38,16 @@
@Test
void assertSwapToDataNodes() {
Collection<ShardingSphereUser> users = Collections.singleton(new ShardingSphereUser("root", "", "localhost"));
- Collection<YamlDataNode> actual = swapper.swapToDataNodes(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()),
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()),
Collections.singletonMap("md5", new AlgorithmConfiguration("MD5", createProperties())), "scram_sha256"));
- YamlDataNode yamlDataNode = actual.iterator().next();
- assertThat(yamlDataNode.getKey(), is("authority"));
- assertThat(yamlDataNode.getValue(), containsString("user: root@localhost"));
- assertThat(yamlDataNode.getValue(), containsString("password: ''"));
- assertThat(yamlDataNode.getValue(), containsString("type: ALL_PERMITTED"));
- assertThat(yamlDataNode.getValue(), containsString("defaultAuthenticator: scram_sha256"));
- assertThat(yamlDataNode.getValue(), containsString("type: MD5"));
- assertThat(yamlDataNode.getValue(), containsString("proxy-frontend-database-protocol-type: openGauss"));
+ RepositoryTuple repositoryTuple = actual.iterator().next();
+ assertThat(repositoryTuple.getKey(), is("authority"));
+ assertThat(repositoryTuple.getValue(), containsString("user: root@localhost"));
+ assertThat(repositoryTuple.getValue(), containsString("password: ''"));
+ assertThat(repositoryTuple.getValue(), containsString("type: ALL_PERMITTED"));
+ assertThat(repositoryTuple.getValue(), containsString("defaultAuthenticator: scram_sha256"));
+ assertThat(repositoryTuple.getValue(), containsString("type: MD5"));
+ assertThat(repositoryTuple.getValue(), containsString("proxy-frontend-database-protocol-type: openGauss"));
}
private Properties createProperties() {
diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapper.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapper.java
index 4cb6d7f..9f55af5 100644
--- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapper.java
+++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapper.java
@@ -22,7 +22,7 @@
import org.apache.shardingsphere.globalclock.core.yaml.config.YamlGlobalClockRuleConfiguration;
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import java.util.Collection;
@@ -36,8 +36,8 @@
public final class YamlGlobalClockDataNodeRuleConfigurationSwapper implements YamlDataNodeGlobalRuleConfigurationSwapper<GlobalClockRuleConfiguration> {
@Override
- public Collection<YamlDataNode> swapToDataNodes(final GlobalClockRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final GlobalClockRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlGlobalClockRuleConfiguration swapToYamlConfiguration(final GlobalClockRuleConfiguration data) {
@@ -50,13 +50,11 @@
}
@Override
- public Optional<GlobalClockRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<GlobalClockRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlGlobalClockRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlGlobalClockRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapperTest.java b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapperTest.java
index 40898a8..84b8bad 100644
--- a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/YamlGlobalClockDataNodeRuleConfigurationSwapperTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.globalclock.core.yaml.swapper;
import org.apache.shardingsphere.globalclock.api.config.GlobalClockRuleConfiguration;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.junit.jupiter.api.Test;
import java.util.Collection;
@@ -33,7 +33,7 @@
@Test
void assertSwapToDataNodes() {
- Collection<YamlDataNode> actual = swapper.swapToDataNodes(new GlobalClockRuleConfiguration("", "", false, new Properties()));
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(new GlobalClockRuleConfiguration("", "", false, new Properties()));
assertThat(actual.iterator().next().getKey(), is("global_clock"));
}
}
diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapper.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapper.java
index dc943a6..a337a6e 100644
--- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapper.java
+++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapper.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
import org.apache.shardingsphere.logging.constant.LoggingOrder;
@@ -38,8 +38,8 @@
public final class YamlLoggingDataNodeRuleConfigurationSwapper implements YamlDataNodeGlobalRuleConfigurationSwapper<LoggingRuleConfiguration> {
@Override
- public Collection<YamlDataNode> swapToDataNodes(final LoggingRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final LoggingRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlLoggingRuleConfiguration swapToYamlConfiguration(final LoggingRuleConfiguration data) {
@@ -50,13 +50,11 @@
}
@Override
- public Optional<LoggingRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<LoggingRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlLoggingRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlLoggingRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapperTest.java b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapperTest.java
index 376ede6..f2952df 100644
--- a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingDataNodeRuleConfigurationSwapperTest.java
@@ -29,6 +29,6 @@
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new DefaultLoggingRuleConfigurationBuilder().build()).iterator().next().getKey(), is("logging"));
+ assertThat(swapper.swapToRepositoryTuples(new DefaultLoggingRuleConfigurationBuilder().build()).iterator().next().getKey(), is("logging"));
}
}
diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/AbstractPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/AbstractPersistService.java
index 39a92e7..2c34ae4 100644
--- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/AbstractPersistService.java
+++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/AbstractPersistService.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.metadata.persist.service.config;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.mode.spi.PersistRepository;
import java.util.Collection;
@@ -26,7 +26,6 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
@RequiredArgsConstructor
@@ -41,19 +40,18 @@
private final PersistRepository repository;
/**
- * Get data nodes.
+ * Get repository tuples.
*
* @param rootPath root path
- * @return yaml data nodes
+ * @return repository tuples
*/
- public Collection<YamlDataNode> getDataNodes(final String rootPath) {
- Collection<YamlDataNode> result = new LinkedList<>();
+ public Collection<RepositoryTuple> getRepositoryTuple(final String rootPath) {
+ Collection<RepositoryTuple> result = new LinkedList<>();
+ Pattern pattern = Pattern.compile(ACTIVE_VERSION_PATTERN, Pattern.CASE_INSENSITIVE);
for (String each : getNodes(rootPath)) {
- Pattern pattern = Pattern.compile(ACTIVE_VERSION_PATTERN, Pattern.CASE_INSENSITIVE);
- Matcher matcher = pattern.matcher(each);
- if (matcher.find()) {
+ if (pattern.matcher(each).find()) {
String activeRuleKey = each.replace(ACTIVE_VERSION_PATH, VERSIONS_PATH) + "/" + getActiveVersion(each);
- result.add(new YamlDataNode(activeRuleKey, repository.getDirectly(activeRuleKey)));
+ result.add(new RepositoryTuple(activeRuleKey, repository.getDirectly(activeRuleKey)));
}
}
return result;
diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java
index 93c9a29..6bc5ef3 100644
--- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java
+++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/database/rule/DatabaseRulePersistService.java
@@ -20,7 +20,7 @@
import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.metadata.persist.node.metadata.DatabaseRuleMetaDataNode;
@@ -54,18 +54,17 @@
public void persist(final String databaseName, final Collection<RuleConfiguration> configs) {
Map<RuleConfiguration, YamlDataNodeRuleConfigurationSwapper> yamlConfigs = new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs);
for (Entry<RuleConfiguration, YamlDataNodeRuleConfigurationSwapper> entry : yamlConfigs.entrySet()) {
- Collection<YamlDataNode> dataNodes = entry.getValue().swapToDataNodes(entry.getKey());
- if (dataNodes.isEmpty()) {
- continue;
+ Collection<RepositoryTuple> repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey());
+ if (!repositoryTuples.isEmpty()) {
+ persistDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), repositoryTuples);
}
- persistDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), dataNodes);
}
}
@Override
public Collection<RuleConfiguration> load(final String databaseName) {
- Collection<YamlDataNode> dataNodes = getDataNodes(DatabaseRuleMetaDataNode.getRulesNode(databaseName));
- return dataNodes.isEmpty() ? Collections.emptyList() : new YamlDataNodeRuleConfigurationSwapperEngine().swapToRuleConfigurations(dataNodes);
+ Collection<RepositoryTuple> repositoryTuple = getRepositoryTuple(DatabaseRuleMetaDataNode.getRulesNode(databaseName));
+ return repositoryTuple.isEmpty() ? Collections.emptyList() : new YamlDataNodeRuleConfigurationSwapperEngine().swapToRuleConfigurations(repositoryTuple);
}
@Override
@@ -79,18 +78,17 @@
Collection<MetaDataVersion> result = new LinkedList<>();
Map<RuleConfiguration, YamlDataNodeRuleConfigurationSwapper> yamlConfigs = new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs);
for (Entry<RuleConfiguration, YamlDataNodeRuleConfigurationSwapper> entry : yamlConfigs.entrySet()) {
- Collection<YamlDataNode> dataNodes = entry.getValue().swapToDataNodes(entry.getKey());
- if (dataNodes.isEmpty()) {
- continue;
+ Collection<RepositoryTuple> repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey());
+ if (!repositoryTuples.isEmpty()) {
+ result.addAll(persistDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), repositoryTuples));
}
- result.addAll(persistDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), dataNodes));
}
return result;
}
- private Collection<MetaDataVersion> persistDataNodes(final String databaseName, final String ruleName, final Collection<YamlDataNode> dataNodes) {
+ private Collection<MetaDataVersion> persistDataNodes(final String databaseName, final String ruleName, final Collection<RepositoryTuple> repositoryTuples) {
Collection<MetaDataVersion> result = new LinkedList<>();
- for (YamlDataNode each : dataNodes) {
+ for (RepositoryTuple each : repositoryTuples) {
List<String> versions = repository.getChildrenKeys(DatabaseRuleMetaDataNode.getDatabaseRuleVersionsNode(databaseName, ruleName, each.getKey()));
String nextVersion = versions.isEmpty() ? DEFAULT_VERSION : String.valueOf(Integer.parseInt(versions.get(0)) + 1);
repository.persist(DatabaseRuleMetaDataNode.getDatabaseRuleVersionNode(databaseName, ruleName, each.getKey(), nextVersion), each.getValue());
@@ -108,20 +106,20 @@
Collection<MetaDataVersion> result = new LinkedList<>();
Map<RuleConfiguration, YamlDataNodeRuleConfigurationSwapper> yamlConfigs = new YamlDataNodeRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs);
for (Entry<RuleConfiguration, YamlDataNodeRuleConfigurationSwapper> entry : yamlConfigs.entrySet()) {
- Collection<YamlDataNode> dataNodes = entry.getValue().swapToDataNodes(entry.getKey());
- if (dataNodes.isEmpty()) {
+ Collection<RepositoryTuple> repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey());
+ if (repositoryTuples.isEmpty()) {
continue;
}
- List<YamlDataNode> newDataNodes = new LinkedList<>(dataNodes);
- Collections.reverse(newDataNodes);
- result.addAll(deleteDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), newDataNodes));
+ List<RepositoryTuple> newRepositoryTuples = new LinkedList<>(repositoryTuples);
+ Collections.reverse(newRepositoryTuples);
+ result.addAll(deleteDataNodes(databaseName, entry.getValue().getRuleTagName().toLowerCase(), newRepositoryTuples));
}
return result;
}
- private Collection<MetaDataVersion> deleteDataNodes(final String databaseName, final String ruleName, final Collection<YamlDataNode> dataNodes) {
+ private Collection<MetaDataVersion> deleteDataNodes(final String databaseName, final String ruleName, final Collection<RepositoryTuple> repositoryTuples) {
Collection<MetaDataVersion> result = new LinkedList<>();
- for (YamlDataNode each : dataNodes) {
+ for (RepositoryTuple each : repositoryTuples) {
String delKey = DatabaseRuleMetaDataNode.getDatabaseRuleNode(databaseName, ruleName, each.getKey());
repository.delete(delKey);
result.add(new MetaDataVersion(delKey));
diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java
index cd69b80..3f98350 100644
--- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java
+++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalRulePersistService.java
@@ -20,7 +20,7 @@
import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.metadata.persist.node.GlobalNode;
@@ -53,11 +53,10 @@
public void persist(final Collection<RuleConfiguration> globalRuleConfigs) {
Map<RuleConfiguration, YamlDataNodeGlobalRuleConfigurationSwapper> yamlConfigs = new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(globalRuleConfigs);
for (Entry<RuleConfiguration, YamlDataNodeGlobalRuleConfigurationSwapper> entry : yamlConfigs.entrySet()) {
- Collection<YamlDataNode> dataNodes = entry.getValue().swapToDataNodes(entry.getKey());
- if (dataNodes.isEmpty()) {
- continue;
+ Collection<RepositoryTuple> repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey());
+ if (!repositoryTuples.isEmpty()) {
+ persistDataNodes(repositoryTuples);
}
- persistDataNodes(dataNodes);
}
}
@@ -67,18 +66,17 @@
Collection<MetaDataVersion> result = new LinkedList<>();
Map<RuleConfiguration, YamlDataNodeGlobalRuleConfigurationSwapper> yamlConfigs = new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(globalRuleConfigs);
for (Entry<RuleConfiguration, YamlDataNodeGlobalRuleConfigurationSwapper> entry : yamlConfigs.entrySet()) {
- Collection<YamlDataNode> dataNodes = entry.getValue().swapToDataNodes(entry.getKey());
- if (dataNodes.isEmpty()) {
- continue;
+ Collection<RepositoryTuple> repositoryTuples = entry.getValue().swapToRepositoryTuples(entry.getKey());
+ if (!repositoryTuples.isEmpty()) {
+ result.addAll(persistDataNodes(repositoryTuples));
}
- result.addAll(persistDataNodes(dataNodes));
}
return result;
}
- private Collection<MetaDataVersion> persistDataNodes(final Collection<YamlDataNode> dataNodes) {
+ private Collection<MetaDataVersion> persistDataNodes(final Collection<RepositoryTuple> repositoryTuples) {
Collection<MetaDataVersion> result = new LinkedList<>();
- for (YamlDataNode each : dataNodes) {
+ for (RepositoryTuple each : repositoryTuples) {
List<String> versions = repository.getChildrenKeys(GlobalNode.getGlobalRuleVersionsNode(each.getKey()));
String nextActiveVersion = versions.isEmpty() ? DEFAULT_VERSION : String.valueOf(Integer.parseInt(versions.get(0)) + 1);
String persistKey = GlobalNode.getGlobalRuleVersionNode(each.getKey(), nextActiveVersion);
@@ -93,13 +91,13 @@
@Override
public Collection<RuleConfiguration> load() {
- Collection<YamlDataNode> dataNodes = getDataNodes(GlobalNode.getGlobalRuleRootNode());
- return dataNodes.isEmpty() ? Collections.emptyList() : new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToRuleConfigurations(dataNodes);
+ Collection<RepositoryTuple> repositoryTuple = getRepositoryTuple(GlobalNode.getGlobalRuleRootNode());
+ return repositoryTuple.isEmpty() ? Collections.emptyList() : new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapToRuleConfigurations(repositoryTuple);
}
@Override
public RuleConfiguration load(final String ruleName) {
- Collection<YamlDataNode> dataNodes = getDataNodes(GlobalNode.getGlobalRuleNode(ruleName));
- return new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapSingleRuleToRuleConfiguration(ruleName, dataNodes).orElse(null);
+ Collection<RepositoryTuple> repositoryTuple = getRepositoryTuple(GlobalNode.getGlobalRuleNode(ruleName));
+ return new YamlDataNodeGlobalRuleConfigurationSwapperEngine().swapSingleRuleToRuleConfiguration(ruleName, repositoryTuple).orElse(null);
}
}
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapper.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapper.java
index 6c9acf3..a110ad6 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapper.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapper.java
@@ -17,10 +17,10 @@
package org.apache.shardingsphere.single.yaml.config.swapper;
-import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeRuleConfigurationSwapper;
+import org.apache.shardingsphere.mode.path.RuleNodePath;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.constant.SingleOrder;
import org.apache.shardingsphere.single.metadata.nodepath.SingleRuleNodePathProvider;
@@ -28,7 +28,6 @@
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -40,8 +39,8 @@
private final RuleNodePath singleRuleNodePath = new SingleRuleNodePathProvider().getRuleNodePath();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final SingleRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(SingleRuleNodePathProvider.TABLES, YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final SingleRuleConfiguration data) {
+ return Collections.singletonList(new RepositoryTuple(SingleRuleNodePathProvider.TABLES, YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlSingleRuleConfiguration swapToYamlConfiguration(final SingleRuleConfiguration data) {
@@ -52,9 +51,8 @@
}
@Override
- public Optional<SingleRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- List<YamlDataNode> validDataNodes = dataNodes.stream().filter(each -> singleRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
- for (YamlDataNode each : validDataNodes) {
+ public Optional<SingleRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples.stream().filter(each -> singleRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList())) {
if (singleRuleNodePath.getUniqueItem(SingleRuleNodePathProvider.TABLES).isValidatedPath(each.getKey())) {
return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSingleRuleConfiguration.class)));
}
diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapperTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapperTest.java
index ea518b7..5de9216 100644
--- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleDataNodeRuleConfigurationSwapperTest.java
@@ -29,6 +29,6 @@
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new SingleRuleConfiguration()).iterator().next().getKey(), is("tables"));
+ assertThat(swapper.swapToRepositoryTuples(new SingleRuleConfiguration()).iterator().next().getKey(), is("tables"));
}
}
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapper.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapper.java
index 4ac7ccf..3fdaff6 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapper.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapper.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration;
@@ -38,8 +38,8 @@
private final YamlSQLFederationExecutionPlanCacheConfigurationSwapper executionPlanCacheConfigSwapper = new YamlSQLFederationExecutionPlanCacheConfigurationSwapper();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final SQLFederationRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final SQLFederationRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlSQLFederationRuleConfiguration swapToYamlConfiguration(final SQLFederationRuleConfiguration data) {
@@ -51,13 +51,11 @@
}
@Override
- public Optional<SQLFederationRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<SQLFederationRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSQLFederationRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSQLFederationRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapperTest.java b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapperTest.java
index 31beae7..ae605c8 100644
--- a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/YamlSQLFederationDataNodeRuleConfigurationSwapperTest.java
@@ -30,6 +30,6 @@
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new SQLFederationRuleConfiguration(false, false, new CacheOption(0, 0))).iterator().next().getKey(), is("sql_federation"));
+ assertThat(swapper.swapToRepositoryTuples(new SQLFederationRuleConfiguration(false, false, new CacheOption(0, 0))).iterator().next().getKey(), is("sql_federation"));
}
}
diff --git a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapper.java b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapper.java
index f06c302..b0faec9 100644
--- a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapper.java
+++ b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapper.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
import org.apache.shardingsphere.parser.constant.SQLParserOrder;
@@ -39,8 +39,8 @@
private final YamlSQLParserCacheOptionConfigurationSwapper cacheOptionSwapper = new YamlSQLParserCacheOptionConfigurationSwapper();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final SQLParserRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final SQLParserRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlSQLParserRuleConfiguration swapToYamlConfiguration(final SQLParserRuleConfiguration data) {
@@ -51,13 +51,11 @@
}
@Override
- public Optional<SQLParserRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<SQLParserRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSQLParserRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSQLParserRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapperTest.java b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapperTest.java
index e40f2d0..c540c68 100644
--- a/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserDataNodeRuleConfigurationSwapperTest.java
@@ -30,7 +30,7 @@
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new SQLParserRuleConfiguration(DefaultSQLParserRuleConfigurationBuilder.PARSE_TREE_CACHE_OPTION,
+ assertThat(swapper.swapToRepositoryTuples(new SQLParserRuleConfiguration(DefaultSQLParserRuleConfigurationBuilder.PARSE_TREE_CACHE_OPTION,
DefaultSQLParserRuleConfigurationBuilder.SQL_STATEMENT_CACHE_OPTION)).iterator().next().getKey(), is("sql_parser"));
}
}
diff --git a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapper.java b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapper.java
index 19b8e36..e107bc0 100644
--- a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapper.java
+++ b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapper.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
import org.apache.shardingsphere.sqltranslator.constant.SQLTranslatorOrder;
@@ -35,8 +35,8 @@
public final class YamlSQLTranslatorDataNodeRuleConfigurationSwapper implements YamlDataNodeGlobalRuleConfigurationSwapper<SQLTranslatorRuleConfiguration> {
@Override
- public Collection<YamlDataNode> swapToDataNodes(final SQLTranslatorRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final SQLTranslatorRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlSQLTranslatorRuleConfiguration swapToYamlConfiguration(final SQLTranslatorRuleConfiguration data) {
@@ -48,13 +48,11 @@
}
@Override
- public Optional<SQLTranslatorRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<SQLTranslatorRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSQLTranslatorRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSQLTranslatorRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapperTest.java b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapperTest.java
index b4592aa..850211b 100644
--- a/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/YamlSQLTranslatorDataNodeRuleConfigurationSwapperTest.java
@@ -29,6 +29,6 @@
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new DefaultSQLTranslatorRuleConfigurationBuilder().build()).iterator().next().getKey(), is("sql_translator"));
+ assertThat(swapper.swapToRepositoryTuples(new DefaultSQLTranslatorRuleConfigurationBuilder().build()).iterator().next().getKey(), is("sql_translator"));
}
}
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapper.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapper.java
index 2f83877..8156072 100644
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapper.java
+++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapper.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.algorithm.core.yaml.YamlAlgorithmConfigurationSwapper;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
@@ -42,8 +42,8 @@
private final YamlAlgorithmConfigurationSwapper algorithmSwapper = new YamlAlgorithmConfigurationSwapper();
@Override
- public Collection<YamlDataNode> swapToDataNodes(final TrafficRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final TrafficRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlTrafficRuleConfiguration swapToYamlConfiguration(final TrafficRuleConfiguration data) {
@@ -63,13 +63,11 @@
}
@Override
- public Optional<TrafficRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<TrafficRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlTrafficRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlTrafficRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapperTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapperTest.java
index 8914ce2..3eca9dc 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/YamlTrafficDataNodeRuleConfigurationSwapperTest.java
@@ -29,6 +29,6 @@
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("traffic"));
+ assertThat(swapper.swapToRepositoryTuples(new TrafficRuleConfiguration()).iterator().next().getKey(), is("traffic"));
}
}
diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapper.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapper.java
index 2bd7b42..92c6193 100644
--- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapper.java
+++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapper.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.infra.config.nodepath.GlobalNodePath;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlDataNodeGlobalRuleConfigurationSwapper;
import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
import org.apache.shardingsphere.transaction.constant.TransactionOrder;
@@ -36,8 +36,8 @@
public final class YamlTransactionDataNodeRuleConfigurationSwapper implements YamlDataNodeGlobalRuleConfigurationSwapper<TransactionRuleConfiguration> {
@Override
- public Collection<YamlDataNode> swapToDataNodes(final TransactionRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ public Collection<RepositoryTuple> swapToRepositoryTuples(final TransactionRuleConfiguration data) {
+ return Collections.singleton(new RepositoryTuple(getRuleTagName().toLowerCase(), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlTransactionRuleConfiguration swapToYamlConfiguration(final TransactionRuleConfiguration data) {
@@ -49,13 +49,11 @@
}
@Override
- public Optional<TransactionRuleConfiguration> swapToObject(final Collection<YamlDataNode> dataNodes) {
- for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey());
- if (!version.isPresent()) {
- continue;
+ public Optional<TransactionRuleConfiguration> swapToObject(final Collection<RepositoryTuple> repositoryTuples) {
+ for (RepositoryTuple each : repositoryTuples) {
+ if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), each.getKey()).isPresent()) {
+ return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlTransactionRuleConfiguration.class)));
}
- return Optional.of(swapToObject(YamlEngine.unmarshal(each.getValue(), YamlTransactionRuleConfiguration.class)));
}
return Optional.empty();
}
diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapperTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapperTest.java
index fa180a5..700cb15 100644
--- a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapperTest.java
+++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/yaml/swapper/YamlTransactionDataNodeRuleConfigurationSwapperTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.transaction.yaml.swapper;
-import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
import org.junit.jupiter.api.Test;
@@ -33,7 +33,7 @@
@Test
void assertSwapToDataNodes() {
- Collection<YamlDataNode> actual = swapper.swapToDataNodes(new TransactionRuleConfiguration("", "", new Properties()));
+ Collection<RepositoryTuple> actual = swapper.swapToRepositoryTuples(new TransactionRuleConfiguration("", "", new Properties()));
assertThat(actual.iterator().next().getKey(), is("transaction"));
}
}