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 e06a14fc147 Refactor ViewMetaDataNodePath (#34562)
e06a14fc147 is described below

commit e06a14fc1476859314e1883c1117556313a20852
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Wed Feb 5 19:15:11 2025 +0800

    Refactor ViewMetaDataNodePath (#34562)
---
 .../service/ViewMetaDataPersistService.java        |  2 +-
 .../node/path/metadata/ViewMetaDataNodePath.java   | 38 ++++++++++------------
 .../path/metadata/ViewMetaDataNodePathTest.java    |  4 +--
 3 files changed, 21 insertions(+), 23 deletions(-)

diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/ViewMetaDataPersistService.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/ViewMetaDataPersistService.java
index 650b3760fd3..309ba679724 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/ViewMetaDataPersistService.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/ViewMetaDataPersistService.java
@@ -53,7 +53,7 @@ public final class ViewMetaDataPersistService {
      * @return loaded views
      */
     public Collection<ShardingSphereView> load(final String databaseName, 
final String schemaName) {
-        return 
repository.getChildrenKeys(ViewMetaDataNodePath.getMetaDataViewsPath(databaseName,
 schemaName)).stream().map(each -> load(databaseName, schemaName, 
each)).collect(Collectors.toList());
+        return 
repository.getChildrenKeys(ViewMetaDataNodePath.getViewRootPath(databaseName, 
schemaName)).stream().map(each -> load(databaseName, schemaName, 
each)).collect(Collectors.toList());
     }
     
     /**
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePath.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePath.java
index b30aa186ea5..447bab68ea8 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePath.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePath.java
@@ -32,8 +32,6 @@ public final class ViewMetaDataNodePath {
     
     private static final String ROOT_NODE = "/metadata";
     
-    private static final String SCHEMAS_NODE = "schemas";
-    
     private static final String VIEWS_NODE = "views";
     
     private static final String VERSIONS_NODE = "versions";
@@ -47,14 +45,26 @@ public final class ViewMetaDataNodePath {
     private static final String VIEW_SUFFIX = "/([\\w\\-]+)$";
     
     /**
-     * Get meta data views path.
+     * Get view root path.
+     *
+     * @param databaseName database name
+     * @param schemaName schema name
+     * @return view root path
+     */
+    public static String getViewRootPath(final String databaseName, final 
String schemaName) {
+        return String.join("/", 
DatabaseMetaDataNodePath.getSchemaPath(databaseName, schemaName), VIEWS_NODE);
+    }
+    
+    /**
+     * Get view path.
      *
      * @param databaseName database name
      * @param schemaName schema name
-     * @return views path
+     * @param viewName view name
+     * @return view path
      */
-    public static String getMetaDataViewsPath(final String databaseName, final 
String schemaName) {
-        return String.join("/", ROOT_NODE, databaseName, SCHEMAS_NODE, 
schemaName, VIEWS_NODE);
+    public static String getViewPath(final String databaseName, final String 
schemaName, final String viewName) {
+        return String.join("/", getViewRootPath(databaseName, schemaName), 
viewName);
     }
     
     /**
@@ -66,7 +76,7 @@ public final class ViewMetaDataNodePath {
      * @return view active version path
      */
     public static String getViewActiveVersionPath(final String databaseName, 
final String schemaName, final String viewName) {
-        return String.join("/", ROOT_NODE, databaseName, SCHEMAS_NODE, 
schemaName, VIEWS_NODE, viewName, ACTIVE_VERSION_NODE);
+        return String.join("/", getViewPath(databaseName, schemaName, 
viewName), ACTIVE_VERSION_NODE);
     }
     
     /**
@@ -78,7 +88,7 @@ public final class ViewMetaDataNodePath {
      * @return view versions path
      */
     public static String getViewVersionsPath(final String databaseName, final 
String schemaName, final String viewName) {
-        return String.join("/", ROOT_NODE, databaseName, SCHEMAS_NODE, 
schemaName, VIEWS_NODE, viewName, VERSIONS_NODE);
+        return String.join("/", getViewPath(databaseName, schemaName, 
viewName), VERSIONS_NODE);
     }
     
     /**
@@ -94,18 +104,6 @@ public final class ViewMetaDataNodePath {
         return String.join("/", getViewVersionsPath(databaseName, schemaName, 
viewName), version);
     }
     
-    /**
-     * Get view path.
-     *
-     * @param databaseName database name
-     * @param schemaName schema name
-     * @param viewName view name
-     * @return view path
-     */
-    public static String getViewPath(final String databaseName, final String 
schemaName, final String viewName) {
-        return String.join("/", ROOT_NODE, databaseName, SCHEMAS_NODE, 
schemaName, VIEWS_NODE, viewName);
-    }
-    
     /**
      * Get view name by active version path.
      *
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePathTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePathTest.java
index 956af7acc8d..4cc6c839933 100644
--- 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePathTest.java
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/ViewMetaDataNodePathTest.java
@@ -29,8 +29,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 class ViewMetaDataNodePathTest {
     
     @Test
-    void assertGetMetaDataViewsPath() {
-        assertThat(ViewMetaDataNodePath.getMetaDataViewsPath("foo_db", 
"foo_schema"), is("/metadata/foo_db/schemas/foo_schema/views"));
+    void assertGetViewRootPath() {
+        assertThat(ViewMetaDataNodePath.getViewRootPath("foo_db", 
"foo_schema"), is("/metadata/foo_db/schemas/foo_schema/views"));
     }
     
     @Test

Reply via email to