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

zichaowang 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 0ab150a1e43 Refactor ShardingSphereSQLException (#30944)
0ab150a1e43 is described below

commit 0ab150a1e435ce58792311ff0a0d3a878d6b3817
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Apr 18 04:42:16 2024 +0800

    Refactor ShardingSphereSQLException (#30944)
---
 .../connection/OverallConnectionNotEnoughException.java  |  4 ++--
 .../metadata/resource/ResourceDefinitionException.java   |  4 ++--
 .../storageunit/StorageUnitsOperateException.java        |  2 +-
 .../core/external/sql/ShardingSphereSQLException.java    | 16 +++-------------
 .../external/sql/type/kernel/KernelSQLException.java     |  4 ++--
 .../sql/type/kernel/category/ClusterSQLException.java    |  4 ++--
 .../sql/type/kernel/category/ConnectionSQLException.java |  4 ++--
 .../sql/type/kernel/category/MetaDataSQLException.java   |  4 ++--
 .../type/kernel/category/TransactionSQLException.java    |  4 ++--
 .../external/sql/type/kernel/KernelSQLExceptionTest.java |  2 +-
 .../driver/exception/DriverConnectionException.java      |  4 ++--
 .../driver/exception/DriverRegisterException.java        |  2 +-
 .../CloseTransactionManagerFailedException.java          |  2 +-
 .../exception/XATransactionPrivilegeCheckException.java  |  2 +-
 .../xa/jta/exception/XATransactionSQLException.java      |  4 ++--
 .../exception/ClusterPersistRepositoryException.java     |  2 +-
 16 files changed, 27 insertions(+), 37 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/connection/OverallConnectionNotEnoughException.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/connection/OverallConnectionNotEnoughException.java
index 8674a2f7e6e..2be4cf38031 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/connection/OverallConnectionNotEnoughException.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/connection/OverallConnectionNotEnoughException.java
@@ -28,7 +28,7 @@ public final class OverallConnectionNotEnoughException 
extends ConnectionSQLExce
     private static final long serialVersionUID = -1297088138042287804L;
     
     public OverallConnectionNotEnoughException(final int desiredSize, final 
int actualSize, final Exception cause) {
-        super(XOpenSQLState.CONNECTION_EXCEPTION, 0, String.format("Can not 
get %d connections one time, partition succeed connection(%d) have released. "
-                + "Please consider increasing the 'maxPoolSize' of the data 
sources or decreasing the 'max-connections-size-per-query' in properties.", 
desiredSize, actualSize), cause);
+        super(XOpenSQLState.CONNECTION_EXCEPTION, 0, cause, "Can not get %d 
connections one time, partition succeed connection(%d) have released. "
+                + "Please consider increasing the 'maxPoolSize' of the data 
sources or decreasing the 'max-connections-size-per-query' in properties.", 
desiredSize, actualSize);
     }
 }
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/ResourceDefinitionException.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/ResourceDefinitionException.java
index b02e855a03a..240671674c1 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/ResourceDefinitionException.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/ResourceDefinitionException.java
@@ -34,8 +34,8 @@ public abstract class ResourceDefinitionException extends 
MetaDataSQLException {
         super(sqlState, getErrorCode(errorCode), reason, messageArgs);
     }
     
-    protected ResourceDefinitionException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, getErrorCode(errorCode), reason, cause);
+    protected ResourceDefinitionException(final SQLState sqlState, final int 
errorCode, final Exception cause, final String reason, final Object... 
messageArgs) {
+        super(sqlState, getErrorCode(errorCode), cause, reason, messageArgs);
     }
     
     private static int getErrorCode(final int errorCode) {
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/storageunit/StorageUnitsOperateException.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/storageunit/StorageUnitsOperateException.java
index 71cedf2faf4..9a3b2627d61 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/storageunit/StorageUnitsOperateException.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/kernel/metadata/resource/storageunit/StorageUnitsOperateException.java
@@ -30,6 +30,6 @@ public final class StorageUnitsOperateException extends 
ResourceDefinitionExcept
     private static final long serialVersionUID = 7029641448948791509L;
     
     public StorageUnitsOperateException(final String operationType, final 
Collection<String> storageUnitNames, final Exception cause) {
-        super(XOpenSQLState.GENERAL_ERROR, 0, String.format("Can not %s 
storage units '%s'.", operationType, storageUnitNames), cause);
+        super(XOpenSQLState.GENERAL_ERROR, 0, cause, "Can not %s storage units 
'%s'.", operationType, storageUnitNames);
     }
 }
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
index 4e790a63add..a2e7ac9de6f 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/ShardingSphereSQLException.java
@@ -43,19 +43,11 @@ public abstract class ShardingSphereSQLException extends 
ShardingSphereExternalE
     private final Exception cause;
     
     protected ShardingSphereSQLException(final SQLState sqlState, final int 
typeOffset, final int errorCode, final String reason, final Object... 
messageArgs) {
-        this(sqlState.getValue(), typeOffset, errorCode, reason, messageArgs);
+        this(sqlState.getValue(), typeOffset, errorCode, null == reason ? null 
: String.format(reason, formatMessageArguments(messageArgs)), null);
     }
     
     protected ShardingSphereSQLException(final SQLState sqlState, final int 
typeOffset, final int errorCode, final Exception cause, final String reason, 
final Object... messageArgs) {
-        this(sqlState.getValue(), typeOffset, errorCode, cause, reason, 
messageArgs);
-    }
-    
-    protected ShardingSphereSQLException(final String sqlState, final int 
typeOffset, final int errorCode, final String reason, final Object... 
messageArgs) {
-        this(sqlState, typeOffset, errorCode, null == reason ? null : 
String.format(reason, formatMessageArguments(messageArgs)), (Exception) null);
-    }
-    
-    protected ShardingSphereSQLException(final String sqlState, final int 
typeOffset, final int errorCode, final Exception cause, final String reason, 
final Object... messageArgs) {
-        this(sqlState, typeOffset, errorCode, null == reason ? null : 
String.format(reason, formatMessageArguments(messageArgs)), cause);
+        this(sqlState.getValue(), typeOffset, errorCode, null == reason ? null 
: String.format(reason, formatMessageArguments(messageArgs)), cause);
     }
     
     protected ShardingSphereSQLException(final String sqlState, final int 
typeOffset, final int errorCode, final String reason, final Exception cause) {
@@ -64,9 +56,7 @@ public abstract class ShardingSphereSQLException extends 
ShardingSphereExternalE
         Preconditions.checkArgument(typeOffset >= 0 && typeOffset < 4, "The 
value range of type offset should be [0, 3].");
         Preconditions.checkArgument(errorCode >= 0 && errorCode < 10000, "The 
value range of error code should be [0, 10000).");
         vendorCode = typeOffset * 10000 + errorCode;
-        this.reason = null == cause || 
Strings.isNullOrEmpty(cause.getMessage())
-                ? reason
-                : String.format("%s%sMore details: %s", reason, 
System.lineSeparator(), cause.getMessage());
+        this.reason = null == cause || 
Strings.isNullOrEmpty(cause.getMessage()) ? reason : String.format("%s%sMore 
details: %s", reason, System.lineSeparator(), cause.getMessage());
         this.cause = cause;
     }
     
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLException.java
index c4db8e52b51..874b87388ab 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLException.java
@@ -34,8 +34,8 @@ public abstract class KernelSQLException extends 
ShardingSphereSQLException {
         super(sqlState, TYPE_OFFSET, getErrorCode(kernelCode, errorCode), 
reason, messageArgs);
     }
     
-    protected KernelSQLException(final SQLState sqlState, final int 
kernelCode, final int errorCode, final String reason, final Exception cause) {
-        super(sqlState.getValue(), TYPE_OFFSET, getErrorCode(kernelCode, 
errorCode), reason, cause);
+    protected KernelSQLException(final SQLState sqlState, final int 
kernelCode, final int errorCode, final Exception cause, final String reason, 
final Object... messageArgs) {
+        super(sqlState, TYPE_OFFSET, getErrorCode(kernelCode, errorCode), 
cause, reason, messageArgs);
     }
     
     private static int getErrorCode(final int kernelCode, final int errorCode) 
{
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ClusterSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ClusterSQLException.java
index 07da6d1a8ba..b4bf031d3e9 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ClusterSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ClusterSQLException.java
@@ -33,7 +33,7 @@ public abstract class ClusterSQLException extends 
KernelSQLException {
         super(sqlState, KERNEL_CODE, errorCode, reason, messageArgs);
     }
     
-    protected ClusterSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, KERNEL_CODE, errorCode, reason, cause);
+    protected ClusterSQLException(final SQLState sqlState, final int 
errorCode, final Exception cause, final String reason, final Object... 
messageArgs) {
+        super(sqlState, KERNEL_CODE, errorCode, cause, reason, messageArgs);
     }
 }
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
index dd08c471986..cfb1c5648e4 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/ConnectionSQLException.java
@@ -33,7 +33,7 @@ public abstract class ConnectionSQLException extends 
KernelSQLException {
         super(sqlState, KERNEL_CODE, errorCode, reason, messageArgs);
     }
     
-    protected ConnectionSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, KERNEL_CODE, errorCode, reason, cause);
+    protected ConnectionSQLException(final SQLState sqlState, final int 
errorCode, final Exception cause, final String reason, final Object... 
messageArgs) {
+        super(sqlState, KERNEL_CODE, errorCode, cause, reason, messageArgs);
     }
 }
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
index 5e19f43fb28..746f86f1518 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/MetaDataSQLException.java
@@ -33,7 +33,7 @@ public abstract class MetaDataSQLException extends 
KernelSQLException {
         super(sqlState, KERNEL_CODE, errorCode, reason, messageArgs);
     }
     
-    protected MetaDataSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, KERNEL_CODE, errorCode, reason, cause);
+    protected MetaDataSQLException(final SQLState sqlState, final int 
errorCode, final Exception cause, final String reason, final Object... 
messageArgs) {
+        super(sqlState, KERNEL_CODE, errorCode, cause, reason, messageArgs);
     }
 }
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/TransactionSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/TransactionSQLException.java
index 56ddf109b81..d97b0392e64 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/TransactionSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/TransactionSQLException.java
@@ -33,7 +33,7 @@ public abstract class TransactionSQLException extends 
KernelSQLException {
         super(sqlState, KERNEL_CODE, errorCode, reason, messageArgs);
     }
     
-    protected TransactionSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, KERNEL_CODE, errorCode, reason, cause);
+    protected TransactionSQLException(final SQLState sqlState, final int 
errorCode, final Exception cause, final String reason, final Object... 
messageArgs) {
+        super(sqlState, KERNEL_CODE, errorCode, cause, reason, messageArgs);
     }
 }
diff --git 
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
 
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
index 4dd577e91f2..322eb3c8eeb 100644
--- 
a/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
+++ 
b/infra/exception/core/src/test/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/KernelSQLExceptionTest.java
@@ -41,7 +41,7 @@ class KernelSQLExceptionTest {
     @Test
     void assertToSQLExceptionWithCause() {
         Exception cause = new RuntimeException("test");
-        SQLException actual = new 
KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, "reason", cause) {
+        SQLException actual = new 
KernelSQLException(XOpenSQLState.GENERAL_ERROR, 1, 1, cause, "reason") {
         }.toSQLException();
         assertThat(actual.getSQLState(), 
is(XOpenSQLState.GENERAL_ERROR.getValue()));
         assertThat(actual.getErrorCode(), is(11001));
diff --git 
a/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverConnectionException.java
 
b/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverConnectionException.java
index c09d81e8762..658c7b5c28c 100644
--- 
a/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverConnectionException.java
+++ 
b/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverConnectionException.java
@@ -34,8 +34,8 @@ public abstract class DriverConnectionException extends 
ConnectionSQLException {
         super(sqlState, getErrorCode(errorCode), reason, messageArgs);
     }
     
-    protected DriverConnectionException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, getErrorCode(errorCode), reason, cause);
+    protected DriverConnectionException(final SQLState sqlState, final int 
errorCode, final Exception cause, final String reason, final Object... 
messageArgs) {
+        super(sqlState, getErrorCode(errorCode), cause, reason, messageArgs);
     }
     
     private static int getErrorCode(final int errorCode) {
diff --git 
a/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverRegisterException.java
 
b/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverRegisterException.java
index 1a08a4284f1..eb3fa8cf63c 100644
--- 
a/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverRegisterException.java
+++ 
b/jdbc/src/main/java/org/apache/shardingsphere/driver/exception/DriverRegisterException.java
@@ -29,6 +29,6 @@ public final class DriverRegisterException extends 
DriverConnectionException {
     private static final long serialVersionUID = -8091239932993280564L;
     
     public DriverRegisterException(final SQLException cause) {
-        super(XOpenSQLState.CONNECTION_EXCEPTION, 0, "Can not register 
driver.", cause);
+        super(XOpenSQLState.CONNECTION_EXCEPTION, 0, cause, "Can not register 
driver.");
     }
 }
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/CloseTransactionManagerFailedException.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/CloseTransactionManagerFailedException.java
index c7e4bf05f0b..528f8670fb9 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/CloseTransactionManagerFailedException.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/CloseTransactionManagerFailedException.java
@@ -28,6 +28,6 @@ public final class CloseTransactionManagerFailedException 
extends TransactionSQL
     private static final long serialVersionUID = -3396778990357223580L;
     
     public CloseTransactionManagerFailedException(final Exception cause) {
-        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 4, "Close transaction 
manager failed.", cause);
+        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 4, cause, "Close 
transaction manager failed.");
     }
 }
diff --git 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionPrivilegeCheckException.java
 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionPrivilegeCheckException.java
index 1748fd9bc39..45c971c5b58 100644
--- 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionPrivilegeCheckException.java
+++ 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionPrivilegeCheckException.java
@@ -33,6 +33,6 @@ public final class XATransactionPrivilegeCheckException 
extends XATransactionSQL
     }
     
     public XATransactionPrivilegeCheckException(final String privilege, final 
SQLException cause) {
-        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 2, String.format("Check 
XA transaction privileges failed on data source, please grant '%s' to current 
user.", privilege), cause);
+        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 2, cause, "Check XA 
transaction privileges failed on data source, please grant '%s' to current 
user.", privilege);
     }
 }
diff --git 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionSQLException.java
 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionSQLException.java
index ee2c4d9653c..7a4d4453564 100644
--- 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionSQLException.java
+++ 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/exception/XATransactionSQLException.java
@@ -34,8 +34,8 @@ public abstract class XATransactionSQLException extends 
TransactionSQLException
         super(sqlState, getErrorCode(errorCode), reason, messageArgs);
     }
     
-    protected XATransactionSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Exception cause) {
-        super(sqlState, getErrorCode(errorCode), reason, cause);
+    protected XATransactionSQLException(final SQLState sqlState, final int 
errorCode, final Exception cause, final String reason, final Object... 
messageArgs) {
+        super(sqlState, getErrorCode(errorCode), cause, reason, messageArgs);
     }
     
     private static int getErrorCode(final int errorCode) {
diff --git 
a/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/exception/ClusterPersistRepositoryException.java
 
b/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/exception/ClusterPersistRepositoryException.java
index eed877f86fc..c2d7ee1e3a9 100644
--- 
a/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/exception/ClusterPersistRepositoryException.java
+++ 
b/mode/type/cluster/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/cluster/exception/ClusterPersistRepositoryException.java
@@ -28,6 +28,6 @@ public final class ClusterPersistRepositoryException extends 
ClusterSQLException
     private static final long serialVersionUID = -6417179023552012152L;
     
     public ClusterPersistRepositoryException(final Exception cause) {
-        super(XOpenSQLState.GENERAL_ERROR, 10, "Cluster persist repository 
error.", cause);
+        super(XOpenSQLState.GENERAL_ERROR, 10, cause, "Cluster persist 
repository error.");
     }
 }

Reply via email to