Add ShardingSpherePreconditions.checkContains() (#30981)
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
index 2cb1266..a315713 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/EncryptRuleConfigurationChecker.java
@@ -73,7 +73,7 @@
() -> new MissingRequiredEncryptColumnException("Cipher", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
ShardingSpherePreconditions.checkNotEmpty(cipherColumnConfig.getEncryptorName(),
() -> new EmptyAlgorithmException("Standard encrypt", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
- ShardingSpherePreconditions.checkState(encryptors.containsKey(cipherColumnConfig.getEncryptorName()),
+ ShardingSpherePreconditions.checkContainsKey(encryptors, cipherColumnConfig.getEncryptorName(),
() -> new UnregisteredAlgorithmException("Standard encrypt", cipherColumnConfig.getEncryptorName(), new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
}
@@ -83,7 +83,7 @@
() -> new MissingRequiredEncryptColumnException("Assisted query", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
ShardingSpherePreconditions.checkNotEmpty(assistedQueryColumnConfig.getEncryptorName(),
() -> new EmptyAlgorithmException("Assist query encrypt", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
- ShardingSpherePreconditions.checkState(encryptors.containsKey(assistedQueryColumnConfig.getEncryptorName()),
+ ShardingSpherePreconditions.checkContainsKey(encryptors, assistedQueryColumnConfig.getEncryptorName(),
() -> new UnregisteredAlgorithmException("Assist query encrypt", assistedQueryColumnConfig.getEncryptorName(), new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
}
@@ -93,7 +93,7 @@
() -> new MissingRequiredEncryptColumnException("Like", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
ShardingSpherePreconditions.checkNotEmpty(likeQueryColumnConfig.getEncryptorName(),
() -> new EmptyAlgorithmException("Like query", new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
- ShardingSpherePreconditions.checkState(encryptors.containsKey(likeQueryColumnConfig.getEncryptorName()),
+ ShardingSpherePreconditions.checkContainsKey(encryptors, likeQueryColumnConfig.getEncryptorName(),
() -> new UnregisteredAlgorithmException("Like query encrypt", likeQueryColumnConfig.getEncryptorName(), new SQLExceptionIdentifier(databaseName, tableName, logicColumnName)));
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
index 91c52105..4f4e506 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/condition/EncryptConditionEngine.java
@@ -162,7 +162,7 @@
if (LOGICAL_OPERATOR.contains(operator)) {
return Optional.empty();
}
- ShardingSpherePreconditions.checkState(SUPPORTED_COMPARE_OPERATOR.contains(operator), () -> new UnsupportedEncryptSQLException(operator));
+ ShardingSpherePreconditions.checkContains(SUPPORTED_COMPARE_OPERATOR, operator, () -> new UnsupportedEncryptSQLException(operator));
return createCompareEncryptCondition(tableName, expression, expression.getRight());
}
diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
index 75c066d..d747cd0 100644
--- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
+++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/algorithm/MaskAlgorithmPropertiesChecker.java
@@ -74,6 +74,6 @@
}
private static void checkRequired(final Properties props, final String requiredPropKey, final MaskAlgorithm<?, ?> algorithm) {
- ShardingSpherePreconditions.checkState(props.containsKey(requiredPropKey), () -> new AlgorithmInitializationException(algorithm, "%s is required", requiredPropKey));
+ ShardingSpherePreconditions.checkContainsKey(props, requiredPropKey, () -> new AlgorithmInitializationException(algorithm, "%s is required", requiredPropKey));
}
}
diff --git a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
index 494aa08..661f736 100644
--- a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
+++ b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/checker/MaskRuleConfigurationChecker.java
@@ -59,7 +59,7 @@
}
private void checkColumn(final String databaseName, final String tableName, final MaskColumnRuleConfiguration columnRuleConfig, final Map<String, AlgorithmConfiguration> maskAlgorithms) {
- ShardingSpherePreconditions.checkState(maskAlgorithms.containsKey(columnRuleConfig.getMaskAlgorithm()),
+ ShardingSpherePreconditions.checkContainsKey(maskAlgorithms, columnRuleConfig.getMaskAlgorithm(),
() -> new UnregisteredAlgorithmException("Mask", columnRuleConfig.getMaskAlgorithm(), new SQLExceptionIdentifier(databaseName, tableName, columnRuleConfig.getLogicColumn())));
}
diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java
index fe08d57..8acad8f 100644
--- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java
+++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java
@@ -70,7 +70,7 @@
@Override
public void cleanStorageNodeDataSource(final String groupName) {
- ShardingSpherePreconditions.checkState(dataSourceRules.containsKey(groupName), () -> new ReadwriteSplittingDataSourceRuleNotFoundException(groupName, databaseName));
+ ShardingSpherePreconditions.checkContainsKey(dataSourceRules, groupName, () -> new ReadwriteSplittingDataSourceRuleNotFoundException(groupName, databaseName));
deleteStorageNodeDataSources(dataSourceRules.get(groupName));
}
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
index 93db476..eba0117 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/checker/ReadwriteSplittingRuleStatementChecker.java
@@ -211,7 +211,7 @@
Collection<String> validStrategyNames = Arrays.stream(TransactionalReadQueryStrategy.values()).map(Enum::name).collect(Collectors.toSet());
for (ReadwriteSplittingRuleSegment each : segments) {
if (null != each.getTransactionalReadQueryStrategy()) {
- ShardingSpherePreconditions.checkState(validStrategyNames.contains(each.getTransactionalReadQueryStrategy().toUpperCase()),
+ ShardingSpherePreconditions.checkContains(validStrategyNames, each.getTransactionalReadQueryStrategy().toUpperCase(),
() -> new MissingRequiredStrategyException("Transactional read query", Collections.singleton(each.getTransactionalReadQueryStrategy())));
}
}
diff --git a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
index 90e2618..47a8806 100644
--- a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
+++ b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/AlterReadwriteSplittingStorageUnitStatusExecutor.java
@@ -62,14 +62,14 @@
private void checkBeforeUpdate(final AlterReadwriteSplittingStorageUnitStatusStatement sqlStatement) {
Optional<ReadwriteSplittingDataSourceRule> dataSourceRule = rule.getDataSourceRules().values().stream().filter(each -> each.getName().equalsIgnoreCase(sqlStatement.getRuleName())).findAny();
ShardingSpherePreconditions.checkState(dataSourceRule.isPresent(), () -> new MissingRequiredRuleException("Readwrite-splitting", database.getName(), sqlStatement.getRuleName()));
- ShardingSpherePreconditions.checkState(dataSourceRule.get().getReadwriteSplittingGroup().getReadDataSources().contains(sqlStatement.getStorageUnitName()),
+ ShardingSpherePreconditions.checkContains(dataSourceRule.get().getReadwriteSplittingGroup().getReadDataSources(), sqlStatement.getStorageUnitName(),
() -> new ReadwriteSplittingActualDataSourceNotFoundException(
ReadwriteSplittingDataSourceType.READ, sqlStatement.getStorageUnitName(), new ReadwriteSplittingRuleExceptionIdentifier(database.getName(), dataSourceRule.get().getName())));
if (sqlStatement.isEnable()) {
- ShardingSpherePreconditions.checkState(dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
+ ShardingSpherePreconditions.checkContains(dataSourceRule.get().getDisabledDataSourceNames(), sqlStatement.getStorageUnitName(),
() -> new InvalidStorageUnitStatusException("storage unit is not disabled"));
} else {
- ShardingSpherePreconditions.checkState(!dataSourceRule.get().getDisabledDataSourceNames().contains(sqlStatement.getStorageUnitName()),
+ ShardingSpherePreconditions.checkNotContains(dataSourceRule.get().getDisabledDataSourceNames(), sqlStatement.getStorageUnitName(),
() -> new InvalidStorageUnitStatusException("storage unit is already disabled"));
}
}
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
index 4909310..429ae99 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
@@ -60,8 +60,8 @@
private void checkDataSources(final Collection<ShadowDataSourceConfiguration> shadowDataSources, final Map<String, DataSource> dataSourceMap, final String databaseName) {
for (ShadowDataSourceConfiguration each : shadowDataSources) {
- ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each.getProductionDataSourceName()), () -> new MissingRequiredProductionDataSourceException(databaseName));
- ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each.getShadowDataSourceName()), () -> new MissingRequiredShadowDataSourceException(databaseName));
+ ShardingSpherePreconditions.checkContainsKey(dataSourceMap, each.getProductionDataSourceName(), () -> new MissingRequiredProductionDataSourceException(databaseName));
+ ShardingSpherePreconditions.checkContainsKey(dataSourceMap, each.getShadowDataSourceName(), () -> new MissingRequiredShadowDataSourceException(databaseName));
}
}
@@ -69,7 +69,7 @@
Collection<String> dataSourceNames = shadowDataSources.stream().map(ShadowDataSourceConfiguration::getName).collect(Collectors.toSet());
shadowTables.forEach((key, value) -> {
for (String each : value.getDataSourceNames()) {
- ShardingSpherePreconditions.checkState(dataSourceNames.contains(each), () -> new ShadowDataSourceMappingNotFoundException(key));
+ ShardingSpherePreconditions.checkContains(dataSourceNames, each, () -> new ShadowDataSourceMappingNotFoundException(key));
}
});
}
@@ -84,7 +84,7 @@
private void checkShadowTableAlgorithmsReferences(final Map<String, ShadowTableConfiguration> shadowTables, final Map<String, AlgorithmConfiguration> shadowAlgorithms, final String databaseName) {
for (ShadowTableConfiguration each : shadowTables.values()) {
ShardingSpherePreconditions.checkNotEmpty(each.getShadowAlgorithmNames(), () -> new EmptyAlgorithmException("Shadow", new SQLExceptionIdentifier(databaseName)));
- each.getShadowAlgorithmNames().forEach(shadowAlgorithmName -> ShardingSpherePreconditions.checkState(shadowAlgorithms.containsKey(shadowAlgorithmName),
+ each.getShadowAlgorithmNames().forEach(shadowAlgorithmName -> ShardingSpherePreconditions.checkContainsKey(shadowAlgorithms, shadowAlgorithmName,
() -> new EmptyAlgorithmException("Shadow", new SQLExceptionIdentifier(databaseName))));
}
}
diff --git a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
index 0f9b3bd..7b4370e 100644
--- a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
+++ b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmExecutor.java
@@ -65,7 +65,7 @@
notExistedAlgorithms -> new UnregisteredAlgorithmException("Shadow", notExistedAlgorithms, new SQLExceptionIdentifier(database.getName())));
}
checkAlgorithmInUsed(requiredAlgorithms, getAlgorithmInUse(), identical -> new InUsedAlgorithmException("Shadow", database.getName(), identical));
- ShardingSpherePreconditions.checkState(!requiredAlgorithms.contains(defaultShadowAlgorithmName),
+ ShardingSpherePreconditions.checkNotContains(requiredAlgorithms, defaultShadowAlgorithmName,
() -> new InUsedAlgorithmException("Shadow", database.getName(), Collections.singleton(defaultShadowAlgorithmName)));
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java
index e539094..bbe238f 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java
@@ -75,7 +75,7 @@
}
private long getShardingSeconds(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_SECONDS_KEY), () -> new AlgorithmInitializationException(this, String.format("%s cannot be null.", SHARDING_SECONDS_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, SHARDING_SECONDS_KEY, () -> new AlgorithmInitializationException(this, String.format("%s cannot be null.", SHARDING_SECONDS_KEY)));
return Long.parseLong(props.getProperty(SHARDING_SECONDS_KEY));
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
index c92ba0d..ed829da 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
@@ -94,14 +94,12 @@
}
private String getDateTimePattern(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_PATTERN_KEY),
- () -> new AlgorithmInitializationException(this, String.format("%s can not be null", DATE_TIME_PATTERN_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, DATE_TIME_PATTERN_KEY, () -> new AlgorithmInitializationException(this, String.format("%s can not be null", DATE_TIME_PATTERN_KEY)));
return props.getProperty(DATE_TIME_PATTERN_KEY);
}
private TemporalAccessor getDateTimeLower(final Properties props, final String dateTimePattern) {
- ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_LOWER_KEY),
- () -> new AlgorithmInitializationException(this, String.format("%s can not be null.", DATE_TIME_LOWER_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, DATE_TIME_LOWER_KEY, () -> new AlgorithmInitializationException(this, String.format("%s can not be null.", DATE_TIME_LOWER_KEY)));
return getDateTime(DATE_TIME_LOWER_KEY, props.getProperty(DATE_TIME_LOWER_KEY), dateTimePattern);
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java
index c71344d..b1fb965 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/HashModShardingAlgorithm.java
@@ -44,7 +44,7 @@
}
private int getShardingCount(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_COUNT_KEY), () -> new AlgorithmInitializationException(this, "Sharding count cannot be null."));
+ ShardingSpherePreconditions.checkContainsKey(props, SHARDING_COUNT_KEY, () -> new AlgorithmInitializationException(this, "Sharding count cannot be null."));
int result = Integer.parseInt(String.valueOf(props.getProperty(SHARDING_COUNT_KEY)));
ShardingSpherePreconditions.checkState(result > 0, () -> new AlgorithmInitializationException(this, "Sharding count must be a positive integer."));
return result;
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java
index ab18d88..08c69a9 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/mod/ModShardingAlgorithm.java
@@ -65,7 +65,7 @@
}
private int getShardingCount(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_COUNT_KEY), () -> new AlgorithmInitializationException(this, "Sharding count can not be null."));
+ ShardingSpherePreconditions.checkContainsKey(props, SHARDING_COUNT_KEY, () -> new AlgorithmInitializationException(this, "Sharding count can not be null."));
int result = Integer.parseInt(String.valueOf(props.getProperty(SHARDING_COUNT_KEY)));
ShardingSpherePreconditions.checkState(result > 0, () -> new AlgorithmInitializationException(this, "Sharding count must be a positive integer."));
return result;
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java
index 9adcdac..01686e4 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/BoundaryBasedRangeShardingAlgorithm.java
@@ -38,7 +38,7 @@
@Override
public Map<Integer, Range<Comparable<?>>> calculatePartitionRange(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_RANGES_KEY), () -> new AlgorithmInitializationException(this, "Sharding ranges cannot be null."));
+ ShardingSpherePreconditions.checkContainsKey(props, SHARDING_RANGES_KEY, () -> new AlgorithmInitializationException(this, "Sharding ranges cannot be null."));
List<Long> partitionRanges = Splitter.on(",").trimResults().splitToList(props.getProperty(SHARDING_RANGES_KEY)).stream()
.map(this::parseLong).filter(Objects::nonNull).sorted().collect(Collectors.toList());
ShardingSpherePreconditions.checkNotEmpty(partitionRanges, () -> new AlgorithmInitializationException(this, "Sharding ranges can not be empty."));
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java
index 7dc3571..ff0f2fb 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/range/VolumeBasedRangeShardingAlgorithm.java
@@ -40,9 +40,9 @@
@Override
public Map<Integer, Range<Comparable<?>>> calculatePartitionRange(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(RANGE_LOWER_KEY), () -> new AlgorithmInitializationException(this, "Lower range cannot be null."));
- ShardingSpherePreconditions.checkState(props.containsKey(RANGE_UPPER_KEY), () -> new AlgorithmInitializationException(this, "Upper range cannot be null."));
- ShardingSpherePreconditions.checkState(props.containsKey(SHARDING_VOLUME_KEY), () -> new AlgorithmInitializationException(this, "Sharding volume cannot be null."));
+ ShardingSpherePreconditions.checkContainsKey(props, RANGE_LOWER_KEY, () -> new AlgorithmInitializationException(this, "Lower range cannot be null."));
+ ShardingSpherePreconditions.checkContainsKey(props, RANGE_UPPER_KEY, () -> new AlgorithmInitializationException(this, "Upper range cannot be null."));
+ ShardingSpherePreconditions.checkContainsKey(props, SHARDING_VOLUME_KEY, () -> new AlgorithmInitializationException(this, "Sharding volume cannot be null."));
long lower = Long.parseLong(props.getProperty(RANGE_LOWER_KEY));
long upper = Long.parseLong(props.getProperty(RANGE_UPPER_KEY));
long volume = Long.parseLong(props.getProperty(SHARDING_VOLUME_KEY));
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
index 21675c0..f34d911 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/ShardingRuleConfigurationChecker.java
@@ -101,7 +101,7 @@
return;
}
ShardingSpherePreconditions.checkNotEmpty(keyGenerateStrategy.getColumn(), () -> new MissingRequiredShardingConfigurationException("Key generate column", databaseName));
- ShardingSpherePreconditions.checkState(keyGenerators.contains(keyGenerateStrategy.getKeyGeneratorName()),
+ ShardingSpherePreconditions.checkContains(keyGenerators, keyGenerateStrategy.getKeyGeneratorName(),
() -> new UnregisteredAlgorithmException("Key generate", keyGenerateStrategy.getKeyGeneratorName(), new SQLExceptionIdentifier(databaseName)));
}
@@ -122,7 +122,7 @@
() -> new MissingRequiredShardingConfigurationException("Complex sharding columns", databaseName));
}
ShardingSpherePreconditions.checkNotNull(shardingStrategy.getShardingAlgorithmName(), () -> new MissingRequiredShardingConfigurationException("Sharding algorithm name", databaseName));
- ShardingSpherePreconditions.checkState(shardingAlgorithms.contains(shardingStrategy.getShardingAlgorithmName()),
+ ShardingSpherePreconditions.checkContains(shardingAlgorithms, shardingStrategy.getShardingAlgorithmName(),
() -> new UnregisteredAlgorithmException("Key generate", shardingStrategy.getShardingAlgorithmName(), new SQLExceptionIdentifier(databaseName)));
}
diff --git a/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java b/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
index df0097f..c017743 100644
--- a/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
+++ b/infra/algorithm/load-balancer/type/weight/src/main/java/org/apache/shardingsphere/infra/algorithm/loadbalancer/weight/WeightLoadBalanceAlgorithm.java
@@ -60,7 +60,7 @@
@Override
public void check(final String databaseName, final Collection<String> configuredTargetNames) {
- weightConfigMap.keySet().forEach(each -> ShardingSpherePreconditions.checkState(configuredTargetNames.contains(each),
+ weightConfigMap.keySet().forEach(each -> ShardingSpherePreconditions.checkContains(configuredTargetNames, each,
() -> new AlgorithmInitializationException(this, "Target `%s` is required in database `%s`.", each, databaseName)));
}
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java
index d8fe4ca..1d0649d 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/from/impl/JoinTableSegmentBinder.java
@@ -148,7 +148,7 @@
}
private static Collection<ProjectionSegment> getProjectionSegmentsByTableAliasOrName(final Map<String, TableSegmentBinderContext> tableBinderContexts, final String tableAliasOrName) {
- ShardingSpherePreconditions.checkState(tableBinderContexts.containsKey(tableAliasOrName.toLowerCase()),
+ ShardingSpherePreconditions.checkContainsKey(tableBinderContexts, tableAliasOrName.toLowerCase(),
() -> new IllegalStateException(String.format("Can not find table binder context by table alias or name %s.", tableAliasOrName)));
return tableBinderContexts.get(tableAliasOrName.toLowerCase()).getProjectionSegments();
}
diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
index a6c56c0..f21f5e5 100644
--- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
+++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/projection/impl/ShorthandProjectionSegmentBinder.java
@@ -59,7 +59,7 @@
}
private static Collection<ProjectionSegment> getProjectionSegmentsByTableAliasOrName(final Map<String, TableSegmentBinderContext> tableBinderContexts, final String tableAliasOrName) {
- ShardingSpherePreconditions.checkState(tableBinderContexts.containsKey(tableAliasOrName.toLowerCase()),
+ ShardingSpherePreconditions.checkContainsKey(tableBinderContexts, tableAliasOrName.toLowerCase(),
() -> new IllegalStateException(String.format("Can not find table binder context by table alias or name %s.", tableAliasOrName)));
return tableBinderContexts.get(tableAliasOrName.toLowerCase()).getProjectionSegments();
}
diff --git a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
index aa46335..bdec1cd 100644
--- a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
+++ b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditions.java
@@ -116,7 +116,7 @@
}
/**
- * Ensures that a collection passed as a parameter to the calling method must empty.
+ * Ensures that a map passed as a parameter to the calling method must empty.
*
* @param <T> type of exception
* @param map map to be checked
@@ -128,4 +128,49 @@
throw exceptionSupplierIfUnexpected.get();
}
}
+
+ /**
+ * Ensures that a collection passed as a parameter to the calling method must contain element.
+ *
+ * @param <T> type of exception
+ * @param values values to be checked
+ * @param element element to be checked
+ * @param exceptionSupplierIfUnexpected exception from this supplier will be thrown if expression is unexpected
+ * @throws T exception to be thrown
+ */
+ public static <T extends Throwable> void checkContains(final Collection<?> values, final Object element, final Supplier<T> exceptionSupplierIfUnexpected) throws T {
+ if (!values.contains(element)) {
+ throw exceptionSupplierIfUnexpected.get();
+ }
+ }
+
+ /**
+ * Ensures that a collection passed as a parameter to the calling method must not contain element.
+ *
+ * @param <T> type of exception
+ * @param values values to be checked
+ * @param element element to be checked
+ * @param exceptionSupplierIfUnexpected exception from this supplier will be thrown if expression is unexpected
+ * @throws T exception to be thrown
+ */
+ public static <T extends Throwable> void checkNotContains(final Collection<?> values, final Object element, final Supplier<T> exceptionSupplierIfUnexpected) throws T {
+ if (values.contains(element)) {
+ throw exceptionSupplierIfUnexpected.get();
+ }
+ }
+
+ /**
+ * Ensures that a map passed as a parameter to the calling method must contain key.
+ *
+ * @param <T> type of exception
+ * @param map map to be checked
+ * @param key key to be checked
+ * @param exceptionSupplierIfUnexpected exception from this supplier will be thrown if expression is unexpected
+ * @throws T exception to be thrown
+ */
+ public static <T extends Throwable> void checkContainsKey(final Map<?, ?> map, final Object key, final Supplier<T> exceptionSupplierIfUnexpected) throws T {
+ if (!map.containsKey(key)) {
+ throw exceptionSupplierIfUnexpected.get();
+ }
+ }
}
diff --git a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
index 4841749..173ea3e 100644
--- a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
+++ b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/ShardingSpherePreconditionsTest.java
@@ -22,6 +22,7 @@
import java.sql.SQLException;
import java.util.Collections;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
class ShardingSpherePreconditionsTest {
@@ -32,8 +33,8 @@
}
@Test
- void assertCheckStateToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkState(true, SQLException::new);
+ void assertCheckStateToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkState(true, SQLException::new));
}
@Test
@@ -42,8 +43,8 @@
}
@Test
- void assertCheckNotNullToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkNotNull(new Object(), SQLException::new);
+ void assertCheckNotNullToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkNotNull(new Object(), SQLException::new));
}
@Test
@@ -53,8 +54,8 @@
}
@Test
- void assertCheckNotEmptyWithStringToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkNotEmpty("foo", SQLException::new);
+ void assertCheckNotEmptyWithStringToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkNotEmpty("foo", SQLException::new));
}
@Test
@@ -63,8 +64,8 @@
}
@Test
- void assertCheckNotEmptyWithCollectionToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkNotEmpty(Collections.singleton("foo"), SQLException::new);
+ void assertCheckNotEmptyWithCollectionToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkNotEmpty(Collections.singleton("foo"), SQLException::new));
}
@Test
@@ -73,8 +74,8 @@
}
@Test
- void assertCheckNotEmptyWithMapToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkNotEmpty(Collections.singletonMap("key", "value"), SQLException::new);
+ void assertCheckNotEmptyWithMapToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkNotEmpty(Collections.singletonMap("key", "value"), SQLException::new));
}
@Test
@@ -83,8 +84,8 @@
}
@Test
- void assertCheckMustEmptyWithCollectionToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkMustEmpty(Collections.emptyList(), SQLException::new);
+ void assertCheckMustEmptyWithCollectionToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkMustEmpty(Collections.emptyList(), SQLException::new));
}
@Test
@@ -93,7 +94,37 @@
}
@Test
- void assertCheckMustEmptyWithMapToNotThrowException() throws SQLException {
- ShardingSpherePreconditions.checkMustEmpty(Collections.emptyMap(), SQLException::new);
+ void assertCheckMustEmptyWithMapToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkMustEmpty(Collections.emptyMap(), SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkContains(Collections.singleton("foo"), "foo", SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsToThrowsException() {
+ assertThrows(SQLException.class, () -> ShardingSpherePreconditions.checkContains(Collections.singleton("foo"), "bar", SQLException::new));
+ }
+
+ @Test
+ void assertCheckNotContainsToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkNotContains(Collections.singleton("foo"), "bar", SQLException::new));
+ }
+
+ @Test
+ void assertCheckNotContainsToThrowsException() {
+ assertThrows(SQLException.class, () -> ShardingSpherePreconditions.checkNotContains(Collections.singleton("foo"), "foo", SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsKeyToNotThrowException() {
+ assertDoesNotThrow(() -> ShardingSpherePreconditions.checkContainsKey(Collections.singletonMap("foo", "value"), "foo", SQLException::new));
+ }
+
+ @Test
+ void assertCheckContainsKeyToThrowsException() {
+ assertThrows(SQLException.class, () -> ShardingSpherePreconditions.checkContainsKey(Collections.singletonMap("foo", "value"), "bar", SQLException::new));
}
}
diff --git a/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java b/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
index 976612c..6edfed0 100644
--- a/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
+++ b/infra/expr/type/interval/src/main/java/org/apache/shardingsphere/infra/expr/interval/IntervalInlineExpressionParser.java
@@ -115,20 +115,17 @@
}
private String getPrefix(final Map<String, String> props) {
- ShardingSpherePreconditions.checkState(props.containsKey(PREFIX_KEY),
- () -> new RuntimeException(String.format("%s can not be null.", PREFIX_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, PREFIX_KEY, () -> new RuntimeException(String.format("%s can not be null.", PREFIX_KEY)));
return props.get(PREFIX_KEY);
}
private TemporalAccessor getDateTimeLower(final Map<String, String> props) {
- ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_LOWER_KEY),
- () -> new RuntimeException(String.format("%s can not be null.", DATE_TIME_LOWER_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, DATE_TIME_LOWER_KEY, () -> new RuntimeException(String.format("%s can not be null.", DATE_TIME_LOWER_KEY)));
return getDateTime(props.get(DATE_TIME_LOWER_KEY));
}
private TemporalAccessor getDateTimeUpper(final Map<String, String> props) {
- ShardingSpherePreconditions.checkState(props.containsKey(DATE_TIME_UPPER_KEY),
- () -> new RuntimeException(String.format("%s can not be null.", DATE_TIME_UPPER_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, DATE_TIME_UPPER_KEY, () -> new RuntimeException(String.format("%s can not be null.", DATE_TIME_UPPER_KEY)));
return getDateTime(props.get(DATE_TIME_UPPER_KEY));
}
@@ -144,14 +141,12 @@
}
private int getStepAmount(final Map<String, String> props) {
- ShardingSpherePreconditions.checkState(props.containsKey(INTERVAL_AMOUNT_KEY),
- () -> new RuntimeException(String.format("%s can not be null.", INTERVAL_AMOUNT_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, INTERVAL_AMOUNT_KEY, () -> new RuntimeException(String.format("%s can not be null.", INTERVAL_AMOUNT_KEY)));
return Integer.parseInt(props.get(INTERVAL_AMOUNT_KEY));
}
private ChronoUnit getStepUnit(final Map<String, String> props) {
- ShardingSpherePreconditions.checkState(props.containsKey(INTERVAL_UNIT_KEY),
- () -> new RuntimeException(String.format("%s can not be null.", INTERVAL_UNIT_KEY)));
+ ShardingSpherePreconditions.checkContainsKey(props, INTERVAL_UNIT_KEY, () -> new RuntimeException(String.format("%s can not be null.", INTERVAL_UNIT_KEY)));
String stepUnit = props.get(INTERVAL_UNIT_KEY);
return Arrays.stream(ChronoUnit.values())
.filter(chronoUnit -> chronoUnit.toString().equals(stepUnit))
diff --git a/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java b/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
index 5ecdff7..b4310c5 100644
--- a/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
+++ b/infra/merge/src/main/java/org/apache/shardingsphere/infra/merge/result/impl/memory/MemoryMergedResult.java
@@ -74,7 +74,7 @@
@Override
public final Object getValue(final int columnIndex, final Class<?> type) throws SQLException {
- ShardingSpherePreconditions.checkState(!INVALID_MEMORY_TYPES.contains(type), () -> new SQLFeatureNotSupportedException(String.format("Get value from `%s`", type.getName())));
+ ShardingSpherePreconditions.checkNotContains(INVALID_MEMORY_TYPES, type, () -> new SQLFeatureNotSupportedException(String.format("Get value from `%s`", type.getName())));
Object result = currentResultSetRow.getCell(columnIndex);
wasNull = null == result;
return result;
diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java
index e62fc84..c22d898 100644
--- a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java
+++ b/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java
@@ -110,8 +110,8 @@
try (TableDataConsistencyChecker checker = TableDataConsistencyCheckerFactory.newInstance(param.getAlgorithmTypeName(), param.getAlgorithmProps())) {
supportedDatabaseTypes = checker.getSupportedDatabaseTypes();
}
- ShardingSpherePreconditions.checkState(supportedDatabaseTypes.contains(param.getSourceDatabaseType()), () -> new UnsupportedPipelineDatabaseTypeException(param.getSourceDatabaseType()));
- ShardingSpherePreconditions.checkState(supportedDatabaseTypes.contains(param.getTargetDatabaseType()), () -> new UnsupportedPipelineDatabaseTypeException(param.getTargetDatabaseType()));
+ ShardingSpherePreconditions.checkContains(supportedDatabaseTypes, param.getSourceDatabaseType(), () -> new UnsupportedPipelineDatabaseTypeException(param.getSourceDatabaseType()));
+ ShardingSpherePreconditions.checkContains(supportedDatabaseTypes, param.getTargetDatabaseType(), () -> new UnsupportedPipelineDatabaseTypeException(param.getTargetDatabaseType()));
}
private YamlConsistencyCheckJobConfiguration getYamlConfiguration(final String jobId, final String parentJobId, final CreateConsistencyCheckJobParameter param) {
diff --git a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java
index 8b8d624..5e2ff99 100644
--- a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java
+++ b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java
@@ -134,7 +134,7 @@
if (configSources.containsKey(dataSourceName)) {
continue;
}
- ShardingSpherePreconditions.checkState(metaDataDataSource.containsKey(dataSourceName),
+ ShardingSpherePreconditions.checkContainsKey(metaDataDataSource, dataSourceName,
() -> new PipelineInvalidParameterException(dataSourceName + " doesn't exist. Run `SHOW MIGRATION SOURCE STORAGE UNITS;` to verify it."));
Map<String, Object> sourceDataSourcePoolProps = dataSourceConfigSwapper.swapToMap(metaDataDataSource.get(dataSourceName));
StandardPipelineDataSourceConfiguration sourceDataSourceConfig = new StandardPipelineDataSourceConfiguration(sourceDataSourcePoolProps);
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
index 21b5076..34182d0 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/decorator/SingleRuleConfigurationDecorator.java
@@ -127,7 +127,7 @@
final Collection<DataNode> configuredDataNodes) {
Collection<String> result = new LinkedHashSet<>();
for (DataNode each : configuredDataNodes) {
- ShardingSpherePreconditions.checkState(actualDataNodes.containsKey(each.getTableName()), () -> new SingleTableNotFoundException(getTableNodeString(isSchemaSupportedDatabaseType, each)));
+ ShardingSpherePreconditions.checkContainsKey(actualDataNodes, each.getTableName(), () -> new SingleTableNotFoundException(getTableNodeString(isSchemaSupportedDatabaseType, each)));
DataNode actualDataNode = actualDataNodes.get(each.getTableName()).iterator().next();
String tableNodeStr = getTableNodeString(isSchemaSupportedDatabaseType, actualDataNode);
ShardingSpherePreconditions.checkState(actualDataNode.equals(each),
@@ -155,12 +155,11 @@
private void checkRuleConfiguration(final String databaseName, final Map<String, DataSource> dataSources, final Collection<String> excludedTables, final Collection<DataNode> dataNodes) {
for (DataNode each : dataNodes) {
if (!SingleTableConstants.ASTERISK.equals(each.getDataSourceName())) {
- ShardingSpherePreconditions.checkState(dataSources.containsKey(each.getDataSourceName()),
+ ShardingSpherePreconditions.checkContainsKey(dataSources, each.getDataSourceName(),
() -> new InvalidSingleRuleConfigurationException(String.format("Data source `%s` does not exist in database `%s`", each.getDataSourceName(), databaseName)));
}
- ShardingSpherePreconditions.checkState(!excludedTables.contains(each.getTableName()),
- () -> new InvalidSingleRuleConfigurationException(String.format("Table `%s` existed and is not a single table in database `%s`",
- each.getTableName(), databaseName)));
+ ShardingSpherePreconditions.checkNotContains(excludedTables, each.getTableName(),
+ () -> new InvalidSingleRuleConfigurationException(String.format("Table `%s` existed and is not a single table in database `%s`", each.getTableName(), databaseName)));
}
}
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
index a10465d..5e9263b 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
@@ -95,7 +95,7 @@
}
private void checkStorageUnits(final LoadSingleTableStatement sqlStatement) {
- ShardingSpherePreconditions.checkState(!database.getResourceMetaData().getStorageUnits().isEmpty(), () -> new EmptyStorageUnitException(database.getName()));
+ ShardingSpherePreconditions.checkNotEmpty(database.getResourceMetaData().getStorageUnits(), () -> new EmptyStorageUnitException(database.getName()));
Collection<String> requiredDataSources = getRequiredDataSources(sqlStatement);
if (requiredDataSources.isEmpty()) {
return;
@@ -104,7 +104,7 @@
Collection<String> logicDataSources = database.getRuleMetaData().getAttributes(DataSourceMapperRuleAttribute.class).stream()
.flatMap(each -> each.getDataSourceMapper().keySet().stream()).collect(Collectors.toSet());
notExistedDataSources.removeIf(logicDataSources::contains);
- ShardingSpherePreconditions.checkState(notExistedDataSources.isEmpty(), () -> new MissingRequiredStorageUnitsException(database.getName(), notExistedDataSources));
+ ShardingSpherePreconditions.checkMustEmpty(notExistedDataSources, () -> new MissingRequiredStorageUnitsException(database.getName(), notExistedDataSources));
}
private void checkActualTableExist(final LoadSingleTableStatement sqlStatement, final String defaultSchemaName) {
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java
index 505bfff..8c3d4e0 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/SetDefaultSingleTableStorageUnitExecutor.java
@@ -48,7 +48,7 @@
private void checkStorageUnitExist(final SetDefaultSingleTableStorageUnitStatement sqlStatement) {
if (!Strings.isNullOrEmpty(sqlStatement.getDefaultStorageUnit())) {
Collection<String> storageUnitNames = database.getResourceMetaData().getStorageUnits().keySet();
- ShardingSpherePreconditions.checkState(storageUnitNames.contains(sqlStatement.getDefaultStorageUnit()),
+ ShardingSpherePreconditions.checkContains(storageUnitNames, sqlStatement.getDefaultStorageUnit(),
() -> new MissingRequiredStorageUnitsException(database.getName(), Collections.singleton(sqlStatement.getDefaultStorageUnit())));
}
}
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
index 98f5c6c..3169289 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/UnloadSingleTableExecutor.java
@@ -80,14 +80,14 @@
}
private void checkIsSingleTable(final Collection<String> singleTables, final String tableName) {
- ShardingSpherePreconditions.checkState(singleTables.contains(tableName), () -> new SingleTableNotFoundException(tableName));
+ ShardingSpherePreconditions.checkContains(singleTables, tableName, () -> new SingleTableNotFoundException(tableName));
}
private void checkTableRuleExist(final String databaseName, final DatabaseType databaseType,
final Collection<DataNode> dataNodes, final String tableName) {
ShardingSpherePreconditions.checkNotEmpty(dataNodes, () -> new MissingRequiredRuleException("Single", databaseName, tableName));
DataNode dataNode = dataNodes.iterator().next();
- ShardingSpherePreconditions.checkState(rule.getConfiguration().getTables().contains(dataNode.format(databaseType)), () -> new MissingRequiredRuleException("Single", databaseName, tableName));
+ ShardingSpherePreconditions.checkContains(rule.getConfiguration().getTables(), dataNode.format(databaseType), () -> new MissingRequiredRuleException("Single", databaseName, tableName));
}
@Override
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
index df26d57..2c846c7 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/SQLFederationResultSet.java
@@ -466,7 +466,7 @@
}
private Object getValue(final int columnIndex, final Class<?> type) throws SQLException {
- ShardingSpherePreconditions.checkState(!INVALID_FEDERATION_TYPES.contains(type), () -> new SQLFeatureNotSupportedException(String.format("Get value from `%s`", type.getName())));
+ ShardingSpherePreconditions.checkNotContains(INVALID_FEDERATION_TYPES, type, () -> new SQLFeatureNotSupportedException(String.format("Get value from `%s`", type.getName())));
Object result = currentRows[columnIndex - 1];
wasNull = null == result;
return columnTypeConverter.convertColumnValue(result);
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
index 5c7bc31..6fbd231 100644
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
+++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLMatchTrafficAlgorithm.java
@@ -42,7 +42,7 @@
@Override
public void init(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(SQL_PROPS_KEY), () -> new AlgorithmInitializationException(this, "%s cannot be null", SQL_PROPS_KEY));
+ ShardingSpherePreconditions.checkContainsKey(props, SQL_PROPS_KEY, () -> new AlgorithmInitializationException(this, "%s cannot be null", SQL_PROPS_KEY));
sql = getExactlySQL(props.getProperty(SQL_PROPS_KEY));
ShardingSpherePreconditions.checkNotEmpty(String.valueOf(sql), () -> new AlgorithmInitializationException(this, "SQL must be not empty"));
}
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
index 2a4631e..dd3a6d1 100644
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
+++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/algorithm/traffic/segment/SQLRegexTrafficAlgorithm.java
@@ -36,7 +36,7 @@
@Override
public void init(final Properties props) {
- ShardingSpherePreconditions.checkState(props.containsKey(REGEX_PROPS_KEY), () -> new AlgorithmInitializationException(this, "%s cannot be null", REGEX_PROPS_KEY));
+ ShardingSpherePreconditions.checkContainsKey(props, REGEX_PROPS_KEY, () -> new AlgorithmInitializationException(this, "%s cannot be null", REGEX_PROPS_KEY));
regex = Pattern.compile(props.getProperty(REGEX_PROPS_KEY));
ShardingSpherePreconditions.checkNotEmpty(String.valueOf(regex), () -> new AlgorithmInitializationException(this, "Regex must be not empty"));
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java
index f590ce5..ca4ef5f 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/RefreshTableMetaDataExecutor.java
@@ -64,8 +64,7 @@
ShardingSpherePreconditions.checkNotEmpty(storageUnits, () -> new EmptyStorageUnitException(database.getName()));
if (sqlStatement.getStorageUnitName().isPresent()) {
String storageUnitName = sqlStatement.getStorageUnitName().get();
- ShardingSpherePreconditions.checkState(
- storageUnits.containsKey(storageUnitName), () -> new MissingRequiredStorageUnitsException(database.getName(), Collections.singleton(storageUnitName)));
+ ShardingSpherePreconditions.checkContainsKey(storageUnits, storageUnitName, () -> new MissingRequiredStorageUnitsException(database.getName(), Collections.singleton(storageUnitName)));
}
}
diff --git a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java
index 61f677d..cc992b4 100644
--- a/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java
+++ b/proxy/backend/type/hbase/src/main/java/org/apache/shardingsphere/proxy/backend/hbase/context/HBaseContext.java
@@ -138,7 +138,7 @@
* @return HBase connection
*/
public Connection getConnection(final String tableName) {
- ShardingSpherePreconditions.checkState(tableConnectionMap.containsKey(tableName), () -> new TableNotFoundException(tableName));
+ ShardingSpherePreconditions.checkContainsKey(tableConnectionMap, tableName, () -> new TableNotFoundException(tableName));
return tableConnectionMap.get(tableName).getConnection();
}