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 e50aaed934a Remove NodePathPattern.IDENTIFIER (#34671)
e50aaed934a is described below

commit e50aaed934ad3a7e9edf1c72df9ff449adfd51cc
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Fri Feb 14 22:04:18 2025 +0800

    Remove NodePathPattern.IDENTIFIER (#34671)
    
    * Remove NodePathPattern.IDENTIFIER
    
    * Remove NodePathPattern.IDENTIFIER
---
 .../metadata/changed/executor/type/RuleItemAlteredBuildExecutor.java | 2 +-
 .../org/apache/shardingsphere/mode/node/path/NodePathPattern.java    | 5 -----
 .../path/config/database/item/NamedDatabaseRuleItemNodePath.java     | 4 ++--
 .../node/path/config/database/root/DatabaseRuleRootNodePath.java     | 2 +-
 .../mode/node/tuple/YamlRepositoryTupleSwapperEngine.java            | 4 ++--
 .../node/path/config/database/root/DatabaseRuleRootNodePathTest.java | 2 +-
 6 files changed, 7 insertions(+), 12 deletions(-)

diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/changed/executor/type/RuleItemAlteredBuildExecutor.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/changed/executor/type/RuleItemAlteredBuildExecutor.java
index 870cd857629..2dbd5e712ff 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/changed/executor/type/RuleItemAlteredBuildExecutor.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/changed/executor/type/RuleItemAlteredBuildExecutor.java
@@ -36,7 +36,7 @@ public final class RuleItemAlteredBuildExecutor implements 
RuleItemChangedBuildE
     @Override
     public Optional<AlterRuleItem> build(final DatabaseRuleNodePath 
databaseRuleNodePath, final String databaseName, final String path, final 
Integer activeVersion) {
         for (Entry<String, NamedDatabaseRuleItemNodePath> entry : 
databaseRuleNodePath.getNamedItems().entrySet()) {
-            Optional<String> itemName = 
entry.getValue().getVersionNodePathParser().findIdentifierByActiveVersionPath(path,
 1);
+            Optional<String> itemName = 
entry.getValue().getVersionNodePathParser().findIdentifierByActiveVersionPath(path,
 2);
             if (itemName.isPresent()) {
                 return Optional.of(new AlterNamedRuleItem(databaseName, 
itemName.get(), path, activeVersion, 
databaseRuleNodePath.getRoot().getRuleType() + "." + entry.getKey()));
             }
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
index a45e2201516..a95152649f6 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
@@ -26,11 +26,6 @@ import lombok.NoArgsConstructor;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class NodePathPattern {
     
-    /**
-     * Identifier pattern.
-     */
-    public static final String IDENTIFIER = "[\\w\\-]+";
-    
     /**
      * Grouped identifier pattern.
      */
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/item/NamedDatabaseRuleItemNodePath.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/item/NamedDatabaseRuleItemNodePath.java
index 04cb0229a2d..64106a6a87e 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/item/NamedDatabaseRuleItemNodePath.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/item/NamedDatabaseRuleItemNodePath.java
@@ -41,8 +41,8 @@ public final class NamedDatabaseRuleItemNodePath {
     public NamedDatabaseRuleItemNodePath(final DatabaseRuleRootNodePath 
rootNodePath, final String type) {
         this.type = type;
         String pattern = String.join("/", rootNodePath.getNodePrefix() + type, 
NodePathPattern.GROUPED_IDENTIFIER);
-        versionNodePathParser = new VersionNodePathParser(pattern);
         itemPathPattern = Pattern.compile(pattern + "$");
+        versionNodePathParser = new VersionNodePathParser(pattern);
     }
     
     /**
@@ -63,6 +63,6 @@ public final class NamedDatabaseRuleItemNodePath {
      */
     public Optional<String> findNameByItemPath(final String itemPath) {
         Matcher matcher = itemPathPattern.matcher(itemPath);
-        return matcher.find() ? Optional.of(matcher.group(1)) : 
Optional.empty();
+        return matcher.find() ? Optional.of(matcher.group(2)) : 
Optional.empty();
     }
 }
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePath.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePath.java
index daf3cb24dc6..f9fe923222f 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePath.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePath.java
@@ -41,7 +41,7 @@ public final class DatabaseRuleRootNodePath {
     
     public DatabaseRuleRootNodePath(final String ruleType) {
         this.ruleType = ruleType;
-        nodePrefix = String.join("/", ROOT_NODE, NodePathPattern.IDENTIFIER, 
RULE_NODE, ruleType, "");
+        nodePrefix = String.join("/", ROOT_NODE, 
NodePathPattern.GROUPED_IDENTIFIER, RULE_NODE, ruleType, "");
         pathPattern = Pattern.compile(nodePrefix + ".*");
     }
     
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 bb658a162f1..6ca30b3ec1f 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
@@ -206,12 +206,12 @@ public final class YamlRepositoryTupleSwapperEngine {
         RepositoryTupleKeyListNameGenerator tupleKeyListNameGenerator = 
field.getAnnotation(RepositoryTupleKeyListNameGenerator.class);
         if (null != tupleKeyListNameGenerator && fieldValue instanceof 
Collection) {
             
databaseRuleNodePath.getNamedItem(tupleName).getVersionNodePathParser()
-                    .findIdentifierByVersionsPath(repositoryTuple.getKey(), 
1).ifPresent(optional -> ((Collection) 
fieldValue).add(repositoryTuple.getValue()));
+                    .findIdentifierByVersionsPath(repositoryTuple.getKey(), 
2).ifPresent(optional -> ((Collection) 
fieldValue).add(repositoryTuple.getValue()));
             return;
         }
         if (fieldValue instanceof Map) {
             Class<?> valueClass = (Class) ((ParameterizedType) 
field.getGenericType()).getActualTypeArguments()[1];
-            
databaseRuleNodePath.getNamedItem(tupleName).getVersionNodePathParser().findIdentifierByVersionsPath(repositoryTuple.getKey(),
 1)
+            
databaseRuleNodePath.getNamedItem(tupleName).getVersionNodePathParser().findIdentifierByVersionsPath(repositoryTuple.getKey(),
 2)
                     .ifPresent(optional -> ((Map) fieldValue).put(optional, 
YamlEngine.unmarshal(repositoryTuple.getValue(), valueClass)));
             return;
         }
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePathTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePathTest.java
index ecbd9e23c64..fdca2c8d113 100644
--- 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePathTest.java
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/config/database/root/DatabaseRuleRootNodePathTest.java
@@ -30,7 +30,7 @@ class DatabaseRuleRootNodePathTest {
     
     @Test
     void assertGetRuleNodePrefix() {
-        assertThat(nodePath.getNodePrefix(), 
is("/metadata/[\\w\\-]+/rules/foo/"));
+        assertThat(nodePath.getNodePrefix(), 
is("/metadata/([\\w\\-]+)/rules/foo/"));
     }
     
     @Test

Reply via email to