You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2024/04/10 09:33:20 UTC
(shardingsphere) branch master updated: Refactor EmptyTrafficExecutionUnitException (#30832)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 e9a9e13e31b Refactor EmptyTrafficExecutionUnitException (#30832)
e9a9e13e31b is described below
commit e9a9e13e31b7fb12d5ee8a738a1e8ded274b6a8d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Apr 10 17:33:13 2024 +0800
Refactor EmptyTrafficExecutionUnitException (#30832)
---
.../jdbc/core/statement/ShardingSpherePreparedStatement.java | 7 +++----
.../driver/jdbc/core/statement/ShardingSphereStatement.java | 2 +-
.../{metadata => }/EmptyTrafficExecutionUnitException.java | 3 +--
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index ff49f46198f..a3afae022b5 100644
--- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.driver.jdbc.core.resultset.GeneratedKeysResultS
import org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet;
import org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetUtils;
import org.apache.shardingsphere.driver.jdbc.core.statement.metadata.ShardingSphereParameterMetaData;
+import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.kernel.syntax.EmptySQLException;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.aware.ParameterAware;
@@ -86,7 +87,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sqlfederation.executor.context.SQLFederationContext;
import org.apache.shardingsphere.traffic.engine.TrafficEngine;
-import org.apache.shardingsphere.traffic.exception.metadata.EmptyTrafficExecutionUnitException;
+import org.apache.shardingsphere.traffic.exception.EmptyTrafficExecutionUnitException;
import org.apache.shardingsphere.traffic.rule.TrafficRule;
import org.apache.shardingsphere.transaction.implicit.ImplicitTransactionCallback;
import org.apache.shardingsphere.transaction.util.AutoCommitUtils;
@@ -282,9 +283,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
ExecutionUnit executionUnit = new ExecutionUnit(trafficInstanceId, new SQLUnit(queryContext.getSql(), queryContext.getParameters()));
ExecutionGroupContext<JDBCExecutionUnit> context =
prepareEngine.prepare(new RouteContext(), Collections.singleton(executionUnit), new ExecutionGroupReportContext(connection.getProcessId(), databaseName, new Grantee("", "")));
- if (context.getInputGroups().isEmpty() || context.getInputGroups().iterator().next().getInputs().isEmpty()) {
- throw new EmptyTrafficExecutionUnitException();
- }
+ ShardingSpherePreconditions.checkState(!context.getInputGroups().isEmpty() && !context.getInputGroups().iterator().next().getInputs().isEmpty(), EmptyTrafficExecutionUnitException::new);
return context.getInputGroups().iterator().next().getInputs().iterator().next();
}
diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index 5606dc375e5..fb9e7012826 100644
--- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -80,7 +80,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sqlfederation.executor.context.SQLFederationContext;
import org.apache.shardingsphere.traffic.engine.TrafficEngine;
-import org.apache.shardingsphere.traffic.exception.metadata.EmptyTrafficExecutionUnitException;
+import org.apache.shardingsphere.traffic.exception.EmptyTrafficExecutionUnitException;
import org.apache.shardingsphere.traffic.executor.TrafficExecutorCallback;
import org.apache.shardingsphere.traffic.rule.TrafficRule;
import org.apache.shardingsphere.transaction.implicit.ImplicitTransactionCallback;
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/exception/metadata/EmptyTrafficExecutionUnitException.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/exception/EmptyTrafficExecutionUnitException.java
similarity index 90%
rename from kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/exception/metadata/EmptyTrafficExecutionUnitException.java
rename to kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/exception/EmptyTrafficExecutionUnitException.java
index 14c48abe553..c637972f705 100644
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/exception/metadata/EmptyTrafficExecutionUnitException.java
+++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/exception/EmptyTrafficExecutionUnitException.java
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.traffic.exception.metadata;
+package org.apache.shardingsphere.traffic.exception;
import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-import org.apache.shardingsphere.traffic.exception.TrafficException;
/**
* Empty traffic execution unit exception.