You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/06/25 14:25:42 UTC

[shardingsphere] branch master updated: Remove ResourceRequiredRuleConfiguration to keep API clean (#18589)

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 8118813385d Remove ResourceRequiredRuleConfiguration to keep API clean (#18589)
8118813385d is described below

commit 8118813385d2b4d11bd69e42c4d1a3cd16b8e904
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Jun 25 22:25:37 2022 +0800

    Remove ResourceRequiredRuleConfiguration to keep API clean (#18589)
---
 .../shadow/api/config/ShadowRuleConfiguration.java | 11 +------
 .../api/config/ShardingRuleConfiguration.java      | 18 +-----------
 .../checker/ShardingTableRuleStatementChecker.java | 13 +++++++--
 .../ResourceRequiredRuleConfiguration.java         | 34 ----------------------
 4 files changed, 13 insertions(+), 63 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java
index 596f65fb9a8..9daadd464bc 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-api/src/main/java/org/apache/shardingsphere/shadow/api/config/ShadowRuleConfiguration.java
@@ -21,23 +21,19 @@ import lombok.Getter;
 import lombok.Setter;
 import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.function.DistributedRuleConfiguration;
-import org.apache.shardingsphere.infra.config.function.ResourceRequiredRuleConfiguration;
 import org.apache.shardingsphere.infra.config.scope.DatabaseRuleConfiguration;
 import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
 import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
 
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * Shadow rule configuration.
  */
 @Getter
 @Setter
-public final class ShadowRuleConfiguration implements DatabaseRuleConfiguration, DistributedRuleConfiguration, ResourceRequiredRuleConfiguration {
+public final class ShadowRuleConfiguration implements DatabaseRuleConfiguration, DistributedRuleConfiguration {
     
     private String defaultShadowAlgorithmName;
     
@@ -46,9 +42,4 @@ public final class ShadowRuleConfiguration implements DatabaseRuleConfiguration,
     private Map<String, ShadowTableConfiguration> tables = new LinkedHashMap<>();
     
     private Map<String, ShardingSphereAlgorithmConfiguration> shadowAlgorithms = new LinkedHashMap<>();
-    
-    @Override
-    public Collection<String> getRequiredResource() {
-        return dataSources.values().stream().map(each -> Arrays.asList(each.getSourceDataSourceName(), each.getShadowDataSourceName())).flatMap(Collection::stream).collect(Collectors.toSet());
-    }
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
index 60ad9125258..ee7e5e460ed 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-api/src/main/java/org/apache/shardingsphere/sharding/api/config/ShardingRuleConfiguration.java
@@ -17,34 +17,28 @@
 
 package org.apache.shardingsphere.sharding.api.config;
 
-import com.google.common.base.Splitter;
 import lombok.Getter;
 import lombok.Setter;
 import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.function.DistributedRuleConfiguration;
-import org.apache.shardingsphere.infra.config.function.ResourceRequiredRuleConfiguration;
 import org.apache.shardingsphere.infra.config.rulealtered.OnRuleAlteredActionConfiguration;
 import org.apache.shardingsphere.infra.config.scope.DatabaseRuleConfiguration;
-import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
 import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
-import org.apache.shardingsphere.infra.expr.InlineExpressionParser;
 
 import java.util.Collection;
 import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 /**
  * Sharding rule configuration.
  */
 @Getter
 @Setter
-public final class ShardingRuleConfiguration implements DatabaseRuleConfiguration, DistributedRuleConfiguration, ResourceRequiredRuleConfiguration {
+public final class ShardingRuleConfiguration implements DatabaseRuleConfiguration, DistributedRuleConfiguration {
     
     private Collection<ShardingTableRuleConfiguration> tables = new LinkedList<>();
     
@@ -69,14 +63,4 @@ public final class ShardingRuleConfiguration implements DatabaseRuleConfiguratio
     private String scalingName;
     
     private Map<String, OnRuleAlteredActionConfiguration> scaling = new LinkedHashMap<>();
-    
-    @Override
-    public Collection<String> getRequiredResource() {
-        Collection<String> result = new LinkedHashSet<>();
-        result.addAll(autoTables.stream().map(ShardingAutoTableRuleConfiguration::getActualDataSources)
-                .map(each -> Splitter.on(",").trimResults().splitToList(each)).flatMap(Collection::stream).collect(Collectors.toSet()));
-        result.addAll(tables.stream().map(each -> new InlineExpressionParser(each.getActualDataNodes()).splitAndEvaluate())
-                .flatMap(Collection::stream).distinct().map(each -> new DataNode(each).getDataSourceName()).collect(Collectors.toSet()));
-        return result;
-    }
 }
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
index fd7791bdcfe..fa5360110f5 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/checker/ShardingTableRuleStatementChecker.java
@@ -327,12 +327,21 @@ public final class ShardingTableRuleStatementChecker {
         toBeCheckedRuleConfig.setScaling(currentRuleConfig.getScaling());
         removeRuleConfiguration(toBeCheckedRuleConfig, toBeAlteredRuleConfig);
         addRuleConfiguration(toBeCheckedRuleConfig, toBeAlteredRuleConfig);
-        Collection<String> dataSourceNames = toBeCheckedRuleConfig.getRequiredResource();
-        dataSourceNames.addAll(toBeAlteredRuleConfig.getRequiredResource());
+        Collection<String> dataSourceNames = getRequiredResource(toBeCheckedRuleConfig);
+        dataSourceNames.addAll(getRequiredResource(toBeAlteredRuleConfig));
         DistSQLException.predictionThrow(check(toBeCheckedRuleConfig, dataSourceNames),
                 () -> new InvalidRuleConfigurationException("sharding table", toBeAlteredLogicTableNames, Collections.singleton("invalid binding table configuration")));
     }
     
+    private static Collection<String> getRequiredResource(final ShardingRuleConfiguration config) {
+        Collection<String> result = new LinkedHashSet<>();
+        result.addAll(config.getAutoTables().stream().map(ShardingAutoTableRuleConfiguration::getActualDataSources)
+                .map(each -> Splitter.on(",").trimResults().splitToList(each)).flatMap(Collection::stream).collect(Collectors.toSet()));
+        result.addAll(config.getTables().stream().map(each -> new InlineExpressionParser(each.getActualDataNodes()).splitAndEvaluate())
+                .flatMap(Collection::stream).distinct().map(each -> new DataNode(each).getDataSourceName()).collect(Collectors.toSet()));
+        return result;
+    }
+    
     private static boolean isValidBindingTableConfiguration(final Map<String, TableRule> tableRules, final BindingTableCheckedConfiguration checkedConfig) {
         for (String each : checkedConfig.getBindingTableGroups()) {
             Collection<String> bindingTables = Splitter.on(",").trimResults().splitToList(each.toLowerCase());
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/function/ResourceRequiredRuleConfiguration.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/function/ResourceRequiredRuleConfiguration.java
deleted file mode 100644
index 71a12525637..00000000000
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/function/ResourceRequiredRuleConfiguration.java
+++ /dev/null
@@ -1,34 +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.
- */
-
-package org.apache.shardingsphere.infra.config.function;
-
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-
-import java.util.Collection;
-
-/**
- * Resource Required rule configuration.
- */
-public interface ResourceRequiredRuleConfiguration extends RuleConfiguration {
-    
-    /**
-     * Get Required Resource.
-     * @return required resource names
-     */
-    Collection<String> getRequiredResource();
-}