This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 b1027bba107 Add EmptySQLException (#20714)
b1027bba107 is described below
commit b1027bba107b40a82b9d8284115e4a5e4868cbb3
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Sep 1 21:31:12 2022 +0800
Add EmptySQLException (#20714)
---
.../user-manual/error-code/sql-error-code.cn.md | 1 +
.../user-manual/error-code/sql-error-code.en.md | 1 +
.../statement/ShardingSpherePreparedStatement.java | 7 +++----
.../core/statement/ShardingSphereStatement.java | 5 ++---
...ceptionErrorCode.java => EmptySQLException.java} | 21 +++++++--------------
5 files changed, 14 insertions(+), 21 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 bcb59b802e9..e8ad0e55b59 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
@@ -15,6 +15,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 42000 | 10002 | Can not support 3-tier structure for actual data
node \`%s\` with JDBC \`%s\` |
| 42000 | 10003 | Unsupported SQL node conversion for SQL statement
\`%s\` |
| HY004 | 10004 | Unsupported conversion data type \`%s\` for value
\`%s\` |
+| HY004 | 10005 | SQL String can not be NULL or empty |
| HY004 | 10100 | Can not register driver, reason is: %s |
| 34000 | 10200 | Can not get cursor name from fetch statement |
| HY000 | 10300 | Could not support variable \`%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 078f68f04c9..179a79a8dfe 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
@@ -15,6 +15,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 42000 | 10002 | Can not support 3-tier structure for actual data
node \`%s\` with JDBC \`%s\` |
| 42000 | 10003 | Unsupported SQL node conversion for SQL statement
\`%s\` |
| HY004 | 10004 | Unsupported conversion data type \`%s\` for value
\`%s\` |
+| HY004 | 10005 | SQL String can not be NULL or empty |
| HY004 | 10100 | Can not register driver, reason is: %s |
| 34000 | 10200 | Can not get cursor name from fetch statement |
| HY000 | 10300 | Could not support variable \`%s\` |
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index 87aa9496f96..cf5d543ef78 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -28,10 +28,10 @@ import
org.apache.shardingsphere.driver.executor.callback.impl.PreparedStatement
import
org.apache.shardingsphere.driver.jdbc.adapter.AbstractPreparedStatementAdapter;
import
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import
org.apache.shardingsphere.driver.jdbc.core.resultset.GeneratedKeysResultSet;
-import
org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetUtil;
import
org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet;
+import
org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSetUtil;
import
org.apache.shardingsphere.driver.jdbc.core.statement.metadata.ShardingSphereParameterMetaData;
-import org.apache.shardingsphere.driver.jdbc.exception.SQLExceptionErrorCode;
+import org.apache.shardingsphere.driver.jdbc.exception.EmptySQLException;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import org.apache.shardingsphere.infra.binder.aware.ParameterAware;
@@ -181,8 +181,7 @@ public final class ShardingSpherePreparedStatement extends
AbstractPreparedState
final int resultSetType, final int
resultSetConcurrency, final int resultSetHoldability, final boolean
returnGeneratedKeys,
final String[] columns) throws
SQLException {
if (Strings.isNullOrEmpty(sql)) {
- SQLExceptionErrorCode errorCode =
SQLExceptionErrorCode.SQL_STRING_NULL_OR_EMPTY;
- throw new SQLException(errorCode.getErrorMessage(),
errorCode.getSqlState(), errorCode.getErrorCode());
+ throw new EmptySQLException().toSQLException();
}
this.connection = connection;
metaDataContexts =
connection.getContextManager().getMetaDataContexts();
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index da35c83bda4..5942cade051 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -29,8 +29,8 @@ import
org.apache.shardingsphere.driver.jdbc.adapter.AbstractStatementAdapter;
import
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import
org.apache.shardingsphere.driver.jdbc.core.resultset.GeneratedKeysResultSet;
import
org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet;
+import org.apache.shardingsphere.driver.jdbc.exception.EmptySQLException;
import
org.apache.shardingsphere.driver.jdbc.exception.JDBCTransactionAcrossDatabasesException;
-import org.apache.shardingsphere.driver.jdbc.exception.SQLExceptionErrorCode;
import org.apache.shardingsphere.infra.binder.QueryContext;
import org.apache.shardingsphere.infra.binder.SQLStatementContextFactory;
import
org.apache.shardingsphere.infra.binder.decider.context.SQLFederationDeciderContext;
@@ -153,8 +153,7 @@ public final class ShardingSphereStatement extends
AbstractStatementAdapter {
@Override
public ResultSet executeQuery(final String sql) throws SQLException {
if (Strings.isNullOrEmpty(sql)) {
- SQLExceptionErrorCode errorCode =
SQLExceptionErrorCode.SQL_STRING_NULL_OR_EMPTY;
- throw new SQLException(errorCode.getErrorMessage(),
errorCode.getSqlState(), errorCode.getErrorCode());
+ throw new EmptySQLException().toSQLException();
}
ResultSet result;
try {
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/SQLExceptionErrorCode.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
similarity index 67%
rename from
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/SQLExceptionErrorCode.java
rename to
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
index 057270dcd25..5c369826a74 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/SQLExceptionErrorCode.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
@@ -17,24 +17,17 @@
package org.apache.shardingsphere.driver.jdbc.exception;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
+import
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
import
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
/**
- * SQL exception constant.
+ * Empty SQL exception.
*/
-@RequiredArgsConstructor
-@Getter
-public enum SQLExceptionErrorCode {
+public final class EmptySQLException extends ShardingSphereSQLException {
- SQL_STRING_NULL_OR_EMPTY(0, null, "SQL String can not be NULL or empty."),
+ private static final long serialVersionUID = -5723825491720138339L;
- COLUMN_INDEX_OUT_OF_RANGE(0,
XOpenSQLState.INVALID_COLUMN_NUMBER.getValue(), "Column index out of range.");
-
- private final int errorCode;
-
- private final String sqlState;
-
- private final String errorMessage;
+ public EmptySQLException() {
+ super(XOpenSQLState.GENERAL_ERROR.getValue(), 10005, "SQL String can
not be NULL or empty");
+ }
}