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 2022/12/06 16:28:13 UTC

[shardingsphere] branch master updated: Adjust param order of ShardingSphereSQLException (#22706)

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 90c18a62334 Adjust param order of ShardingSphereSQLException (#22706)
90c18a62334 is described below

commit 90c18a62334f1366a046323cf5e502326ac4a799
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Dec 7 00:27:57 2022 +0800

    Adjust param order of ShardingSphereSQLException (#22706)
---
 .../external/sql/ShardingSphereSQLException.java         |  4 ++--
 .../external/sql/type/generic/GenericSQLException.java   |  2 +-
 .../external/sql/type/kernel/KernelSQLException.java     |  4 ++--
 .../external/sql/type/wrapper/SQLWrapperException.java   |  2 +-
 .../sql/type/feature/FeatureSQLExceptionTest.java        | 12 +-----------
 .../external/sql/type/kernel/KernelSQLExceptionTest.java | 16 +++++++++++++++-
 .../SQLWrapperExceptionTest.java}                        | 15 ++++++---------
 .../internal/ShardingSphereInternalExceptionTest.java    |  6 ++++++
 .../fixture/ShardingSphereInternalExceptionFixture.java  |  2 ++
 .../pipeline/core/exception/PipelineSQLException.java    |  2 +-
 10 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/ShardingSphereSQLException.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/ShardingSphereSQLException.java
index 89512629b52..a41d57fe05a 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/ShardingSphereSQLException.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/ShardingSphereSQLException.java
@@ -42,10 +42,10 @@ public abstract class ShardingSphereSQLException extends ShardingSphereExternalE
     }
     
     public ShardingSphereSQLException(final String sqlState, final int typeOffset, final int errorCode, final String reason, final Object... messageArgs) {
-        this(null == reason ? null : String.format(reason, messageArgs), null, sqlState, typeOffset, errorCode);
+        this(sqlState, typeOffset, errorCode, null == reason ? null : String.format(reason, messageArgs), (Exception) null);
     }
     
-    public ShardingSphereSQLException(final String reason, final Exception cause, final String sqlState, final int typeOffset, final int errorCode) {
+    public ShardingSphereSQLException(final String sqlState, final int typeOffset, final int errorCode, final String reason, final Exception cause) {
         super(reason, cause);
         this.sqlState = sqlState;
         vendorCode = typeOffset * 10000 + errorCode;
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/GenericSQLException.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/GenericSQLException.java
index bc56a5f56d3..e1a9ac7e48a 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/GenericSQLException.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/GenericSQLException.java
@@ -34,6 +34,6 @@ public abstract class GenericSQLException extends ShardingSphereSQLException {
     }
     
     public GenericSQLException(final String reason, final Exception cause, final SQLState sqlState, final int errorCode) {
-        super(reason, cause, sqlState.getValue(), TYPE_OFFSET, errorCode);
+        super(sqlState.getValue(), TYPE_OFFSET, errorCode, reason, cause);
     }
 }
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLException.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLException.java
index 5838b8b3eb2..8c8ffc79cbb 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLException.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLException.java
@@ -33,7 +33,7 @@ public abstract class KernelSQLException extends ShardingSphereSQLException {
         super(sqlState, TYPE_OFFSET, kernelCode * 1000 + errorCode, reason, messageArgs);
     }
     
-    public KernelSQLException(final String reason, final Exception cause, final SQLState sqlState, final int kernelCode, final int errorCode) {
-        super(reason, cause, sqlState.getValue(), TYPE_OFFSET, kernelCode * 1000 + errorCode);
+    public KernelSQLException(final SQLState sqlState, final int kernelCode, final int errorCode, final String reason, final Exception cause) {
+        super(sqlState.getValue(), TYPE_OFFSET, kernelCode * 1000 + errorCode, reason, cause);
     }
 }
diff --git a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/wrapper/SQLWrapperException.java b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/wrapper/SQLWrapperException.java
index f014b4cc8a1..0263b889042 100644
--- a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/wrapper/SQLWrapperException.java
+++ b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/wrapper/SQLWrapperException.java
@@ -31,6 +31,6 @@ public final class SQLWrapperException extends ShardingSphereSQLException {
     private static final int TYPE_OFFSET = 0;
     
     public SQLWrapperException(final SQLException cause) {
-        super(cause.getMessage(), cause, cause.getSQLState(), TYPE_OFFSET, cause.getErrorCode());
+        super(cause.getSQLState(), TYPE_OFFSET, cause.getErrorCode(), cause.getMessage(), cause);
     }
 }
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/feature/FeatureSQLExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/feature/FeatureSQLExceptionTest.java
index e655141d65c..e81bb335960 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/feature/FeatureSQLExceptionTest.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/feature/FeatureSQLExceptionTest.java
@@ -29,21 +29,11 @@ public final class FeatureSQLExceptionTest {
     
     @SuppressWarnings("serial")
     @Test
-    public void assertNewFeatureSQLExceptionWithSingleDigitalForFeatureCode() {
+    public void assertToSQLException() {
         SQLException actual = new FeatureSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, "reason") {
         }.toSQLException();
         assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
         assertThat(actual.getErrorCode(), is(20101));
         assertThat(actual.getMessage(), is("reason"));
     }
-    
-    @SuppressWarnings("serial")
-    @Test
-    public void assertNewFeatureSQLExceptionWithDoubleDigitalForFeatureCode() {
-        SQLException actual = new FeatureSQLException(XOpenSQLState.GENERAL_ERROR, 99, 10, "reason") {
-        }.toSQLException();
-        assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
-        assertThat(actual.getErrorCode(), is(29910));
-        assertThat(actual.getMessage(), is("reason"));
-    }
 }
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
index 6d215815e20..ebdf64e95b9 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
@@ -24,16 +24,30 @@ import java.sql.SQLException;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
 
 public final class KernelSQLExceptionTest {
     
     @SuppressWarnings("serial")
     @Test
-    public void assertNewKernelSQLExceptionSQLException() {
+    public void assertToSQLException() {
         SQLException actual = new KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, "reason") {
         }.toSQLException();
         assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
         assertThat(actual.getErrorCode(), is(11001));
         assertThat(actual.getMessage(), is("reason"));
+        assertNull(actual.getCause());
+    }
+    
+    @SuppressWarnings("serial")
+    @Test
+    public void assertToSQLExceptionWithCause() {
+        Exception cause = new RuntimeException("test");
+        SQLException actual = new KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, "reason", cause) {
+        }.toSQLException();
+        assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
+        assertThat(actual.getErrorCode(), is(11001));
+        assertThat(actual.getMessage(), is("reason"));
+        assertThat(actual.getCause(), is(cause));
     }
 }
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/wrapper/SQLWrapperExceptionTest.java
similarity index 68%
copy from infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
copy to infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/wrapper/SQLWrapperExceptionTest.java
index 6d215815e20..9ddc00b45c6 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/kernel/KernelSQLExceptionTest.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/wrapper/SQLWrapperExceptionTest.java
@@ -15,9 +15,8 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.util.exception.external.sql.type.kernel;
+package org.apache.shardingsphere.infra.util.exception.external.sql.type.wrapper;
 
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 import org.junit.Test;
 
 import java.sql.SQLException;
@@ -25,15 +24,13 @@ import java.sql.SQLException;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 
-public final class KernelSQLExceptionTest {
+public final class SQLWrapperExceptionTest {
     
-    @SuppressWarnings("serial")
     @Test
-    public void assertNewKernelSQLExceptionSQLException() {
-        SQLException actual = new KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, "reason") {
-        }.toSQLException();
-        assertThat(actual.getSQLState(), is(XOpenSQLState.GENERAL_ERROR.getValue()));
-        assertThat(actual.getErrorCode(), is(11001));
+    public 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("reason"));
     }
 }
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/ShardingSphereInternalExceptionTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/ShardingSphereInternalExceptionTest.java
index 38e97eff7f7..cff1d39b1d6 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/ShardingSphereInternalExceptionTest.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/ShardingSphereInternalExceptionTest.java
@@ -22,9 +22,15 @@ import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNull;
 
 public final class ShardingSphereInternalExceptionTest {
     
+    @Test
+    public void assertGetMessageWithNoArgsConstructor() {
+        assertNull(new ShardingSphereInternalExceptionFixture().getMessage());
+    }
+    
     @Test
     public void assertGetMessage() {
         assertThat(new ShardingSphereInternalExceptionFixture("Test").getMessage(), is("Fixture error message: Test"));
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/fixture/ShardingSphereInternalExceptionFixture.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/fixture/ShardingSphereInternalExceptionFixture.java
index d7d9cc76cdc..8b2a6282d7c 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/fixture/ShardingSphereInternalExceptionFixture.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/exception/internal/fixture/ShardingSphereInternalExceptionFixture.java
@@ -17,8 +17,10 @@
 
 package org.apache.shardingsphere.infra.util.exception.internal.fixture;
 
+import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.util.exception.internal.ShardingSphereInternalException;
 
+@NoArgsConstructor
 public final class ShardingSphereInternalExceptionFixture extends ShardingSphereInternalException {
     
     private static final long serialVersionUID = 3759417279204541147L;
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/PipelineSQLException.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/PipelineSQLException.java
index 6a0619b25eb..16e8a250471 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/PipelineSQLException.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/PipelineSQLException.java
@@ -34,6 +34,6 @@ public abstract class PipelineSQLException extends KernelSQLException {
     }
     
     public PipelineSQLException(final SQLState sqlState, final int errorCode, final String reason, final Exception cause) {
-        super(reason, cause, sqlState, KERNEL_CODE, errorCode);
+        super(sqlState, KERNEL_CODE, errorCode, reason, cause);
     }
 }