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 ca2204e404e Remove GlobalRuleNodePathParser (#34764)
ca2204e404e is described below
commit ca2204e404e36e781cb860ed2760775c9d9e7a87
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Feb 23 20:16:47 2025 +0800
Remove GlobalRuleNodePathParser (#34764)
---
.../config/global/GlobalRuleNodePathParser.java | 52 ----------------------
.../tuple/YamlRepositoryTupleSwapperEngine.java | 5 ++-
.../global/GlobalRuleNodePathParserTest.java | 41 -----------------
.../path/config/global/GlobalRuleNodePathTest.java | 10 +++++
.../global/type/GlobalRuleChangedHandler.java | 5 ++-
5 files changed, 16 insertions(+), 97 deletions(-)
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
deleted file mode 100644
index b83231746ba..00000000000
---
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParser.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mode.node.path.config.global;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
-import org.apache.shardingsphere.mode.node.path.NodePathPattern;
-import org.apache.shardingsphere.mode.node.path.version.VersionNodePathParser;
-
-/**
- * Global props node path parser.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class GlobalRuleNodePathParser {
-
- private static final VersionNodePathParser PARSER = new
VersionNodePathParser(NodePathGenerator.toPath(new
GlobalRuleNodePath(NodePathPattern.IDENTIFIER), false));
-
- /**
- * Get global rule version node path parser.
- *
- * @return global rule version node path parser
- */
- public static VersionNodePathParser getVersion() {
- return PARSER;
- }
-
- /**
- * Get global rule version node path parser.
- *
- * @param ruleType rule type
- * @return global rule version node path parser
- */
- 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 98f1870a70d..6c99f2cc20a 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
@@ -29,8 +29,9 @@ import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlGlobalRuleConfi
import
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.mode.node.path.NodePathSearcher;
import
org.apache.shardingsphere.mode.node.path.config.database.DatabaseRuleNodePath;
-import
org.apache.shardingsphere.mode.node.path.config.global.GlobalRuleNodePathParser;
+import
org.apache.shardingsphere.mode.node.path.config.global.GlobalRuleNodePath;
import org.apache.shardingsphere.mode.node.spi.DatabaseRuleNodePathProvider;
import
org.apache.shardingsphere.mode.node.tuple.annotation.RepositoryTupleEntity;
import
org.apache.shardingsphere.mode.node.tuple.annotation.RepositoryTupleField;
@@ -155,7 +156,7 @@ public final class YamlRepositoryTupleSwapperEngine {
final
Class<? extends YamlRuleConfiguration> toBeSwappedType, final
RepositoryTupleEntity tupleEntity) {
if
(YamlGlobalRuleConfiguration.class.isAssignableFrom(toBeSwappedType)) {
for (RepositoryTuple each : repositoryTuples) {
- if
(GlobalRuleNodePathParser.getVersion(tupleEntity.value()).isVersionPath(each.getKey()))
{
+ if (NodePathSearcher.getVersion(new
GlobalRuleNodePath(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/GlobalRuleNodePathParserTest.java
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParserTest.java
deleted file mode 100644
index e4b8f95ecf0..00000000000
---
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathParserTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.mode.node.path.config.global;
-
-import org.junit.jupiter.api.Test;
-
-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 GlobalRuleNodePathParserTest {
-
- @Test
- 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 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/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathTest.java
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathTest.java
index 62c2396257f..10c59fad29f 100644
---
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathTest.java
+++
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/global/GlobalRuleNodePathTest.java
@@ -18,10 +18,13 @@
package org.apache.shardingsphere.mode.node.path.config.global;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
+import org.apache.shardingsphere.mode.node.path.NodePathSearcher;
+import org.apache.shardingsphere.mode.node.path.version.VersionNodePathParser;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class GlobalRuleNodePathTest {
@@ -30,4 +33,11 @@ class GlobalRuleNodePathTest {
assertThat(NodePathGenerator.toPath(new GlobalRuleNodePath(null),
false), is("/rules"));
assertThat(NodePathGenerator.toPath(new
GlobalRuleNodePath("foo_rule"), false), is("/rules/foo_rule"));
}
+
+ @Test
+ void assertGetVersion() {
+ VersionNodePathParser versionNodePathParser =
NodePathSearcher.getVersion(new GlobalRuleNodePath("foo_rule"));
+
assertTrue(versionNodePathParser.isActiveVersionPath("/rules/foo_rule/active_version"));
+
assertTrue(versionNodePathParser.isVersionPath("/rules/foo_rule/versions/0"));
+ }
}
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 c077830ce74..01756871890 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
@@ -25,8 +25,9 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.mode.manager.cluster.dispatch.checker.ActiveVersionChecker;
import
org.apache.shardingsphere.mode.manager.cluster.dispatch.handler.global.GlobalDataChangedEventHandler;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
+import org.apache.shardingsphere.mode.node.path.NodePathPattern;
+import org.apache.shardingsphere.mode.node.path.NodePathSearcher;
import
org.apache.shardingsphere.mode.node.path.config.global.GlobalRuleNodePath;
-import
org.apache.shardingsphere.mode.node.path.config.global.GlobalRuleNodePathParser;
import java.util.Arrays;
import java.util.Collection;
@@ -49,7 +50,7 @@ public final class GlobalRuleChangedHandler implements
GlobalDataChangedEventHan
@Override
public void handle(final ContextManager contextManager, final
DataChangedEvent event) {
- Optional<String> ruleType =
GlobalRuleNodePathParser.getVersion().findIdentifierByActiveVersionPath(event.getKey(),
1);
+ Optional<String> ruleType = NodePathSearcher.getVersion(new
GlobalRuleNodePath(NodePathPattern.IDENTIFIER)).findIdentifierByActiveVersionPath(event.getKey(),
1);
if (!ruleType.isPresent()) {
return;
}