This is an automated email from the ASF dual-hosted git repository.

sunnianjun 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 7451af93ad6 Use UnregisteredAlgorithmException on  
ReadwriteSplittingRuleConfigurationChecker (#30648)
7451af93ad6 is described below

commit 7451af93ad6368eb22cbdb7a5dd31f010f2a670d
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Mar 26 10:58:23 2024 +0800

    Use UnregisteredAlgorithmException on  
ReadwriteSplittingRuleConfigurationChecker (#30648)
---
 .../checker/ReadwriteSplittingRuleConfigurationChecker.java  | 12 ++++++------
 .../core/exception/UnregisteredAlgorithmException.java       |  7 +++++--
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
index 22b7f1653ce..12f02038692 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/checker/ReadwriteSplittingRuleConfigurationChecker.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.readwritesplitting.checker;
 
 import com.google.common.base.Strings;
+import 
org.apache.shardingsphere.infra.algorithm.core.exception.UnregisteredAlgorithmException;
 import 
org.apache.shardingsphere.infra.algorithm.loadbalancer.core.LoadBalanceAlgorithm;
 import 
org.apache.shardingsphere.infra.config.rule.checker.RuleConfigurationChecker;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
@@ -30,7 +31,6 @@ import 
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingD
 import 
org.apache.shardingsphere.readwritesplitting.constant.ReadwriteSplittingOrder;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.DataSourceNameNotExistedException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.DuplicateDataSourceException;
-import 
org.apache.shardingsphere.readwritesplitting.exception.checker.LoadBalancerAlgorithmNotFoundException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredDataSourceNameException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredReadDataSourceNamesException;
 import 
org.apache.shardingsphere.readwritesplitting.exception.checker.MissingRequiredWriteDataSourceNameException;
@@ -86,15 +86,15 @@ public final class 
ReadwriteSplittingRuleConfigurationChecker implements RuleCon
     
     private boolean containsInOtherRules(final String datasourceName, final 
Collection<ShardingSphereRule> builtRules) {
         return builtRules.stream().map(each -> 
each.getAttributes().findAttribute(DataSourceMapperRuleAttribute.class))
-                .anyMatch(ruleAttribute -> ruleAttribute.isPresent() && 
ruleAttribute.get().getDataSourceMapper().containsKey(datasourceName));
+                .anyMatch(optional -> optional.isPresent() && 
optional.get().getDataSourceMapper().containsKey(datasourceName));
     }
     
     private void checkReadeDataSourceNames(final String databaseName, final 
Map<String, DataSource> dataSourceMap,
-                                           final Collection<String> 
addedReadDataSourceNames, final String readDataSourceName, final 
Collection<ShardingSphereRule> rules) {
+                                           final Collection<String> 
readDataSourceNames, final String readDataSourceName, final 
Collection<ShardingSphereRule> builtRules) {
         for (String each : 
InlineExpressionParserFactory.newInstance(readDataSourceName).splitAndEvaluate())
 {
-            
ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each) || 
containsInOtherRules(each, rules),
+            
ShardingSpherePreconditions.checkState(dataSourceMap.containsKey(each) || 
containsInOtherRules(each, builtRules),
                     () -> new 
DataSourceNameNotExistedException(String.format("Read data source name `%s` not 
in database `%s`.", each, databaseName)));
-            
ShardingSpherePreconditions.checkState(addedReadDataSourceNames.add(each),
+            
ShardingSpherePreconditions.checkState(readDataSourceNames.add(each),
                     () -> new DuplicateDataSourceException(String.format("Can 
not config duplicate read data source `%s` in database `%s`.", each, 
databaseName)));
         }
     }
@@ -107,7 +107,7 @@ public final class 
ReadwriteSplittingRuleConfigurationChecker implements RuleCon
                 continue;
             }
             LoadBalanceAlgorithm loadBalancer = 
loadBalancers.get(each.getLoadBalancerName());
-            ShardingSpherePreconditions.checkNotNull(loadBalancer, () -> new 
LoadBalancerAlgorithmNotFoundException(databaseName));
+            ShardingSpherePreconditions.checkNotNull(loadBalancer, () -> new 
UnregisteredAlgorithmException("Load balancer", each.getLoadBalancerName(), 
databaseName));
             loadBalancer.check(databaseName, each.getReadDataSourceNames());
         }
     }
diff --git 
a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/UnregisteredAlgorithmException.java
 
b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/UnregisteredAlgorithmException.java
index fce0c4a17bd..29f25c71a1a 100644
--- 
a/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/UnregisteredAlgorithmException.java
+++ 
b/infra/algorithm/core/src/main/java/org/apache/shardingsphere/infra/algorithm/core/exception/UnregisteredAlgorithmException.java
@@ -27,8 +27,11 @@ public final class UnregisteredAlgorithmException extends 
MetaDataSQLException {
     
     private static final long serialVersionUID = -4570489906443880879L;
     
+    public UnregisteredAlgorithmException(final String algorithmType, final 
String algorithmName, final String databaseName) {
+        super(XOpenSQLState.NOT_FOUND, 13, "'%s' algorithm '%s' on database: 
'%s' is unregistered.", algorithmType, algorithmName, databaseName);
+    }
+    
     public UnregisteredAlgorithmException(final String algorithmType, final 
String algorithmName, final String databaseName, final String tableName, final 
String columnName) {
-        super(XOpenSQLState.NOT_FOUND, 13,
-                "'%s' algorithm '%s' on database.table.column: '%s'.'%s'.'%s' 
is unregistered.", algorithmType, algorithmName, databaseName, tableName, 
columnName);
+        super(XOpenSQLState.NOT_FOUND, 13, "'%s' algorithm '%s' on 
database.table.column: '%s'.'%s'.'%s' is unregistered.", algorithmType, 
algorithmName, databaseName, tableName, columnName);
     }
 }

Reply via email to