This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 14967bb7a0c Refactor GlobalPropertiesNodePath and GlobalRuleNodePath
(#34690)
14967bb7a0c is described below
commit 14967bb7a0c013d5ae31cf10e22711a7033fc57c
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Feb 16 02:44:35 2025 +0800
Refactor GlobalPropertiesNodePath and GlobalRuleNodePath (#34690)
* Refactor GlobalPropertiesNodePath and GlobalRuleNodePath
* Refactor GlobalPropertiesNodePath and GlobalRuleNodePath
---
.../persist/config/global/GlobalRulePersistService.java | 2 +-
.../persist/config/global/PropertiesPersistService.java | 6 +++---
.../config/global/GlobalPropertiesNodePathGenerator.java | 5 +----
.../path/config/global/GlobalPropertiesNodePathParser.java | 6 +++---
.../path/config/global/GlobalRuleNodePathGenerator.java | 2 +-
.../node/path/config/global/GlobalRuleNodePathParser.java | 12 ++++++------
.../mode/node/tuple/YamlRepositoryTupleSwapperEngine.java | 2 +-
.../global/GlobalPropertiesNodePathGeneratorTest.java | 8 ++++----
.../config/global/GlobalRuleNodePathGeneratorTest.java | 8 ++++----
.../path/config/global/GlobalRuleNodePathParserTest.java | 14 +++++++-------
.../handler/global/type/GlobalRuleChangedHandler.java | 2 +-
.../handler/global/type/PropertiesChangedHandler.java | 2 +-
12 files changed, 33 insertions(+), 36 deletions(-)
diff --git
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/GlobalRulePersistService.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/GlobalRulePersistService.java
index fdb7e78b804..4f47ac6aff8 100644
---
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/GlobalRulePersistService.java
+++
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/GlobalRulePersistService.java
@@ -83,7 +83,7 @@ public final class GlobalRulePersistService {
private void persistTuples(final Collection<RepositoryTuple> tuples) {
for (RepositoryTuple each : tuples) {
- VersionNodePathGenerator versionNodePathGenerator =
GlobalRuleNodePathGenerator.getVersionNodePathGenerator(each.getKey());
+ VersionNodePathGenerator versionNodePathGenerator =
GlobalRuleNodePathGenerator.getVersion(each.getKey());
metaDataVersionPersistService.persist(versionNodePathGenerator,
each.getValue());
}
}
diff --git
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java
index 835b66064f4..681148ce76f 100644
---
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java
+++
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/config/global/PropertiesPersistService.java
@@ -45,12 +45,12 @@ public final class PropertiesPersistService {
*/
public Properties load() {
return loadActiveVersion()
- .map(optional ->
YamlEngine.unmarshal(repository.query(GlobalPropertiesNodePathGenerator.getVersionNodePathGenerator().getVersionPath(optional)),
Properties.class))
+ .map(optional ->
YamlEngine.unmarshal(repository.query(GlobalPropertiesNodePathGenerator.getVersion().getVersionPath(optional)),
Properties.class))
.orElse(new Properties());
}
private Optional<Integer> loadActiveVersion() {
- String value =
repository.query(GlobalPropertiesNodePathGenerator.getVersionNodePathGenerator().getActiveVersionPath());
+ String value =
repository.query(GlobalPropertiesNodePathGenerator.getVersion().getActiveVersionPath());
return Strings.isNullOrEmpty(value) ? Optional.empty() :
Optional.of(Integer.parseInt(value));
}
@@ -60,7 +60,7 @@ public final class PropertiesPersistService {
* @param props properties
*/
public void persist(final Properties props) {
- VersionNodePathGenerator versionNodePathGenerator =
GlobalPropertiesNodePathGenerator.getVersionNodePathGenerator();
+ VersionNodePathGenerator versionNodePathGenerator =
GlobalPropertiesNodePathGenerator.getVersion();
metaDataVersionPersistService.persist(versionNodePathGenerator,
YamlEngine.marshal(props));
}
}
diff --git
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGenerator.java
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGenerator.java
index 861f2b7ce1c..7f2b35a31ec 100644
---
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGenerator.java
+++
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGenerator.java
@@ -20,7 +20,6 @@ package
org.apache.shardingsphere.mode.node.path.config.global;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator;
-import org.apache.shardingsphere.mode.node.path.version.VersionNodePathParser;
/**
* Global properties node path generator.
@@ -30,8 +29,6 @@ public final class GlobalPropertiesNodePathGenerator {
private static final String ROOT_NODE = "/props";
- private static final VersionNodePathParser PARSER = new
VersionNodePathParser(getRootPath());
-
/**
* Get properties path.
*
@@ -46,7 +43,7 @@ public final class GlobalPropertiesNodePathGenerator {
*
* @return properties version node path generator
*/
- public static VersionNodePathGenerator getVersionNodePathGenerator() {
+ public static VersionNodePathGenerator getVersion() {
return new VersionNodePathGenerator(getRootPath());
}
}
diff --git
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathParser.java
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathParser.java
index 46cd0d340a6..5cecfabbad4 100644
---
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathParser.java
+++
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathParser.java
@@ -27,14 +27,14 @@ import
org.apache.shardingsphere.mode.node.path.version.VersionNodePathParser;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class GlobalPropertiesNodePathParser {
- private static final VersionNodePathParser PARSER = new
VersionNodePathParser(GlobalPropertiesNodePathGenerator.getRootPath());
+ private static final VersionNodePathParser VERSION_PARSER = new
VersionNodePathParser(GlobalPropertiesNodePathGenerator.getRootPath());
/**
* Get properties version node path parser.
*
* @return properties version node path parser
*/
- public static VersionNodePathParser getVersionNodePathParser() {
- return PARSER;
+ public static VersionNodePathParser getVersion() {
+ return VERSION_PARSER;
}
}
diff --git
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGenerator.java
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGenerator.java
index a48bb491191..172fe3482cf 100644
---
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGenerator.java
+++
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGenerator.java
@@ -54,7 +54,7 @@ public final class GlobalRuleNodePathGenerator {
* @param ruleType rule type
* @return global rule version node path generator
*/
- public static VersionNodePathGenerator getVersionNodePathGenerator(final
String ruleType) {
+ public static VersionNodePathGenerator getVersion(final String ruleType) {
return new VersionNodePathGenerator(getRulePath(ruleType));
}
}
diff --git
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParser.java
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParser.java
index ac3590ea792..b20948e3404 100644
---
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParser.java
+++
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParser.java
@@ -31,21 +31,21 @@ public final class GlobalRuleNodePathParser {
private static final VersionNodePathParser PARSER = new
VersionNodePathParser(GlobalRuleNodePathGenerator.getRootPath() + "/" +
NodePathPattern.IDENTIFIER);
/**
- * Get view version pattern node path parser.
+ * Get global rule version node path parser.
*
- * @return view version node path parser
+ * @return global rule version node path parser
*/
- public static VersionNodePathParser getVersionNodePathParser() {
+ public static VersionNodePathParser getVersion() {
return PARSER;
}
/**
- * Get rule version node path parser.
+ * Get global rule version node path parser.
*
* @param ruleType rule type
- * @return rule version node path parser
+ * @return global rule version node path parser
*/
- public static VersionNodePathParser getRuleVersionNodePathParser(final
String ruleType) {
+ public static VersionNodePathParser getVersion(final String ruleType) {
return new VersionNodePathParser(ruleType);
}
}
diff --git
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/tuple/YamlRepositoryTupleSwapperEngine.java
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/tuple/YamlRepositoryTupleSwapperEngine.java
index 1469633395b..98f1870a70d 100644
---
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/tuple/YamlRepositoryTupleSwapperEngine.java
+++
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/tuple/YamlRepositoryTupleSwapperEngine.java
@@ -155,7 +155,7 @@ public final class YamlRepositoryTupleSwapperEngine {
final
Class<? extends YamlRuleConfiguration> toBeSwappedType, final
RepositoryTupleEntity tupleEntity) {
if
(YamlGlobalRuleConfiguration.class.isAssignableFrom(toBeSwappedType)) {
for (RepositoryTuple each : repositoryTuples) {
- if
(GlobalRuleNodePathParser.getRuleVersionNodePathParser(tupleEntity.value()).isVersionPath(each.getKey()))
{
+ if
(GlobalRuleNodePathParser.getVersion(tupleEntity.value()).isVersionPath(each.getKey()))
{
return Optional.of(YamlEngine.unmarshal(each.getValue(),
toBeSwappedType));
}
}
diff --git
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGeneratorTest.java
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGeneratorTest.java
index 290671c5402..a1d28a89da1 100644
---
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGeneratorTest.java
+++
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalPropertiesNodePathGeneratorTest.java
@@ -30,9 +30,9 @@ class GlobalPropertiesNodePathGeneratorTest {
}
@Test
- void assertGetVersionNodePathGenerator() {
-
assertThat(GlobalPropertiesNodePathGenerator.getVersionNodePathGenerator().getActiveVersionPath(),
is("/props/active_version"));
-
assertThat(GlobalPropertiesNodePathGenerator.getVersionNodePathGenerator().getVersionsPath(),
is("/props/versions"));
-
assertThat(GlobalPropertiesNodePathGenerator.getVersionNodePathGenerator().getVersionPath(0),
is("/props/versions/0"));
+ void assertGetVersion() {
+
assertThat(GlobalPropertiesNodePathGenerator.getVersion().getActiveVersionPath(),
is("/props/active_version"));
+
assertThat(GlobalPropertiesNodePathGenerator.getVersion().getVersionsPath(),
is("/props/versions"));
+
assertThat(GlobalPropertiesNodePathGenerator.getVersion().getVersionPath(0),
is("/props/versions/0"));
}
}
diff --git
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGeneratorTest.java
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGeneratorTest.java
index 9473f9dbada..6bac708b560 100644
---
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGeneratorTest.java
+++
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathGeneratorTest.java
@@ -35,9 +35,9 @@ class GlobalRuleNodePathGeneratorTest {
}
@Test
- void assertGetVersionNodePathGenerator() {
-
assertThat(GlobalRuleNodePathGenerator.getVersionNodePathGenerator("foo_rule").getActiveVersionPath(),
is("/rules/foo_rule/active_version"));
-
assertThat(GlobalRuleNodePathGenerator.getVersionNodePathGenerator("foo_rule").getVersionsPath(),
is("/rules/foo_rule/versions"));
-
assertThat(GlobalRuleNodePathGenerator.getVersionNodePathGenerator("foo_rule").getVersionPath(0),
is("/rules/foo_rule/versions/0"));
+ void assertGetVersion() {
+
assertThat(GlobalRuleNodePathGenerator.getVersion("foo_rule").getActiveVersionPath(),
is("/rules/foo_rule/active_version"));
+
assertThat(GlobalRuleNodePathGenerator.getVersion("foo_rule").getVersionsPath(),
is("/rules/foo_rule/versions"));
+
assertThat(GlobalRuleNodePathGenerator.getVersion("foo_rule").getVersionPath(0),
is("/rules/foo_rule/versions/0"));
}
}
diff --git
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParserTest.java
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParserTest.java
index 0bdc04e8127..e4b8f95ecf0 100644
---
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParserTest.java
+++
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParserTest.java
@@ -27,15 +27,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class GlobalRuleNodePathParserTest {
@Test
- void assertGetVersionNodePathParser() {
-
assertTrue(GlobalRuleNodePathParser.getVersionNodePathParser().findIdentifierByActiveVersionPath("/rules/foo_rule/active_version",
1).isPresent());
-
assertThat(GlobalRuleNodePathParser.getVersionNodePathParser().findIdentifierByActiveVersionPath("/rules/foo_rule/active_version",
1).get(), is("foo_rule"));
-
assertFalse(GlobalRuleNodePathParser.getVersionNodePathParser().findIdentifierByActiveVersionPath("/rules/foo_rule/versions",
1).isPresent());
+ void assertGetVersion() {
+
assertTrue(GlobalRuleNodePathParser.getVersion().findIdentifierByActiveVersionPath("/rules/foo_rule/active_version",
1).isPresent());
+
assertThat(GlobalRuleNodePathParser.getVersion().findIdentifierByActiveVersionPath("/rules/foo_rule/active_version",
1).get(), is("foo_rule"));
+
assertFalse(GlobalRuleNodePathParser.getVersion().findIdentifierByActiveVersionPath("/rules/foo_rule/versions",
1).isPresent());
}
@Test
- void assertGetRuleVersionNodePathParser() {
-
assertTrue(GlobalRuleNodePathParser.getRuleVersionNodePathParser("foo_rule").isVersionPath("/rules/foo_rule/versions/0"));
-
assertFalse(GlobalRuleNodePathParser.getRuleVersionNodePathParser("foo_rule").isVersionPath("/rules/foo_rule/active_version"));
+ void assertGetVersionWithRule() {
+
assertTrue(GlobalRuleNodePathParser.getVersion("foo_rule").isVersionPath("/rules/foo_rule/versions/0"));
+
assertFalse(GlobalRuleNodePathParser.getVersion("foo_rule").isVersionPath("/rules/foo_rule/active_version"));
}
}
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/GlobalRuleChangedHandler.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/GlobalRuleChangedHandler.java
index 3240e68adb0..330aa5d6857 100644
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/GlobalRuleChangedHandler.java
+++
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/GlobalRuleChangedHandler.java
@@ -48,7 +48,7 @@ public final class GlobalRuleChangedHandler implements
GlobalDataChangedEventHan
@Override
public void handle(final ContextManager contextManager, final
DataChangedEvent event) {
- Optional<String> ruleType =
GlobalRuleNodePathParser.getVersionNodePathParser().findIdentifierByActiveVersionPath(event.getKey(),
1);
+ Optional<String> ruleType =
GlobalRuleNodePathParser.getVersion().findIdentifierByActiveVersionPath(event.getKey(),
1);
if (!ruleType.isPresent()) {
return;
}
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/PropertiesChangedHandler.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/PropertiesChangedHandler.java
index bcdeae01ed3..6eee39b901d 100644
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/PropertiesChangedHandler.java
+++
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/type/PropertiesChangedHandler.java
@@ -45,7 +45,7 @@ public final class PropertiesChangedHandler implements
GlobalDataChangedEventHan
@Override
public void handle(final ContextManager contextManager, final
DataChangedEvent event) {
- if
(!GlobalPropertiesNodePathParser.getVersionNodePathParser().isActiveVersionPath(event.getKey()))
{
+ if
(!GlobalPropertiesNodePathParser.getVersion().isActiveVersionPath(event.getKey()))
{
return;
}
ActiveVersionChecker.checkActiveVersion(contextManager, event);