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 b23ce84c4cd Merge MetaDataNodePath and DatabaseNodePathGenerator (#34683) b23ce84c4cd is described below commit b23ce84c4cd8110b177a354ac3620efe2454ccc6 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Sat Feb 15 20:22:14 2025 +0800 Merge MetaDataNodePath and DatabaseNodePathGenerator (#34683) * Merge MetaDataNodePath and DatabaseNodePathGenerator * Merge MetaDataNodePath and DatabaseNodePathGenerator * Merge MetaDataNodePath and DatabaseNodePathGenerator * Merge MetaDataNodePath and DatabaseNodePathGenerator --- .../service/DatabaseMetaDataPersistService.java | 3 +- .../path/metadata/DatabaseNodePathGenerator.java | 13 ++++++++- .../node/path/metadata/DatabaseNodePathParser.java | 5 ++-- .../mode/node/path/metadata/MetaDataNodePath.java | 33 ---------------------- .../database/SchemaMetaDataNodePathParser.java | 4 +-- .../DatabaseRuleMetaDataNodePathGenerator.java | 4 +-- .../DataSourceMetaDataNodePathGenerator.java | 4 +-- .../metadata/DatabaseNodePathGeneratorTest.java | 5 ++++ 8 files changed, 27 insertions(+), 44 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/DatabaseMetaDataPersistService.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/DatabaseMetaDataPersistService.java index c3eedcd0ccf..458ccdcb352 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/DatabaseMetaDataPersistService.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/metadata/service/DatabaseMetaDataPersistService.java @@ -19,7 +19,6 @@ package org.apache.shardingsphere.mode.metadata.persist.metadata.service; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.mode.node.path.metadata.DatabaseNodePathGenerator; -import org.apache.shardingsphere.mode.node.path.metadata.MetaDataNodePath; import org.apache.shardingsphere.mode.spi.repository.PersistRepository; import java.util.Collection; @@ -56,6 +55,6 @@ public final class DatabaseMetaDataPersistService { * @return loaded database names */ public Collection<String> loadAllDatabaseNames() { - return repository.getChildrenKeys(MetaDataNodePath.ROOT_NODE); + return repository.getChildrenKeys(DatabaseNodePathGenerator.getRootPath()); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGenerator.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGenerator.java index 3d7fd839c4f..fbc59eb269e 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGenerator.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGenerator.java @@ -26,6 +26,17 @@ import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class DatabaseNodePathGenerator { + private static final String ROOT_NODE = "/metadata"; + + /** + * Get database root path. + * + * @return schema root path + */ + public static String getRootPath() { + return ROOT_NODE; + } + /** * Get database path. * @@ -33,6 +44,6 @@ public final class DatabaseNodePathGenerator { * @return database path */ public static String getDatabasePath(final String databaseName) { - return String.join("/", MetaDataNodePath.ROOT_NODE, databaseName); + return String.join("/", ROOT_NODE, databaseName); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathParser.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathParser.java index 7d32f153e01..c863c1f78cf 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathParser.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathParser.java @@ -31,6 +31,8 @@ import java.util.regex.Pattern; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class DatabaseNodePathParser { + private static final Pattern DATABASE_PATTERN = Pattern.compile(DatabaseNodePathGenerator.getDatabasePath(NodePathPattern.IDENTIFIER) + "?", Pattern.CASE_INSENSITIVE); + /** * Find database name. * @@ -38,8 +40,7 @@ public final class DatabaseNodePathParser { * @return found database name */ public static Optional<String> findDatabaseName(final String path) { - Pattern pattern = Pattern.compile(DatabaseNodePathGenerator.getDatabasePath(NodePathPattern.IDENTIFIER) + "?", Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(path); + Matcher matcher = DATABASE_PATTERN.matcher(path); return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty(); } } diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/MetaDataNodePath.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/MetaDataNodePath.java deleted file mode 100644 index 6afc8a20a12..00000000000 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/MetaDataNodePath.java +++ /dev/null @@ -1,33 +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.metadata; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * Meta data node path. - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class MetaDataNodePath { - - /** - * Root node. - */ - public static final String ROOT_NODE = "/metadata"; -} diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/database/SchemaMetaDataNodePathParser.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/database/SchemaMetaDataNodePathParser.java index 8f222dd6225..d3732de6ade 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/database/SchemaMetaDataNodePathParser.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/database/SchemaMetaDataNodePathParser.java @@ -32,11 +32,11 @@ import java.util.regex.Pattern; public final class SchemaMetaDataNodePathParser { /** - * Find qualified schema. + * Find schema name. * * @param path path * @param containsChildPath whether contains child path - * @return found qualified schema + * @return found schema name */ public static Optional<String> findSchemaName(final String path, final boolean containsChildPath) { String endPattern = containsChildPath ? "?" : "$"; diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/rule/DatabaseRuleMetaDataNodePathGenerator.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/rule/DatabaseRuleMetaDataNodePathGenerator.java index ad5ac1ac01f..f874dc124ef 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/rule/DatabaseRuleMetaDataNodePathGenerator.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/rule/DatabaseRuleMetaDataNodePathGenerator.java @@ -20,7 +20,7 @@ package org.apache.shardingsphere.mode.node.path.metadata.rule; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.shardingsphere.mode.node.path.config.database.item.DatabaseRuleItem; -import org.apache.shardingsphere.mode.node.path.metadata.MetaDataNodePath; +import org.apache.shardingsphere.mode.node.path.metadata.DatabaseNodePathGenerator; import org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator; /** @@ -38,7 +38,7 @@ public final class DatabaseRuleMetaDataNodePathGenerator { * @return database root path */ public static String getRootPath(final String databaseName) { - return String.join("/", MetaDataNodePath.ROOT_NODE, databaseName, RULE_NODE); + return String.join("/", DatabaseNodePathGenerator.getRootPath(), databaseName, RULE_NODE); } /** diff --git a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceMetaDataNodePathGenerator.java b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceMetaDataNodePathGenerator.java index 7dfb7c938b0..ca4f88aa5eb 100644 --- a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceMetaDataNodePathGenerator.java +++ b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/metadata/storage/DataSourceMetaDataNodePathGenerator.java @@ -19,7 +19,7 @@ package org.apache.shardingsphere.mode.node.path.metadata.storage; import lombok.AccessLevel; import lombok.NoArgsConstructor; -import org.apache.shardingsphere.mode.node.path.metadata.MetaDataNodePath; +import org.apache.shardingsphere.mode.node.path.metadata.DatabaseNodePathGenerator; import org.apache.shardingsphere.mode.node.path.version.VersionNodePathGenerator; /** @@ -41,7 +41,7 @@ public final class DataSourceMetaDataNodePathGenerator { * @return data source root path */ public static String getDataSourceRootPath(final String databaseName) { - return String.join("/", MetaDataNodePath.ROOT_NODE, databaseName, DATA_SOURCES_NODE); + return String.join("/", DatabaseNodePathGenerator.getRootPath(), databaseName, DATA_SOURCES_NODE); } /** diff --git a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGeneratorTest.java b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGeneratorTest.java index f5114f3f57e..fd4a9e61d26 100644 --- a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGeneratorTest.java +++ b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/metadata/DatabaseNodePathGeneratorTest.java @@ -24,6 +24,11 @@ import static org.hamcrest.MatcherAssert.assertThat; class DatabaseNodePathGeneratorTest { + @Test + void assertGetPath() { + assertThat(DatabaseNodePathGenerator.getRootPath(), is("/metadata")); + } + @Test void assertGetDatabasePath() { assertThat(DatabaseNodePathGenerator.getDatabasePath("foo_db"), is("/metadata/foo_db"));