Skip to content

Commit

Permalink
Remove RepositoryTupleField#value() (#31218)
Browse files Browse the repository at this point in the history
* Remove RepositoryTupleField#value()

* Fix ci

* Fix CI
  • Loading branch information
zhaojinchao95 authored May 12, 2024
1 parent 1fbc4fd commit d6e24f0
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, YamlReadwriteSplittingDataSourceGroupRuleConfiguration> dataSourceGroups = new LinkedHashMap<>();

@RepositoryTupleField(type = Type.ALGORITHM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -46,10 +45,10 @@ public final class YamlShadowRuleConfiguration implements YamlRuleConfiguration
@RepositoryTupleField(type = Type.TABLE)
private Map<String, YamlShadowTableConfiguration> tables = new LinkedHashMap<>();

@RepositoryTupleField(value = ShadowRuleNodePathProvider.ALGORITHMS, type = Type.ALGORITHM)
@RepositoryTupleField(type = Type.ALGORITHM)
private Map<String, YamlAlgorithmConfiguration> shadowAlgorithms = new LinkedHashMap<>();

@RepositoryTupleField(value = ShadowRuleNodePathProvider.DEFAULT_ALGORITHM, type = Type.DEFAULT_ALGORITHM)
@RepositoryTupleField(type = Type.DEFAULT_ALGORITHM)
private String defaultShadowAlgorithmName;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, YamlAlgorithmConfiguration> shardingAlgorithms = new LinkedHashMap<>();

@RepositoryTupleField(type = Type.ALGORITHM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void assertNew() {
RuleNodePath actualRuleNodePath = ruleNodePathProvider.getRuleNodePath();
assertThat(actualRuleNodePath.getNamedItems().size(), is(6));
List<String> 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<String> uniqueRuleItems = Arrays.asList(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY, ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ private Collection<Field> getFields(final Class<? extends YamlRuleConfiguration>
}

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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface RepositoryTupleField {

/**
* Get persist path name.
*
* @return persist path name
*/
String value() default "";

/**
* Get type.
*
Expand Down

0 comments on commit d6e24f0

Please sign in to comment.