This is an automated email from the ASF dual-hosted git repository. zhangliang 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 414cb048ae5 Refactor SQLWrapperException (#35122) 414cb048ae5 is described below commit 414cb048ae52b39d4c279ae0acd9a97497722c99 Author: Liang Zhang <zhangli...@apache.org> AuthorDate: Tue Apr 1 10:18:37 2025 +0800 Refactor SQLWrapperException (#35122) * Refactor SQLWrapperException * Refactor SQLWrapperException --- .../core/external/sql/type/wrapper/SQLWrapperException.java | 9 ++++----- .../core/external/sql/type/wrapper/SQLWrapperExceptionTest.java | 7 ++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java index 5b1ef7f6e5f..eda8a53db3e 100644 --- a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java +++ b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperException.java @@ -17,20 +17,19 @@ package org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper; -import org.apache.shardingsphere.infra.exception.core.external.sql.ShardingSphereSQLException; +import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; +import org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.GenericSQLException; import java.sql.SQLException; /** * SQL wrapper exception. */ -public final class SQLWrapperException extends ShardingSphereSQLException { +public final class SQLWrapperException extends GenericSQLException { private static final long serialVersionUID = 8983736995662464009L; - private static final int TYPE_OFFSET = 0; - public SQLWrapperException(final SQLException cause) { - super(cause.getSQLState(), TYPE_OFFSET, cause.getErrorCode(), "", cause); + super(XOpenSQLState.GENERAL_ERROR, 5, "Underlying SQL state: " + cause.getSQLState() + ", underlying error code: " + cause.getErrorCode() + ".", cause); } } diff --git a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java index d3108a0a547..efeebd7b04a 100644 --- a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java +++ b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/wrapper/SQLWrapperExceptionTest.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper; +import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; import org.junit.jupiter.api.Test; import java.sql.SQLException; @@ -29,8 +30,8 @@ class SQLWrapperExceptionTest { @Test void assertToSQLException() { SQLException actual = new SQLWrapperException(new SQLException("reason", "1", 10)).toSQLException(); - assertThat(actual.getSQLState(), is("1")); - assertThat(actual.getErrorCode(), is(10)); - assertThat(actual.getMessage(), is(System.lineSeparator() + "More details: java.sql.SQLException: reason")); + assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue())); + assertThat(actual.getErrorCode(), is(30005)); + assertThat(actual.getMessage(), is("Underlying SQL state: 1, underlying error code: 10.")); } }