Skip to content

Commit

Permalink
Refactor AuditSQLException (#30762)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Apr 3, 2024
1 parent 721c0ca commit 10b2cb5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
14 changes: 2 additions & 12 deletions docs/document/content/user-manual/error-code/sql-error-code.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

### 连接

Expand Down Expand Up @@ -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 | 错误信息 |
Expand Down
14 changes: 2 additions & 12 deletions docs/document/content/user-manual/error-code/sql-error-code.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 10b2cb5

Please sign in to comment.