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

yx9o 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 2356d35c26a Add DMLWithMultipleShardingTablesException (#20576)
2356d35c26a is described below

commit 2356d35c26a337044d32f97a52ae1f7b7dc45340
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 23:04:07 2022 +0800

    Add DMLWithMultipleShardingTablesException (#20576)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../DMLWithMultipleShardingTablesException.java    | 35 ++++++++++++++++++++++
 .../dml/ShardingDMLStatementValidator.java         |  4 +--
 .../dml/ShardingDeleteStatementValidatorTest.java  | 12 ++++----
 .../dml/ShardingInsertStatementValidatorTest.java  |  3 +-
 .../dml/ShardingUpdateStatementValidatorTest.java  |  3 +-
 7 files changed, 49 insertions(+), 10 deletions(-)

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 0226d9e8a8b..69bf13b1def 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
@@ -45,6 +45,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | HY000     | 20007       | \`%s %s\` can not route correctly for %s \`%s\` |
 | 42S02     | 20008       | Can not get route result, please check your 
sharding rule configuration |
 | 42S01     | 20009       | View name has to bind to %s tables |
+| 0A000     | 20010       | Can not support DML operation with multiple tables 
\`%s\` |
 | 44000     | 20012       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` are not match |
 | HY004     | 20013       | Found different types for sharding value \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
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 2954f954753..891244867ed 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
@@ -45,6 +45,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | HY000     | 20007       | \`%s %s\` can not route correctly for %s \`%s\` |
 | 42S02     | 20008       | Can not get route result, please check your 
sharding rule configuration |
 | 42S01     | 20009       | View name has to bind to %s tables |
+| 0A000     | 20010       | Can not support DML operation with multiple tables 
\`%s\` |
 | 44000     | 20012       | Inline sharding algorithms expression \`%s\` and 
sharding column \`%s\` are not match |
 | HY004     | 20013       | Found different types for sharding value \`%s\` |
 | HY004     | 24000       | Encrypt algorithm \`%s\` initialize failed, reason 
is: %s |
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DMLWithMultipleShardingTablesException.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DMLWithMultipleShardingTablesException.java
new file mode 100644
index 00000000000..a4123f7bed7
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/DMLWithMultipleShardingTablesException.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.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+import java.util.Collection;
+
+/**
+ * DML with multiple sharding tables exception.
+ */
+public final class DMLWithMultipleShardingTablesException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = -7368310216924145478L;
+    
+    public DMLWithMultipleShardingTablesException(final Collection<String> 
tableNames) {
+        super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 20002, "Can not support DML 
operation with multiple tables `%s`", tableNames.toString());
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java
index a540b0b53f9..06b430e8464 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDMLStatementValidator.java
@@ -18,10 +18,10 @@
 package org.apache.shardingsphere.sharding.route.engine.validator.dml;
 
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 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.DMLWithMultipleShardingTablesException;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.value.ListShardingConditionValue;
@@ -58,7 +58,7 @@ public abstract class ShardingDMLStatementValidator<T extends 
SQLStatement> impl
         boolean isAllBroadcastTables = 
shardingRule.isAllBroadcastTables(tableNames);
         boolean isAllSingleTables = !shardingRule.tableRuleExists(tableNames);
         if (!(isAllShardingTables || isAllBroadcastTables || 
isAllSingleTables)) {
-            throw new ShardingSphereException("Cannot support Multiple-Table 
for '%s'.", tableNames);
+            throw new DMLWithMultipleShardingTablesException(tableNames);
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java
index e07e27c6e0c..c36acea92d3 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingDeleteStatementValidatorTest.java
@@ -18,8 +18,8 @@
 package org.apache.shardingsphere.sharding.route.engine.validator.dml;
 
 import 
org.apache.shardingsphere.infra.binder.statement.dml.DeleteStatementContext;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.sharding.exception.DMLWithMultipleShardingTablesException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingDeleteStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.DeleteMultiTableSegment;
@@ -51,27 +51,27 @@ public final class ShardingDeleteStatementValidatorTest {
     @Mock
     private ShardingRule shardingRule;
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = DMLWithMultipleShardingTablesException.class)
     public void assertPreValidateWhenDeleteMultiTablesForMySQL() {
         assertPreValidateWhenDeleteMultiTables(new MySQLDeleteStatement());
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = DMLWithMultipleShardingTablesException.class)
     public void assertPreValidateWhenDeleteMultiTablesForOracle() {
         assertPreValidateWhenDeleteMultiTables(new OracleDeleteStatement());
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = DMLWithMultipleShardingTablesException.class)
     public void assertPreValidateWhenDeleteMultiTablesForPostgreSQL() {
         assertPreValidateWhenDeleteMultiTables(new 
PostgreSQLDeleteStatement());
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = DMLWithMultipleShardingTablesException.class)
     public void assertPreValidateWhenDeleteMultiTablesForSQL92() {
         assertPreValidateWhenDeleteMultiTables(new SQL92DeleteStatement());
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = DMLWithMultipleShardingTablesException.class)
     public void assertPreValidateWhenDeleteMultiTablesForSQLServer() {
         assertPreValidateWhenDeleteMultiTables(new SQLServerDeleteStatement());
     }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
index 3ef044a4e80..110656c277b 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
@@ -32,6 +32,7 @@ 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.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.exception.DMLWithMultipleShardingTablesException;
 import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
 import 
org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingInsertStatementValidator;
@@ -81,7 +82,7 @@ public final class ShardingInsertStatementValidatorTest {
     @Mock
     private ShardingConditions shardingConditions;
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = DMLWithMultipleShardingTablesException.class)
     public void assertPreValidateWhenInsertMultiTables() {
         SQLStatementContext<InsertStatement> sqlStatementContext = 
createInsertStatementContext(Collections.singletonList(1), 
createInsertStatement());
         Collection<String> tableNames = 
sqlStatementContext.getTablesContext().getTableNames();
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
index 306967f4b5a..c7621f85911 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingUpdateStatementValidatorTest.java
@@ -27,6 +27,7 @@ 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.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
+import 
org.apache.shardingsphere.sharding.exception.DMLWithMultipleShardingTablesException;
 import org.apache.shardingsphere.sharding.factory.ShardingAlgorithmFactory;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingUpdateStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -77,7 +78,7 @@ public final class ShardingUpdateStatementValidatorTest {
         new ShardingUpdateStatementValidator().preValidate(shardingRule, 
sqlStatementContext, Collections.emptyList(), 
mock(ShardingSphereDatabase.class));
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = DMLWithMultipleShardingTablesException.class)
     public void assertPreValidateWhenUpdateMultipleTables() {
         UpdateStatement updateStatement = createUpdateStatement();
         JoinTableSegment joinTableSegment = new JoinTableSegment();

Reply via email to