From d6e24f0353f4716f66e9f66bf22949e19be6e4ba Mon Sep 17 00:00:00 2001 From: zhaojinchao Date: Sun, 12 May 2024 18:43:26 +0800 Subject: [PATCH] Remove RepositoryTupleField#value() (#31218) * Remove RepositoryTupleField#value() * Fix ci * Fix CI --- .../nodepath/ReadwriteSplittingRuleNodePathProvider.java | 4 ++-- .../ReadwriteSplittingDataSourceChangedProcessor.java | 2 +- .../config/YamlReadwriteSplittingRuleConfiguration.java | 3 +-- .../ReadwriteSplittingRuleNodePathProviderTest.java | 2 +- .../metadata/nodepath/ShadowRuleNodePathProvider.java | 7 ++++--- .../DefaultShadowAlgorithmNameChangedProcessor.java | 2 +- .../rule/changed/ShadowAlgorithmChangedProcessor.java | 2 +- .../shadow/yaml/config/YamlShadowRuleConfiguration.java | 5 ++--- .../metadata/nodepath/ShadowRuleNodePathProviderTest.java | 4 ++-- .../metadata/nodepath/ShardingRuleNodePathProvider.java | 4 ++-- .../rule/changed/ShardingAlgorithmChangedProcessor.java | 2 +- .../yaml/config/YamlShardingRuleConfiguration.java | 3 +-- .../nodepath/ShardingRuleNodePathProviderTest.java | 2 +- .../mode/tuple/RepositoryTupleSwapperEngine.java | 3 +-- .../mode/tuple/annotation/RepositoryTupleField.java | 7 ------- 15 files changed, 21 insertions(+), 31 deletions(-) diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProvider.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProvider.java index 97a0821ec16f6..b238dc0748d80 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProvider.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProvider.java @@ -32,11 +32,11 @@ public final class ReadwriteSplittingRuleNodePathProvider implements RuleNodePat public static final String RULE_TYPE = "readwrite_splitting"; - public static final String DATA_SOURCES = "data_sources"; + public static final String DATA_SOURCE_GROUPS = "data_source_groups"; public static final String LOAD_BALANCERS = "load_balancers"; - private static final RuleNodePath INSTANCE = new RuleNodePath(RULE_TYPE, Arrays.asList(DATA_SOURCES, LOAD_BALANCERS), Collections.emptyList()); + private static final RuleNodePath INSTANCE = new RuleNodePath(RULE_TYPE, Arrays.asList(DATA_SOURCE_GROUPS, LOAD_BALANCERS), Collections.emptyList()); @Override public RuleNodePath getRuleNodePath() { diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java index 222dba3ad2956..05f215468bcee 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/changed/ReadwriteSplittingDataSourceChangedProcessor.java @@ -78,6 +78,6 @@ public void dropRuleItemConfiguration(final DropRuleItemEvent event, final Readw @Override public String getType() { - return ReadwriteSplittingRuleNodePathProvider.RULE_TYPE + "." + ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES; + return ReadwriteSplittingRuleNodePathProvider.RULE_TYPE + "." + ReadwriteSplittingRuleNodePathProvider.DATA_SOURCE_GROUPS; } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/config/YamlReadwriteSplittingRuleConfiguration.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/config/YamlReadwriteSplittingRuleConfiguration.java index 83ccc426d1612..157acea845615 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/config/YamlReadwriteSplittingRuleConfiguration.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/config/YamlReadwriteSplittingRuleConfiguration.java @@ -25,7 +25,6 @@ import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity; import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleField.Type; import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration; -import org.apache.shardingsphere.readwritesplitting.metadata.nodepath.ReadwriteSplittingRuleNodePathProvider; import org.apache.shardingsphere.readwritesplitting.yaml.config.rule.YamlReadwriteSplittingDataSourceGroupRuleConfiguration; import java.util.LinkedHashMap; @@ -39,7 +38,7 @@ @Setter public final class YamlReadwriteSplittingRuleConfiguration implements YamlRuleConfiguration { - @RepositoryTupleField(value = ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES, type = Type.DATA_SOURCE) + @RepositoryTupleField(type = Type.DATA_SOURCE) private Map dataSourceGroups = new LinkedHashMap<>(); @RepositoryTupleField(type = Type.ALGORITHM) diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProviderTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProviderTest.java index 974de9c9a84d1..213f54e1b30f3 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProviderTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/metadata/nodepath/ReadwriteSplittingRuleNodePathProviderTest.java @@ -32,7 +32,7 @@ void assertNew() { RuleNodePathProvider ruleNodePathProvider = new ReadwriteSplittingRuleNodePathProvider(); RuleNodePath actualRuleNodePath = ruleNodePathProvider.getRuleNodePath(); assertThat(actualRuleNodePath.getNamedItems().size(), is(2)); - assertTrue(actualRuleNodePath.getNamedItems().containsKey(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES)); + assertTrue(actualRuleNodePath.getNamedItems().containsKey(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCE_GROUPS)); assertTrue(actualRuleNodePath.getNamedItems().containsKey(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS)); assertTrue(actualRuleNodePath.getUniqueItems().isEmpty()); assertThat(actualRuleNodePath.getRoot().getRuleType(), is(ReadwriteSplittingRuleNodePathProvider.RULE_TYPE)); diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProvider.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProvider.java index 62553923d6b95..9e7c08698b3e0 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProvider.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProvider.java @@ -36,11 +36,12 @@ public final class ShadowRuleNodePathProvider implements RuleNodePathProvider { public static final String TABLES = "tables"; - public static final String ALGORITHMS = "algorithms"; + public static final String SHADOW_ALGORITHMS = "shadow_algorithms"; - public static final String DEFAULT_ALGORITHM = "default_algorithm_name"; + public static final String DEFAULT_SHADOW_ALGORITHM_NAME = "default_shadow_algorithm_name"; - private static final RuleNodePath INSTANCE = new RuleNodePath(RULE_TYPE, Arrays.asList(DATA_SOURCES, TABLES, ALGORITHMS), Collections.singleton(DEFAULT_ALGORITHM)); + private static final RuleNodePath INSTANCE = new RuleNodePath(RULE_TYPE, Arrays.asList(DATA_SOURCES, TABLES, SHADOW_ALGORITHMS), + Collections.singleton(DEFAULT_SHADOW_ALGORITHM_NAME)); @Override public RuleNodePath getRuleNodePath() { diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java index 33bc32a0985f3..125574ba11cec 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/DefaultShadowAlgorithmNameChangedProcessor.java @@ -52,6 +52,6 @@ public void dropRuleItemConfiguration(final DropRuleItemEvent event, final Shado @Override public String getType() { - return ShadowRuleNodePathProvider.RULE_TYPE + "." + ShadowRuleNodePathProvider.DEFAULT_ALGORITHM; + return ShadowRuleNodePathProvider.RULE_TYPE + "." + ShadowRuleNodePathProvider.DEFAULT_SHADOW_ALGORITHM_NAME; } } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessor.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessor.java index 7c6b437b4e5e7..8884fc543bde2 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessor.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/changed/ShadowAlgorithmChangedProcessor.java @@ -58,6 +58,6 @@ public void dropRuleItemConfiguration(final DropRuleItemEvent event, final Shado @Override public String getType() { - return ShadowRuleNodePathProvider.RULE_TYPE + "." + ShadowRuleNodePathProvider.ALGORITHMS; + return ShadowRuleNodePathProvider.RULE_TYPE + "." + ShadowRuleNodePathProvider.SHADOW_ALGORITHMS; } } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java index 0b8461e1885f6..0093738d110b8 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/config/YamlShadowRuleConfiguration.java @@ -25,7 +25,6 @@ import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleEntity; import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleField.Type; import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration; -import org.apache.shardingsphere.shadow.metadata.nodepath.ShadowRuleNodePathProvider; import org.apache.shardingsphere.shadow.yaml.config.datasource.YamlShadowDataSourceConfiguration; import org.apache.shardingsphere.shadow.yaml.config.table.YamlShadowTableConfiguration; @@ -46,10 +45,10 @@ public final class YamlShadowRuleConfiguration implements YamlRuleConfiguration @RepositoryTupleField(type = Type.TABLE) private Map tables = new LinkedHashMap<>(); - @RepositoryTupleField(value = ShadowRuleNodePathProvider.ALGORITHMS, type = Type.ALGORITHM) + @RepositoryTupleField(type = Type.ALGORITHM) private Map shadowAlgorithms = new LinkedHashMap<>(); - @RepositoryTupleField(value = ShadowRuleNodePathProvider.DEFAULT_ALGORITHM, type = Type.DEFAULT_ALGORITHM) + @RepositoryTupleField(type = Type.DEFAULT_ALGORITHM) private String defaultShadowAlgorithmName; @Override diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProviderTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProviderTest.java index da965591c32db..ae60a0e5db65c 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProviderTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/metadata/nodepath/ShadowRuleNodePathProviderTest.java @@ -32,11 +32,11 @@ void assertNew() { RuleNodePathProvider ruleNodePathProvider = new ShadowRuleNodePathProvider(); RuleNodePath actualRuleNodePath = ruleNodePathProvider.getRuleNodePath(); assertThat(actualRuleNodePath.getNamedItems().size(), is(3)); - assertTrue(actualRuleNodePath.getNamedItems().containsKey(ShadowRuleNodePathProvider.ALGORITHMS)); + assertTrue(actualRuleNodePath.getNamedItems().containsKey(ShadowRuleNodePathProvider.SHADOW_ALGORITHMS)); assertTrue(actualRuleNodePath.getNamedItems().containsKey(ShadowRuleNodePathProvider.TABLES)); assertTrue(actualRuleNodePath.getNamedItems().containsKey(ShadowRuleNodePathProvider.DATA_SOURCES)); assertThat(actualRuleNodePath.getUniqueItems().size(), is(1)); - assertTrue(actualRuleNodePath.getUniqueItems().containsKey(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM)); + assertTrue(actualRuleNodePath.getUniqueItems().containsKey(ShadowRuleNodePathProvider.DEFAULT_SHADOW_ALGORITHM_NAME)); assertThat(actualRuleNodePath.getRoot().getRuleType(), is(ShadowRuleNodePathProvider.RULE_TYPE)); } } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProvider.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProvider.java index 3a6d361d2dda2..a501bfe249a03 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProvider.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProvider.java @@ -37,7 +37,7 @@ public final class ShardingRuleNodePathProvider implements RuleNodePathProvider public static final String BINDING_TABLES = "binding_tables"; - public static final String ALGORITHMS = "algorithms"; + public static final String SHARDING_ALGORITHMS = "sharding_algorithms"; public static final String KEY_GENERATORS = "key_generators"; @@ -58,7 +58,7 @@ public final class ShardingRuleNodePathProvider implements RuleNodePathProvider private static final String DEFAULT_STRATEGIES_PREFIX = "default_strategies."; private static final RuleNodePath INSTANCE = new RuleNodePath(RULE_TYPE, - Arrays.asList(TABLES, AUTO_TABLES, BINDING_TABLES, ALGORITHMS, KEY_GENERATORS, AUDITORS), + Arrays.asList(TABLES, AUTO_TABLES, BINDING_TABLES, SHARDING_ALGORITHMS, KEY_GENERATORS, AUDITORS), Arrays.asList(DEFAULT_STRATEGIES_PREFIX + DEFAULT_DATABASE_STRATEGY, DEFAULT_STRATEGIES_PREFIX + DEFAULT_TABLE_STRATEGY, DEFAULT_STRATEGIES_PREFIX + DEFAULT_KEY_GENERATE_STRATEGY, DEFAULT_STRATEGIES_PREFIX + DEFAULT_AUDIT_STRATEGY, DEFAULT_STRATEGIES_PREFIX + DEFAULT_SHARDING_COLUMN, SHARDING_CACHE)); diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessor.java index 211e1d167f622..076174cd2de74 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessor.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/changed/ShardingAlgorithmChangedProcessor.java @@ -58,6 +58,6 @@ public void dropRuleItemConfiguration(final DropRuleItemEvent event, final Shard @Override public String getType() { - return ShardingRuleNodePathProvider.RULE_TYPE + "." + ShardingRuleNodePathProvider.ALGORITHMS; + return ShardingRuleNodePathProvider.RULE_TYPE + "." + ShardingRuleNodePathProvider.SHARDING_ALGORITHMS; } } diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java index 13eafc36d282e..c235a09dd4566 100644 --- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java +++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/config/YamlShardingRuleConfiguration.java @@ -26,7 +26,6 @@ import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleField.Type; import org.apache.shardingsphere.mode.tuple.annotation.RepositoryTupleKeyListNameGenerator; import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration; -import org.apache.shardingsphere.sharding.metadata.nodepath.ShardingRuleNodePathProvider; import org.apache.shardingsphere.sharding.yaml.config.cache.YamlShardingCacheConfiguration; import org.apache.shardingsphere.sharding.yaml.config.rule.YamlShardingAutoTableRuleConfiguration; import org.apache.shardingsphere.sharding.yaml.config.rule.YamlTableRuleConfiguration; @@ -70,7 +69,7 @@ public final class YamlShardingRuleConfiguration implements YamlRuleConfiguratio @RepositoryTupleField(type = Type.DEFAULT_STRATEGY) private YamlShardingAuditStrategyConfiguration defaultAuditStrategy; - @RepositoryTupleField(value = ShardingRuleNodePathProvider.ALGORITHMS, type = Type.ALGORITHM) + @RepositoryTupleField(type = Type.ALGORITHM) private Map shardingAlgorithms = new LinkedHashMap<>(); @RepositoryTupleField(type = Type.ALGORITHM) diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProviderTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProviderTest.java index cffa2588db558..e4aeaf77ed619 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProviderTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/nodepath/ShardingRuleNodePathProviderTest.java @@ -36,7 +36,7 @@ void assertNew() { RuleNodePath actualRuleNodePath = ruleNodePathProvider.getRuleNodePath(); assertThat(actualRuleNodePath.getNamedItems().size(), is(6)); List namedRuleItems = Arrays.asList(ShardingRuleNodePathProvider.TABLES, ShardingRuleNodePathProvider.AUTO_TABLES, ShardingRuleNodePathProvider.BINDING_TABLES, - ShardingRuleNodePathProvider.ALGORITHMS, ShardingRuleNodePathProvider.KEY_GENERATORS, ShardingRuleNodePathProvider.AUDITORS); + ShardingRuleNodePathProvider.SHARDING_ALGORITHMS, ShardingRuleNodePathProvider.KEY_GENERATORS, ShardingRuleNodePathProvider.AUDITORS); assertThat("Named rule items equality without order", actualRuleNodePath.getNamedItems().keySet(), IsIterableContainingInAnyOrder.containsInAnyOrder(namedRuleItems.toArray())); assertThat(actualRuleNodePath.getUniqueItems().size(), is(6)); List uniqueRuleItems = Arrays.asList(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY, ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY, diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngine.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngine.java index 11831e67a949f..37763eb66cf2d 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngine.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/RepositoryTupleSwapperEngine.java @@ -127,8 +127,7 @@ private Collection getFields(final Class } private String getTupleName(final Field field) { - RepositoryTupleField tupleField = field.getAnnotation(RepositoryTupleField.class); - return "".equals(tupleField.value()) ? CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getName()) : tupleField.value(); + return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, field.getName()); } /** diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/annotation/RepositoryTupleField.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/annotation/RepositoryTupleField.java index 74fde9ee9a84a..4016112f2a35c 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/annotation/RepositoryTupleField.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/tuple/annotation/RepositoryTupleField.java @@ -31,13 +31,6 @@ @Retention(RetentionPolicy.RUNTIME) public @interface RepositoryTupleField { - /** - * Get persist path name. - * - * @return persist path name - */ - String value() default ""; - /** * Get type. *