-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor DatabaseRuleMetaDataNode (#34276)
* Refactor DatabaseRuleMetaDataNode * Refactor DatabaseRuleMetaDataNode
- Loading branch information
Showing
5 changed files
with
170 additions
and
164 deletions.
There are no files selected for viewing
110 changes: 0 additions & 110 deletions
110
...va/org/apache/shardingsphere/metadata/persist/node/metadata/DatabaseRuleMetaDataNode.java
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
...rg/apache/shardingsphere/metadata/persist/node/metadata/DatabaseRuleMetaDataNodePath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* 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.metadata.persist.node.metadata; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Database rule meta data node path. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class DatabaseRuleMetaDataNodePath { | ||
|
||
private static final String ROOT_NODE = "/metadata"; | ||
|
||
private static final String RULE_NODE = "rules"; | ||
|
||
private static final String VERSIONS_NODE = "versions"; | ||
|
||
private static final String ACTIVE_VERSION_NODE = "active_version"; | ||
|
||
/** | ||
* Get database root path. | ||
* | ||
* @param databaseName database name | ||
* @return database root path | ||
*/ | ||
public static String getRootPath(final String databaseName) { | ||
return String.join("/", ROOT_NODE, databaseName, RULE_NODE); | ||
} | ||
|
||
/** | ||
* Get database rule path. | ||
* | ||
* @param databaseName database name | ||
* @param ruleTypeName rule type name | ||
* @return database rule path | ||
*/ | ||
public static String getRulePath(final String databaseName, final String ruleTypeName) { | ||
return String.join("/", getRootPath(databaseName), ruleTypeName); | ||
} | ||
|
||
/** | ||
* Get database rule path. | ||
* | ||
* @param databaseName database name | ||
* @param ruleTypeName rule type name | ||
* @param key key | ||
* @return database rule path without version | ||
*/ | ||
public static String getRulePath(final String databaseName, final String ruleTypeName, final String key) { | ||
return String.join("/", getRulePath(databaseName, ruleTypeName), key); | ||
} | ||
|
||
/** | ||
* Get database rule versions path. | ||
* | ||
* @param databaseName database name | ||
* @param ruleTypeName rule type name | ||
* @param key key | ||
* @return database rule versions path | ||
*/ | ||
public static String getVersionsPath(final String databaseName, final String ruleTypeName, final String key) { | ||
return String.join("/", getRulePath(databaseName, ruleTypeName, key), VERSIONS_NODE); | ||
} | ||
|
||
/** | ||
* Get database rule version path. | ||
* | ||
* @param databaseName database name | ||
* @param ruleTypeName rule type name | ||
* @param key key | ||
* @param version version | ||
* @return database rule next version | ||
*/ | ||
public static String getVersionPath(final String databaseName, final String ruleTypeName, final String key, final String version) { | ||
return String.join("/", getVersionsPath(databaseName, ruleTypeName, key), version); | ||
} | ||
|
||
/** | ||
* Get database rule active version path. | ||
* | ||
* @param databaseName database name | ||
* @param ruleTypeName rule type name | ||
* @param key key | ||
* @return database rule active version path | ||
*/ | ||
public static String getActiveVersionPath(final String databaseName, final String ruleTypeName, final String key) { | ||
return String.join("/", getRulePath(databaseName, ruleTypeName, key), ACTIVE_VERSION_NODE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...pache/shardingsphere/metadata/persist/node/metadata/DatabaseRuleMetaDataNodePathTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.metadata.persist.node.metadata; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class DatabaseRuleMetaDataNodePathTest { | ||
|
||
@Test | ||
void assertGetRootPath() { | ||
assertThat(DatabaseRuleMetaDataNodePath.getRootPath("foo_db"), is("/metadata/foo_db/rules")); | ||
} | ||
|
||
@Test | ||
void assertGetRulePath() { | ||
assertThat(DatabaseRuleMetaDataNodePath.getRulePath("foo_db", "foo_rule"), is("/metadata/foo_db/rules/foo_rule")); | ||
} | ||
|
||
@Test | ||
void assertGetRulePathWithKey() { | ||
assertThat(DatabaseRuleMetaDataNodePath.getRulePath("foo_db", "foo_rule", "sharding"), is("/metadata/foo_db/rules/foo_rule/sharding")); | ||
} | ||
|
||
@Test | ||
void assertGetVersionsPath() { | ||
assertThat(DatabaseRuleMetaDataNodePath.getVersionsPath("foo_db", "sharding", "foo_key"), is("/metadata/foo_db/rules/sharding/foo_key/versions")); | ||
} | ||
|
||
@Test | ||
void assertGetVersionPath() { | ||
assertThat(DatabaseRuleMetaDataNodePath.getVersionPath("foo_db", "foo_rule", "foo_tbl", "1"), is("/metadata/foo_db/rules/foo_rule/foo_tbl/versions/1")); | ||
} | ||
|
||
@Test | ||
void assertGetActiveVersionPath() { | ||
assertThat(DatabaseRuleMetaDataNodePath.getActiveVersionPath("foo_db", "foo_rule", "foo_tbl"), is("/metadata/foo_db/rules/foo_rule/foo_tbl/active_version")); | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
...rg/apache/shardingsphere/metadata/persist/node/metadata/DatabaseRuleMetaDataNodeTest.java
This file was deleted.
Oops, something went wrong.