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

wuweijie 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 10b2cb54e79 Refactor AuditSQLException (#30762)
10b2cb54e79 is described below

commit 10b2cb54e79a3103950622c515aade0007a54046
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 3 23:55:17 2024 +0800

    Refactor AuditSQLException (#30762)
---
 .../content/user-manual/error-code/sql-error-code.cn.md    | 14 ++------------
 .../content/user-manual/error-code/sql-error-code.en.md    | 14 ++------------
 .../infra/hint/SQLHintDataSourceNotExistsException.java    |  2 +-
 .../sql/type/kernel/category/AuditSQLException.java        | 13 +++++++++----
 .../infra/executor/audit/exception/SQLAuditException.java  |  2 +-
 5 files changed, 15 insertions(+), 30 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 717b25bfc00..6ec92098229 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
@@ -62,6 +62,8 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42S02     | 12021       | Can not find column label '%s'.          |
 | HY000     | 12022       | Column '%s' in %s is ambiguous.          |
 | 0A000     | 12100       | DROP TABLE ... CASCADE is not supported. |
+| 42000     | 12200       | SQL audit failed, error message: %s.     |
+| 42000     | 12201       | Hint datasource '%s' does not exist.     |
 
 ### 连接
 
@@ -93,18 +95,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 25000     | 14301       | ShardingSphere Seata-AT transaction has been 
disabled.                             |
 | 25000     | 14302       | Please config application id within seata.conf 
file.                               |
 
-### 审计
-
-| SQL State | Vendor Code | 错误信息                                 |
-|-----------|-------------|--------------------------------------|
-| 44000     | 16000       | SQL audit failed, error message: %s. |
-| 44000     | 16001       | Hint data source: %s is not exist.   |
-
-### 权限
-
-| SQL State | Vendor Code | 错误信息                              |
-|-----------|-------------|-----------------------------------|
-
 ### 集群
 
 | SQL State | Vendor Code | 错误信息                                               
           |
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 c374d1ea392..61773bf6ef5 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
@@ -62,6 +62,8 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42S02     | 12021       | Can not find column label '%s'.          |
 | HY000     | 12022       | Column '%s' in %s is ambiguous.          |
 | 0A000     | 12100       | DROP TABLE ... CASCADE is not supported. |
+| 42000     | 12200       | SQL audit failed, error message: %s.     |
+| 42000     | 12201       | Hint datasource '%s' does not exist.     |
 
 ### Connection
 
@@ -93,18 +95,6 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 25000     | 14301       | ShardingSphere Seata-AT transaction has been 
disabled.                             |
 | 25000     | 14302       | Please config application id within seata.conf 
file.                               |
 
-### Audit
-
-| SQL State | Vendor Code | Reason                               |
-|-----------|-------------|--------------------------------------|
-| 44000     | 16000       | SQL audit failed, error message: %s. |
-| 44000     | 16001       | Hint datasource: %s is not exist.    |
-
-### Authority
-
-| SQL State | Vendor Code | Reason                            |
-|-----------|-------------|-----------------------------------|
-
 ### Cluster
 
 | SQL State | Vendor Code | Reason                                             
           |
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintDataSourceNotExistsException.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintDataSourceNotExistsException.java
index 15342bc62a0..3298f346e6a 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintDataSourceNotExistsException.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/hint/SQLHintDataSourceNotExistsException.java
@@ -28,6 +28,6 @@ public final class SQLHintDataSourceNotExistsException 
extends AuditSQLException
     private static final long serialVersionUID = -8222967059220727514L;
     
     public SQLHintDataSourceNotExistsException(final String errorMessage) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "Hint data source: %s 
is not exist.", errorMessage);
+        super(XOpenSQLState.SYNTAX_ERROR, 1, "Hint datasource '%s' does not 
exist.", errorMessage);
     }
 }
diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/AuditSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/AuditSQLException.java
index 9e9e4f6af9f..a1e2e83d7a2 100644
--- 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/AuditSQLException.java
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/kernel/category/AuditSQLException.java
@@ -17,19 +17,24 @@
 
 package 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category;
 
+import com.google.common.base.Preconditions;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.SQLState;
-import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.KernelSQLException;
 
 /**
  * Audit SQL exception.
  */
-public abstract class AuditSQLException extends KernelSQLException {
+public abstract class AuditSQLException extends SyntaxSQLException {
     
     private static final long serialVersionUID = -2464996050872874641L;
     
-    private static final int KERNEL_CODE = 6;
+    private static final int AUDIT_CODE = 2;
     
     protected AuditSQLException(final SQLState sqlState, final int errorCode, 
final String reason, final Object... messageArgs) {
-        super(sqlState, KERNEL_CODE, errorCode, reason, messageArgs);
+        super(sqlState, getErrorCode(errorCode), reason, messageArgs);
+    }
+    
+    private static int getErrorCode(final int errorCode) {
+        Preconditions.checkArgument(errorCode >= 0 && errorCode < 100, "The 
value range of error code should be [0, 100).");
+        return AUDIT_CODE * 100 + errorCode;
     }
 }
diff --git 
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/audit/exception/SQLAuditException.java
 
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/audit/exception/SQLAuditException.java
index d101463d011..f95bbd50ecf 100644
--- 
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/audit/exception/SQLAuditException.java
+++ 
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/audit/exception/SQLAuditException.java
@@ -28,6 +28,6 @@ public final class SQLAuditException extends 
AuditSQLException {
     private static final long serialVersionUID = 4183020614721058122L;
     
     public SQLAuditException(final String errorMessage) {
-        super(XOpenSQLState.CHECK_OPTION_VIOLATION, 0, "SQL audit failed, 
error message: %s.", errorMessage);
+        super(XOpenSQLState.SYNTAX_ERROR, 0, "SQL audit failed, error message: 
%s.", errorMessage);
     }
 }

Reply via email to