You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/10/12 12:55:43 UTC

[shardingsphere] branch master updated: Minor refactor for SchemaMetaDataNode (#13006)

This is an automated email from the ASF dual-hosted git repository.

panjuan 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 c6ec965  Minor refactor for SchemaMetaDataNode (#13006)
c6ec965 is described below

commit c6ec9650d0a9190eb6d17cc2ecf6085513f69f7d
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Tue Oct 12 20:55:10 2021 +0800

    Minor refactor for SchemaMetaDataNode (#13006)
---
 .../mode/metadata/persist/node/SchemaMetaDataNode.java              | 6 +++---
 .../mode/metadata/persist/node/SchemaMetaDataNodeTest.java          | 5 +++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNode.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNode.java
index f9b5e69..2801aa8 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNode.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNode.java
@@ -97,11 +97,11 @@ public final class SchemaMetaDataNode {
      * @return schema name
      */
     public static String getSchemaName(final String configurationNodeFullPath) {
-        Pattern pattern = Pattern.compile(getMetaDataNodePath() + "/(\\w+)" + "(/datasource|/rule|/schema)?", Pattern.CASE_INSENSITIVE);
+        Pattern pattern = Pattern.compile(getMetaDataNodePath() + "/([\\w\\-]+)" + "(/datasources|/rules|/schema)?", Pattern.CASE_INSENSITIVE);
         Matcher matcher = pattern.matcher(configurationNodeFullPath);
         return matcher.find() ? matcher.group(1) : "";
     }
-
+    
     /**
      * Get schema name by schema path.
      *
@@ -109,7 +109,7 @@ public final class SchemaMetaDataNode {
      * @return schema name
      */
     public static String getSchemaNameBySchemaPath(final String schemaPath) {
-        Pattern pattern = Pattern.compile(getMetaDataNodePath() + "/(\\w+)$", Pattern.CASE_INSENSITIVE);
+        Pattern pattern = Pattern.compile(getMetaDataNodePath() + "/([\\w\\-]+)$", Pattern.CASE_INSENSITIVE);
         Matcher matcher = pattern.matcher(schemaPath);
         return matcher.find() ? matcher.group(1) : "";
     }
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNodeTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNodeTest.java
index ec0443e..96735af 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNodeTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/SchemaMetaDataNodeTest.java
@@ -36,6 +36,11 @@ public class SchemaMetaDataNodeTest {
     }
     
     @Test
+    public void assertGetSchemaNameWithLine() {
+        assertThat(SchemaMetaDataNode.getSchemaName("/metadata/logic-db-test/rules"), is("logic-db-test"));
+    }
+    
+    @Test
     public void assertGetSchemaNamePath() {
         assertThat(SchemaMetaDataNode.getSchemaNamePath("sharding_db"), is("/metadata/sharding_db"));
     }