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/09/04 11:34:04 UTC

[shardingsphere] branch master updated: Add DataSourceIntersectionNotFoundException (#20766)

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 01a307de5e4 Add DataSourceIntersectionNotFoundException (#20766)
01a307de5e4 is described below

commit 01a307de5e4a49647ccc5df00fd537d6bac1fe4d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Sep 4 19:33:57 2022 +0800

    Add DataSourceIntersectionNotFoundException (#20766)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../DataSourceIntersectionNotFoundException.java   | 35 ++++++++++++++++++++++
 .../type/unicast/ShardingUnicastRoutingEngine.java |  3 +-
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 08e4af85e67..34b9d24c08c 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -64,6 +64,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 44000     | 20020       | Inline sharding algorithms expression \`%s\` and sharding column \`%s\` do not match |
 | 44000     | 20021       | Actual data nodes must be configured for sharding table \`%s\` |
 | 44000     | 20022       | Actual table \`%s.%s\` is not in table rule configuration |
+| 44000     | 20023       | Can not find actual data source intersection for logic tables \`%s\` |
 | 42S01     | 20030       | Index \`%s\` already exists |
 | 42S02     | 20031       | Index \`%s\` does not exist |
 | 44000     | 20032       | Actual tables \`%s\` are in use |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index a02e04bd57d..2db37ab5824 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -64,6 +64,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | 44000     | 20020       | Inline sharding algorithms expression \`%s\` and sharding column \`%s\` do not match |
 | 44000     | 20021       | Actual data nodes must be configured for sharding table \`%s\` |
 | 44000     | 20022       | Actual table \`%s.%s\` is not in table rule configuration |
+| 44000     | 20023       | Can not find actual data source intersection for logic tables \`%s\` |
 | 42S01     | 20030       | Index \`%s\` already exists |
 | 42S02     | 20031       | Index \`%s\` does not exist |
 | 44000     | 20032       | Actual tables \`%s\` are in use |
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DataSourceIntersectionNotFoundException.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DataSourceIntersectionNotFoundException.java
new file mode 100644
index 00000000000..86139e32e9e
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DataSourceIntersectionNotFoundException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.sharding.exception;
+
+import org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+import java.util.Collection;
+
+/**
+ * Data source intersection not found exception.
+ */
+public final class DataSourceIntersectionNotFoundException extends ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = -2142571707728236489L;
+    
+    public DataSourceIntersectionNotFoundException(final Collection<String> logicTables) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 20023, "Can not find actual data source intersection for logic tables `%s`", logicTables);
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java
index 05dbace7dc8..5fc01c82ade 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/unicast/ShardingUnicastRoutingEngine.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteMapper;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.sharding.exception.DataSourceIntersectionNotFoundException;
 import org.apache.shardingsphere.sharding.route.engine.type.ShardingRouteEngine;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -97,7 +98,7 @@ public final class ShardingUnicastRoutingEngine implements ShardingRouteEngine {
             }
         }
         if (availableDataSourceNames.isEmpty()) {
-            throw new ShardingSphereConfigurationException("Cannot find actual datasource intersection for logic tables: %s", logicTables.toArray(new String[0]));
+            throw new DataSourceIntersectionNotFoundException(logicTables);
         }
         String dataSourceName = getRandomDataSourceName(availableDataSourceNames);
         routeContext.getRouteUnits().add(new RouteUnit(new RouteMapper(dataSourceName, dataSourceName), tableMappers));