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 c1b402a67db Add ShardingRuleNotFoundException (#20548)
c1b402a67db is described below
commit c1b402a67db3eb988499b2ba115db1a0f539cee8
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 14:11:19 2022 +0800
Add ShardingRuleNotFoundException (#20548)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../exception/ShardingRuleNotFoundException.java | 35 ++++++++++++++++++++++
.../type/complex/ShardingComplexRoutingEngine.java | 4 +--
.../complex/ShardingComplexRoutingEngineTest.java | 18 +++++------
5 files changed, 48 insertions(+), 11 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 73ec4e172e3..2739255411a 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
@@ -38,6 +38,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| HY000 | 20000 | Sharding algorithm class \`%s\` should be
implement \`%s\` |
| 44000 | 20001 | Sharding value can't be null in insert statement |
| 44000 | 20002 | Can not get uniformed table structure for logic
table \`%s\`, it has different meta data of actual tables are as follows: %s |
+| 44000 | 20003 | Can not find table rule with logic 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 ebc8692e4b8..8d30bbf62a4 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
@@ -38,6 +38,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| HY000 | 20000 | Sharding algorithm class \`%s\` should be
implement \`%s\` |
| 44000 | 20001 | Sharding value can't be null in insert statement |
| 44000 | 20002 | Can not get uniformed table structure for logic
table \`%s\`, it has different meta data of actual tables are as follows: %s |
+| 44000 | 20003 | Can not find table rule with logic 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/ShardingRuleNotFoundException.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/ShardingRuleNotFoundException.java
new file mode 100644
index 00000000000..96360f1ebee
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/ShardingRuleNotFoundException.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;
+
+/**
+ * Sharding rule not found exception.
+ */
+public final class ShardingRuleNotFoundException extends
ShardingSphereSQLException {
+
+ private static final long serialVersionUID = 142299282103233064L;
+
+ public ShardingRuleNotFoundException(final Collection<String> logicTables)
{
+ super(XOpenSQLState.CHECK_OPTION_VIOLATION, 20003, "Can not find table
rule with logic tables `%s`", logicTables.toString());
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngine.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngine.java
index c67fac3b63a..97080563964 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngine.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngine.java
@@ -19,8 +19,8 @@ package
org.apache.shardingsphere.sharding.route.engine.type.complex;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.route.context.RouteContext;
+import
org.apache.shardingsphere.sharding.exception.ShardingRuleNotFoundException;
import
org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
import
org.apache.shardingsphere.sharding.route.engine.type.ShardingRouteEngine;
import
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine;
@@ -59,7 +59,7 @@ public final class ShardingComplexRoutingEngine implements
ShardingRouteEngine {
}
}
if (routeContexts.isEmpty()) {
- throw new ShardingSphereException("Cannot find table rule and
default data source with logic tables: '%s'", logicTables);
+ throw new ShardingRuleNotFoundException(logicTables);
}
if (1 == routeContexts.size()) {
RouteContext newRouteContext = routeContexts.iterator().next();
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
index 527e5945402..3cfba7f8256 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRoutingEngineTest.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.sharding.route.engine.type.complex;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import
org.apache.shardingsphere.sharding.exception.ShardingRuleNotFoundException;
import
org.apache.shardingsphere.sharding.route.engine.fixture.AbstractRoutingEngineTest;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.Test;
@@ -39,8 +39,8 @@ public final class ShardingComplexRoutingEngineTest extends
AbstractRoutingEngin
@Test
public void assertRoutingForBindingTables() {
- ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(createShardingConditions("t_order"),
- new ConfigurationProperties(new Properties()),
Arrays.asList("t_order", "t_order_item"));
+ ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(
+ createShardingConditions("t_order"), new
ConfigurationProperties(new Properties()), Arrays.asList("t_order",
"t_order_item"));
RouteContext routeContext =
complexRoutingEngine.route(createBindingShardingRule());
List<RouteUnit> routeUnits = new
ArrayList<>(routeContext.getRouteUnits());
assertThat(routeContext.getRouteUnits().size(), is(1));
@@ -52,8 +52,8 @@ public final class ShardingComplexRoutingEngineTest extends
AbstractRoutingEngin
@Test
public void assertRoutingForShardingTableJoinBroadcastTable() {
- ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(createShardingConditions("t_order"),
- new ConfigurationProperties(new Properties()),
Arrays.asList("t_order", "t_config"));
+ ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(
+ createShardingConditions("t_order"), new
ConfigurationProperties(new Properties()), Arrays.asList("t_order",
"t_config"));
RouteContext routeContext =
complexRoutingEngine.route(createBroadcastShardingRule());
List<RouteUnit> routeUnits = new
ArrayList<>(routeContext.getRouteUnits());
assertThat(routeContext.getRouteUnits().size(), is(1));
@@ -63,10 +63,10 @@ public final class ShardingComplexRoutingEngineTest extends
AbstractRoutingEngin
assertThat(routeUnits.get(0).getTableMappers().iterator().next().getLogicName(),
is("t_order"));
}
- @Test(expected = ShardingSphereException.class)
+ @Test(expected = ShardingRuleNotFoundException.class)
public void assertRoutingForNonLogicTable() {
- ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(createShardingConditions("t_order"),
- new ConfigurationProperties(new Properties()),
Collections.emptyList());
- RouteContext routeContext =
complexRoutingEngine.route(mock(ShardingRule.class));
+ ShardingComplexRoutingEngine complexRoutingEngine = new
ShardingComplexRoutingEngine(
+ createShardingConditions("t_order"), new
ConfigurationProperties(new Properties()), Collections.emptyList());
+ complexRoutingEngine.route(mock(ShardingRule.class));
}
}