This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 2cb8c5c delete useless SingleTableRuleConfigurationChecker (#12222)
2cb8c5c is described below
commit 2cb8c5c20f7149ec31ad28e164b5f19b0c4069e1
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Sat Sep 4 22:22:32 2021 +0800
delete useless SingleTableRuleConfigurationChecker (#12222)
---
.../checker/RuleConfigurationCheckerFactory.java | 7 +++---
.../TestRuleConfigurationWithoutChecker.java | 26 ++++------------------
.../RuleConfigurationCheckerFactoryTest.java | 18 +++++++++++----
...ere.infra.rule.checker.RuleConfigurationChecker | 18 ---------------
.../service/impl/SchemaRulePersistService.java | 10 ++++-----
5 files changed, 26 insertions(+), 53 deletions(-)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/checker/RuleConfigurationCheckerFactory.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/checker/RuleConfigurationCheckerFactory.java
index dce9574..bdaf9f1 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/checker/RuleConfigurationCheckerFactory.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/rule/checker/RuleConfigurationCheckerFactory.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.infra.rule.checker;
-import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -26,6 +25,7 @@ import
org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
import java.util.Collections;
import java.util.Map;
+import java.util.Optional;
/**
* Rule configuration checker factory.
@@ -44,9 +44,8 @@ public final class RuleConfigurationCheckerFactory {
* @return new instance of rule configuration checker
*/
@SuppressWarnings("rawtypes")
- public static RuleConfigurationChecker newInstance(final RuleConfiguration
config) {
+ public static Optional<RuleConfigurationChecker> newInstance(final
RuleConfiguration config) {
Map<Class<?>, RuleConfigurationChecker> checkers =
OrderedSPIRegistry.getRegisteredServicesByClass(RuleConfigurationChecker.class,
Collections.singleton(config.getClass()));
- Preconditions.checkArgument(checkers.containsKey(config.getClass()),
"Can not find rule configuration checker for rule type: `%s`",
config.getClass());
- return checkers.get(config.getClass());
+ return Optional.ofNullable(checkers.get(config.getClass()));
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/checker/SingleTableRuleConfigurationChecker.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestRuleConfigurationWithoutChecker.java
similarity index 51%
rename from
shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/checker/SingleTableRuleConfigurationChecker.java
rename to
shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestRuleConfigurationWithoutChecker.java
index 468fba3..bfe66e8 100644
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/checker/SingleTableRuleConfigurationChecker.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/TestRuleConfigurationWithoutChecker.java
@@ -15,28 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.singletable.rule.checker;
+package org.apache.shardingsphere.infra.rule.fixture;
-import
org.apache.shardingsphere.singletable.config.SingleTableRuleConfiguration;
-import org.apache.shardingsphere.infra.constant.SingleTableOrder;
-import org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import
org.apache.shardingsphere.infra.config.function.EnhancedRuleConfiguration;
-/**
- * Single table rule configuration checker.
- */
-public final class SingleTableRuleConfigurationChecker implements
RuleConfigurationChecker<SingleTableRuleConfiguration> {
-
- @Override
- public void check(final String schemaName, final
SingleTableRuleConfiguration config) {
- }
-
- @Override
- public int getOrder() {
- return SingleTableOrder.ORDER;
- }
-
- @Override
- public Class<SingleTableRuleConfiguration> getTypeClass() {
- return SingleTableRuleConfiguration.class;
- }
+public final class TestRuleConfigurationWithoutChecker implements
RuleConfiguration, EnhancedRuleConfiguration {
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFactoryTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFactoryTest.java
index 35dbee9..d628ef7 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFactoryTest.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/rule/fixture/checker/RuleConfigurationCheckerFactoryTest.java
@@ -20,16 +20,26 @@ package
org.apache.shardingsphere.infra.rule.fixture.checker;
import org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker;
import
org.apache.shardingsphere.infra.rule.checker.RuleConfigurationCheckerFactory;
import org.apache.shardingsphere.infra.rule.fixture.TestRuleConfiguration;
+import
org.apache.shardingsphere.infra.rule.fixture.TestRuleConfigurationWithoutChecker;
import org.junit.Test;
+
+import java.util.Optional;
+
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
public final class RuleConfigurationCheckerFactoryTest {
@Test
public void assertNewInstance() {
- RuleConfigurationChecker<?> checker =
RuleConfigurationCheckerFactory.newInstance(new TestRuleConfiguration());
- assertNotNull(checker);
- assertTrue(checker instanceof RuleConfigurationCheckerFixture);
+ Optional<RuleConfigurationChecker> checker =
RuleConfigurationCheckerFactory.newInstance(new TestRuleConfiguration());
+ assertTrue(checker.isPresent());
+ assertTrue(checker.get() instanceof RuleConfigurationCheckerFixture);
+ }
+
+ @Test
+ public void assertNewInstanceWithoutChecker() {
+ Optional<RuleConfigurationChecker> checker =
RuleConfigurationCheckerFactory.newInstance(new
TestRuleConfigurationWithoutChecker());
+ assertFalse(checker.isPresent());
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker
b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker
deleted file mode 100644
index 3c5fffc..0000000
---
a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-org.apache.shardingsphere.singletable.rule.checker.SingleTableRuleConfigurationChecker
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/service/impl/SchemaRulePersistService.java
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/service/impl/SchemaRulePersistService.java
index 323c327..b469afe 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/service/impl/SchemaRulePersistService.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/service/impl/SchemaRulePersistService.java
@@ -19,14 +19,14 @@ package org.apache.shardingsphere.mode.persist.service.impl;
import com.google.common.base.Strings;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.mode.persist.node.SchemaMetadataNode;
-import
org.apache.shardingsphere.mode.persist.service.SchemaBasedPersistService;
-import org.apache.shardingsphere.mode.persist.PersistRepository;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import
org.apache.shardingsphere.infra.rule.checker.RuleConfigurationCheckerFactory;
import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRuleConfiguration;
-import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
import
org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.apache.shardingsphere.mode.persist.node.SchemaMetadataNode;
+import
org.apache.shardingsphere.mode.persist.service.SchemaBasedPersistService;
import java.util.Collection;
import java.util.LinkedList;
@@ -55,7 +55,7 @@ public final class SchemaRulePersistService implements
SchemaBasedPersistService
private Collection<YamlRuleConfiguration>
createYamlRuleConfigurations(final String schemaName, final
Collection<RuleConfiguration> ruleConfigs) {
Collection<RuleConfiguration> configs = new LinkedList<>();
for (RuleConfiguration each : ruleConfigs) {
-
RuleConfigurationCheckerFactory.newInstance(each).check(schemaName, each);
+
RuleConfigurationCheckerFactory.newInstance(each).ifPresent(checker ->
checker.check(schemaName, each));
configs.add(each);
}
return new
YamlRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(configs);