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 0b9e29d3f40 Refactor TransactionSQLException's impl (#30786)
0b9e29d3f40 is described below

commit 0b9e29d3f403fad1a5c043f6289a59b47020d52f
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Sat Apr 6 07:16:16 2024 +0800

    Refactor TransactionSQLException's impl (#30786)
    
    * Refactor TransactionSQLException's impl
    
    * Refactor TransactionSQLException's impl
---
 .../user-manual/error-code/sql-error-code.cn.md    | 29 +++++++++++-----------
 .../user-manual/error-code/sql-error-code.en.md    | 28 +++++++++++----------
 .../kernel/category/TransactionSQLException.java   |  4 +++
 .../ShardingSphereTransactionManagerEngine.java    |  4 +--
 .../transaction/core/ResourceDataSource.java       |  4 +--
 .../CloseTransactionManagerFailedException.java    |  4 +--
 ...va => ResourceNameLengthExceededException.java} |  8 +++---
 ...va => TransactionManagerNotFoundException.java} |  8 +++---
 .../exception/TransactionTimeoutException.java     |  2 +-
 9 files changed, 49 insertions(+), 42 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 e415dd3cc24..33e343a8225 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
@@ -82,19 +82,20 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 
 ### 事务
 
-| Vendor Code | SQL State | 错误信息                                               
                                |
-|-------------|-----------|------------------------------------------------------------------------------------|
-| 14000       | 25000     | Switch transaction type failed, please terminate 
the current transaction.          |
-| 14001       | 25000     | Can not find transaction manager of \`%s\`.        
                                |
-| 14002       | 25000     | Transaction timeout should more than 0s.           
                                |
-| 14200       | 25000     | Can not start new XA transaction in a active 
transaction.                          |
-| 14201       | 25000     | Failed to create \`%s\` XA data source.            
                                |
-| 14202       | 25000     | Max length of xa unique resource name \`%s\` 
exceeded: should be less than 45.     |
-| 14203       | 25000     | Check privileges failed on data source, reason is: 
\`%s\`                          |
-| 14204       | 25000     | Failed to create XA transaction manager, requires 
\`%s\` privileges                |
-| 14205       | 25000     | Close transaction manager failed, \`%s\`           
                                |
-| 14301       | 25000     | ShardingSphere Seata-AT transaction has been 
disabled.                             |
-| 14302       | 25000     | Please config application id within seata.conf 
file.                               |
+| Vendor Code | SQL State | 错误信息                                               
                            |
+|-------------|-----------|--------------------------------------------------------------------------------|
+| 14000       | 25000     | Switch transaction type failed, please terminate 
the current transaction.      |
+| 14001       | 42S02     | Can not find transaction manager of '%s'.          
                            |
+| 14002       | 44000     | Max length of unique resource name '%s' exceeded, 
should be less than 45.      |
+| 14003       | 25000     | Transaction timeout should more than 0.            
                            |
+| 14004       | 25000     | Close transaction manager failed.                  
                            |
+| 14200       | 25000     | Can not start new XA transaction in a active 
transaction.                      |
+| 14201       | 25000     | Failed to create \`%s\` XA data source.            
                            |
+| 14202       | 25000     | Max length of xa unique resource name \`%s\` 
exceeded: should be less than 45. |
+| 14203       | 25000     | Check privileges failed on data source, reason is: 
\`%s\`                      |
+| 14204       | 25000     | Failed to create XA transaction manager, requires 
\`%s\` privileges            |
+| 14301       | 25000     | ShardingSphere Seata-AT transaction has been 
disabled.                         |
+| 14302       | 25000     | Please config application id within seata.conf 
file.                           |
 
 ### 集群
 
@@ -258,4 +259,4 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 30003       | 0A000     | Unsupported command: %s         |
 | 30004       | HY000     | Server exception: %s            |
 | 30010       | HY000     | Can not find plugin class '%s'. |
-| 30020       | HY000     | File access failed, file is: %s |
\ No newline at end of file
+| 30020       | HY000     | File access failed, file 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 3db04781bd6..50e11a6ded0 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
@@ -83,19 +83,21 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 
 ### Transaction
 
-| Vendor Code | SQL State | Reason                                             
                                |
-|-------------|-----------|------------------------------------------------------------------------------------|
-| 14000       | 25000     | Switch transaction type failed, please terminate 
the current transaction.          |
-| 14001       | 25000     | Can not find transaction manager of \`%s\`.        
                                |
-| 14002       | 25000     | Transaction timeout should more than 0s.           
                                |
-| 14200       | 25000     | Can not start new XA transaction in a active 
transaction.                          |
-| 14201       | 25000     | Failed to create \`%s\` XA data source.            
                                |
-| 14202       | 25000     | Max length of xa unique resource name \`%s\` 
exceeded: should be less than 45.     |
-| 14203       | 25000     | Check privileges failed on data source, reason is: 
\`%s\`                          |
-| 14204       | 25000     | Failed to create XA transaction manager, requires 
\`%s\` privileges                |
-| 14205       | 25000     | Close transaction manager failed, \`%s\`           
                                |
-| 14301       | 25000     | ShardingSphere Seata-AT transaction has been 
disabled.                             |
-| 14302       | 25000     | Please config application id within seata.conf 
file.                               |
+| Vendor Code | SQL State | Reason                                             
                            |
+|-------------|-----------|--------------------------------------------------------------------------------|
+| 14000       | 25000     | Switch transaction type failed, please terminate 
the current transaction.      |
+| 14001       | 42S02     | Can not find transaction manager of '%s'.          
                            |
+| 14002       | 44000     | Max length of unique resource name '%s' exceeded, 
should be less than 45.      |
+| 14003       | 25000     | Transaction timeout should more than 0.            
                            |
+| 14004       | 25000     | Close transaction manager failed.                  
                            |
+| 14200       | 25000     | Can not start new XA transaction in a active 
transaction.                      |
+| 14201       | 25000     | Failed to create \`%s\` XA data source.            
                            |
+| 14202       | 25000     | Max length of xa unique resource name \`%s\` 
exceeded: should be less than 45. |
+| 14203       | 25000     | Check privileges failed on data source, reason is: 
\`%s\`                      |
+| 14204       | 25000     | Failed to create XA transaction manager, requires 
\`%s\` privileges            |
+| 14205       | 25000     | Close transaction manager failed.                  
                            |
+| 14301       | 25000     | ShardingSphere Seata-AT transaction has been 
disabled.                         |
+| 14302       | 25000     | Please config application id within seata.conf 
file.                           |
 
 ### Cluster
 
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 969a142e2d8..56ddf109b81 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
@@ -32,4 +32,8 @@ public abstract class TransactionSQLException extends 
KernelSQLException {
     protected TransactionSQLException(final SQLState sqlState, final int 
errorCode, final String reason, final Object... messageArgs) {
         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);
+    }
 }
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ShardingSphereTransactionManagerEngine.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ShardingSphereTransactionManagerEngine.java
index 96a4d101715..e2e9ceaaeda 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ShardingSphereTransactionManagerEngine.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/ShardingSphereTransactionManagerEngine.java
@@ -21,7 +21,7 @@ import 
org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.transaction.api.TransactionType;
-import 
org.apache.shardingsphere.transaction.exception.TransactionManagerNotExistedException;
+import 
org.apache.shardingsphere.transaction.exception.TransactionManagerNotFoundException;
 import 
org.apache.shardingsphere.transaction.spi.ShardingSphereTransactionManager;
 
 import javax.sql.DataSource;
@@ -62,7 +62,7 @@ public final class ShardingSphereTransactionManagerEngine {
      */
     public ShardingSphereTransactionManager getTransactionManager(final 
TransactionType transactionType) {
         if (TransactionType.LOCAL != transactionType) {
-            ShardingSpherePreconditions.checkNotNull(transactionManager, () -> 
new TransactionManagerNotExistedException(transactionType));
+            ShardingSpherePreconditions.checkNotNull(transactionManager, () -> 
new TransactionManagerNotFoundException(transactionType));
         }
         return transactionManager;
     }
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/core/ResourceDataSource.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/core/ResourceDataSource.java
index 0f8e36d24d3..b190c1ea6d2 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/core/ResourceDataSource.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/core/ResourceDataSource.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.transaction.core;
 import com.google.common.base.Preconditions;
 import lombok.Getter;
 import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import 
org.apache.shardingsphere.transaction.exception.XAResourceNameLengthExceededException;
+import 
org.apache.shardingsphere.transaction.exception.ResourceNameLengthExceededException;
 
 import javax.sql.DataSource;
 
@@ -44,6 +44,6 @@ public final class ResourceDataSource {
         this.originalName = originalName;
         this.dataSource = dataSource;
         uniqueResourceName = ResourceIdGenerator.getInstance().nextId() + 
databaseAndDataSourceName[1];
-        
ShardingSpherePreconditions.checkState(uniqueResourceName.getBytes().length <= 
MAX_RESOURCE_NAME_LENGTH, () -> new 
XAResourceNameLengthExceededException(uniqueResourceName));
+        
ShardingSpherePreconditions.checkState(uniqueResourceName.getBytes().length <= 
MAX_RESOURCE_NAME_LENGTH, () -> new 
ResourceNameLengthExceededException(uniqueResourceName));
     }
 }
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 2ac10e695be..c7e4bf05f0b 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
@@ -27,7 +27,7 @@ public final class CloseTransactionManagerFailedException 
extends TransactionSQL
     
     private static final long serialVersionUID = -3396778990357223580L;
     
-    public CloseTransactionManagerFailedException(final Exception exception) {
-        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 205, "Close transaction 
manager failed, `%s`", exception.getMessage());
+    public CloseTransactionManagerFailedException(final Exception cause) {
+        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 4, "Close transaction 
manager failed.", cause);
     }
 }
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/XAResourceNameLengthExceededException.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/ResourceNameLengthExceededException.java
similarity index 74%
rename from 
kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/XAResourceNameLengthExceededException.java
rename to 
kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/ResourceNameLengthExceededException.java
index 9f00b962b99..4c3084bf06e 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/XAResourceNameLengthExceededException.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/ResourceNameLengthExceededException.java
@@ -21,13 +21,13 @@ import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpe
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.TransactionSQLException;
 
 /**
- * XA unique resource name length exceeded exception.
+ * Resource name length exceeded exception.
  */
-public final class XAResourceNameLengthExceededException extends 
TransactionSQLException {
+public final class ResourceNameLengthExceededException extends 
TransactionSQLException {
     
     private static final long serialVersionUID = 6190231034576044165L;
     
-    public XAResourceNameLengthExceededException(final String 
uniqueResourceName) {
-        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 202, String.format("Max 
length of xa unique resource name `%s` exceeded: should be less than 45.", 
uniqueResourceName));
+    public ResourceNameLengthExceededException(final String 
uniqueResourceName) {
+        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 2, "Max length of unique 
resource name '%s' exceeded, should be less than 45.", uniqueResourceName);
     }
 }
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionManagerNotExistedException.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionManagerNotFoundException.java
similarity index 77%
rename from 
kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionManagerNotExistedException.java
rename to 
kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionManagerNotFoundException.java
index bdccb5bc335..ebcc9a08976 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionManagerNotExistedException.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionManagerNotFoundException.java
@@ -22,13 +22,13 @@ import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.c
 import org.apache.shardingsphere.transaction.api.TransactionType;
 
 /**
- * Transaction manager not existed exception.
+ * Transaction manager not found exception.
  */
-public final class TransactionManagerNotExistedException extends 
TransactionSQLException {
+public final class TransactionManagerNotFoundException extends 
TransactionSQLException {
     
     private static final long serialVersionUID = 3831707403758598143L;
     
-    public TransactionManagerNotExistedException(final TransactionType 
transactionType) {
-        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 1, String.format("Can 
not find transaction manager of `%s`", transactionType));
+    public TransactionManagerNotFoundException(final TransactionType 
transactionType) {
+        super(XOpenSQLState.NOT_FOUND, 1, "Can not find transaction manager of 
'%s'.", transactionType);
     }
 }
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionTimeoutException.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionTimeoutException.java
index 84ae2656edb..92f8b6f1bf9 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionTimeoutException.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/exception/TransactionTimeoutException.java
@@ -28,6 +28,6 @@ public final class TransactionTimeoutException extends 
TransactionSQLException {
     private static final long serialVersionUID = -2976178098576465693L;
     
     public TransactionTimeoutException() {
-        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 2, "Transaction timeout 
should more than 0s");
+        super(XOpenSQLState.INVALID_TRANSACTION_STATE, 3, "Transaction timeout 
should more than 0.");
     }
 }

Reply via email to