This is an automated email from the ASF dual-hosted git repository.
yx9o 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 eb641734148 Add SQLState (#20140)
eb641734148 is described below
commit eb64173414832c0fadd4b97b0edb68327f06b686
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 13 16:37:53 2022 +0800
Add SQLState (#20140)
* Add SQLState
* Use SQLState
* Use SQLState
* Use SQLState
* Use SQLState
* Use SQLState
---
.../mysql/packet/generic/MySQLErrPacket.java | 2 +-
.../mysql/packet/generic/MySQLErrPacketTest.java | 6 +--
.../shardingsphere/error/SQLExceptionHandler.java | 2 +-
.../shardingsphere/error/code/SQLErrorCode.java | 4 +-
.../error/code/StandardSQLErrorCode.java | 25 +++++-----
.../SQLErrorCode.java => sqlstate/SQLState.java} | 26 +++-------
.../ShardingSphereSQLState.java} | 50 +++++++++----------
.../XOpenSQLState.java} | 56 ++++++++++++----------
.../error/code/StandardSQLErrorCodeTest.java | 6 +--
.../error/mysql/code/MySQLErrorCode.java | 32 +++++++------
.../error/mysql/mapper/MySQLExceptionMapper.java | 2 +-
.../error/mysql/code/MySQLErrorCodeTest.java | 6 +--
.../error/postgresql/code/PostgreSQLErrorCode.java | 34 -------------
.../postgresql/sqlstate/PostgreSQLState.java} | 41 ++++++++--------
.../ral/common/exception/DistSQLErrorCode.java | 7 +--
.../distsql/ral/common/exception/DistSQLState.java | 33 +++++--------
16 files changed, 146 insertions(+), 186 deletions(-)
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacket.java
index f0107578fa5..545ebbbb3f8 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacket.java
@@ -49,7 +49,7 @@ public final class MySQLErrPacket implements MySQLPacket {
private final String errorMessage;
public MySQLErrPacket(final int sequenceId, final SQLErrorCode
sqlErrorCode, final Object... errorMessageArguments) {
- this(sequenceId, sqlErrorCode.getVendorCode(),
sqlErrorCode.getSqlState(), String.format(sqlErrorCode.getReason(),
errorMessageArguments));
+ this(sequenceId, sqlErrorCode.getVendorCode(),
sqlErrorCode.getSqlState().getValue(), String.format(sqlErrorCode.getReason(),
errorMessageArguments));
}
public MySQLErrPacket(final MySQLPacketPayload payload) {
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
index e90859336e3..4b56820662c 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/generic/MySQLErrPacketTest.java
@@ -40,7 +40,7 @@ public final class MySQLErrPacketTest {
MySQLErrPacket actual = new MySQLErrPacket(1,
MySQLErrorCode.ER_ACCESS_DENIED_ERROR, "root", "localhost", "root");
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getVendorCode()));
- assertThat(actual.getSqlState(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState()));
+ assertThat(actual.getSqlState(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState().getValue()));
assertThat(actual.getErrorMessage(),
is(String.format(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getReason(), "root",
"localhost", "root")));
}
@@ -49,12 +49,12 @@ public final class MySQLErrPacketTest {
when(payload.readInt1()).thenReturn(1, MySQLErrPacket.HEADER);
when(payload.readInt2()).thenReturn(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getVendorCode());
when(payload.readStringFix(1)).thenReturn("#");
-
when(payload.readStringFix(5)).thenReturn(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState());
+
when(payload.readStringFix(5)).thenReturn(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState().getValue());
when(payload.readStringEOF()).thenReturn(String.format(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getReason(),
"root", "localhost", "root"));
MySQLErrPacket actual = new MySQLErrPacket(payload);
assertThat(actual.getSequenceId(), is(1));
assertThat(actual.getErrorCode(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getVendorCode()));
- assertThat(actual.getSqlState(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState()));
+ assertThat(actual.getSqlState(),
is(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState().getValue()));
assertThat(actual.getErrorMessage(),
is(String.format(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getReason(), "root",
"localhost", "root")));
}
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/SQLExceptionHandler.java
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/SQLExceptionHandler.java
index 4305b67c29a..36b6a7d021a 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/SQLExceptionHandler.java
+++
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/SQLExceptionHandler.java
@@ -81,6 +81,6 @@ public final class SQLExceptionHandler {
}
private static SQLException toSQLException(final SQLErrorCode errorCode,
final Object... messageArguments) {
- return new SQLException(String.format(errorCode.getReason(),
messageArguments), errorCode.getSqlState(), errorCode.getVendorCode());
+ return new SQLException(String.format(errorCode.getReason(),
messageArguments), errorCode.getSqlState().getValue(),
errorCode.getVendorCode());
}
}
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
index dfb62e7d363..21f43ff06f0 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.error.code;
+import org.apache.shardingsphere.error.sqlstate.SQLState;
+
/**
* SQL error code.
*/
@@ -27,7 +29,7 @@ public interface SQLErrorCode {
*
* @return SQL state
*/
- String getSqlState();
+ SQLState getSqlState();
/**
* Get database vendor code.
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
index 89688ef664c..a3f9148e573 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
@@ -19,6 +19,9 @@ package org.apache.shardingsphere.error.code;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.error.sqlstate.SQLState;
+import org.apache.shardingsphere.error.sqlstate.ShardingSphereSQLState;
+import org.apache.shardingsphere.error.sqlstate.XOpenSQLState;
/**
* Standard SQL error code.
@@ -27,27 +30,27 @@ import lombok.RequiredArgsConstructor;
@Getter
public enum StandardSQLErrorCode implements SQLErrorCode {
- CIRCUIT_BREAK_MODE("C1000", 1000, "Circuit break mode is ON"),
+ CIRCUIT_BREAK_MODE(ShardingSphereSQLState.CIRCUIT_BREAK_MODE, 1000,
"Circuit break mode is ON"),
- SCALING_JOB_NOT_EXIST("C1201", 1201, "Scaling job `%s` does not exist"),
+ SCALING_JOB_NOT_EXIST(ShardingSphereSQLState.SCALING_JOB_NOT_EXIST, 1201,
"Scaling job `%s` does not exist"),
- SCALING_OPERATE_FAILED("C1209", 1209, "Scaling Operate Failed: `%s`"),
+ SCALING_OPERATE_FAILED(ShardingSphereSQLState.SCALING_OPERATE_FAILED,
1209, "Scaling Operate Failed: `%s`"),
- DATABASE_WRITE_LOCKED("C1300", 1300, "The database `%s` is read-only"),
+ DATABASE_WRITE_LOCKED(ShardingSphereSQLState.DATABASE_WRITE_LOCKED, 1300,
"The database `%s` is read-only"),
- TABLE_LOCK_WAIT_TIMEOUT("C1301", 1301, "The table `%s` of schema `%s` lock
wait timeout of %s ms exceeded"),
+ TABLE_LOCK_WAIT_TIMEOUT(ShardingSphereSQLState.TABLE_LOCK_WAIT_TIMEOUT,
1301, "The table `%s` of schema `%s` lock wait timeout of %s ms exceeded"),
- TABLE_LOCKED("C1302", 1302, "The table `%s` of schema `%s` is locked"),
+ TABLE_LOCKED(ShardingSphereSQLState.TABLE_LOCKED, 1302, "The table `%s` of
schema `%s` is locked"),
- RESOURCE_OR_RULE_NOT_EXIST("42000", 1305, "Data source or rule does not
exist"),
+ UNSUPPORTED_COMMAND(ShardingSphereSQLState.UNSUPPORTED_COMMAND, 1998,
"Unsupported command: %s"),
- UNSUPPORTED_SQL("42000", 1235, "Unsupported SQL: %s"),
+ UNKNOWN_EXCEPTION(ShardingSphereSQLState.UNKNOWN_EXCEPTION, 1999, "Unknown
exception: %s"),
- UNSUPPORTED_COMMAND("C1998", 1998, "Unsupported command: %s"),
+ RESOURCE_OR_RULE_NOT_EXIST(XOpenSQLState.SYNTAX_ERROR, 1305, "Data source
or rule does not exist"),
- UNKNOWN_EXCEPTION("C1999", 1999, "Unknown exception: %s");
+ UNSUPPORTED_SQL(XOpenSQLState.SYNTAX_ERROR, 1235, "Unsupported SQL: %s");
- private final String sqlState;
+ private final SQLState sqlState;
private final int vendorCode;
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/SQLState.java
similarity index 69%
copy from
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
copy to
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/SQLState.java
index dfb62e7d363..83fe8401826 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/SQLState.java
@@ -15,31 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.error.code;
+package org.apache.shardingsphere.error.sqlstate;
/**
- * SQL error code.
+ * SQL state.
*/
-public interface SQLErrorCode {
+public interface SQLState {
/**
- * Get SQL state.
+ * Get value.
*
- * @return SQL state
+ * @return value
*/
- String getSqlState();
-
- /**
- * Get database vendor code.
- *
- * @return vendor code
- */
- int getVendorCode();
-
- /**
- * Get reason.
- *
- * @return reason
- */
- String getReason();
+ String getValue();
}
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/ShardingSphereSQLState.java
similarity index 59%
copy from
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
copy to
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/ShardingSphereSQLState.java
index dfb62e7d363..fc48dafe32b 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/ShardingSphereSQLState.java
@@ -15,31 +15,33 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.error.code;
+package org.apache.shardingsphere.error.sqlstate;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
/**
- * SQL error code.
+ * ShardingSphere SQL state.
*/
-public interface SQLErrorCode {
-
- /**
- * Get SQL state.
- *
- * @return SQL state
- */
- String getSqlState();
-
- /**
- * Get database vendor code.
- *
- * @return vendor code
- */
- int getVendorCode();
-
- /**
- * Get reason.
- *
- * @return reason
- */
- String getReason();
+@RequiredArgsConstructor
+@Getter
+public enum ShardingSphereSQLState implements SQLState {
+
+ CIRCUIT_BREAK_MODE("C1000"),
+
+ SCALING_JOB_NOT_EXIST("C1201"),
+
+ SCALING_OPERATE_FAILED("C1209"),
+
+ DATABASE_WRITE_LOCKED("C1300"),
+
+ TABLE_LOCK_WAIT_TIMEOUT("C1301"),
+
+ TABLE_LOCKED("C1302"),
+
+ UNSUPPORTED_COMMAND("C1998"),
+
+ UNKNOWN_EXCEPTION("C1999");
+
+ private final String value;
}
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/XOpenSQLState.java
similarity index 54%
copy from
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
copy to
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/XOpenSQLState.java
index dfb62e7d363..a9d0b952447 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/XOpenSQLState.java
@@ -15,31 +15,39 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.error.code;
+package org.apache.shardingsphere.error.sqlstate;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
/**
- * SQL error code.
+ * XOpen standard SQL state.
*/
-public interface SQLErrorCode {
-
- /**
- * Get SQL state.
- *
- * @return SQL state
- */
- String getSqlState();
-
- /**
- * Get database vendor code.
- *
- * @return vendor code
- */
- int getVendorCode();
-
- /**
- * Get reason.
- *
- * @return reason
- */
- String getReason();
+@RequiredArgsConstructor
+@Getter
+public enum XOpenSQLState implements SQLState {
+
+ SUCCESSFUL_COMPLETION("00000"),
+
+ PRIVILEGE_NOT_GRANTED("01007"),
+
+ DATA_SOURCE_REJECTED_CONNECTION_ATTEMPT("08004"),
+
+ FEATURE_NOT_SUPPORTED("0A000"),
+
+ MISMATCH_INSERT_VALUES_AND_COLUMNS("21S01"),
+
+ INVALID_AUTHORIZATION_SPECIFICATION("28000"),
+
+ INVALID_CATALOG_NAME("3D000"),
+
+ SYNTAX_ERROR("42000"),
+
+ DUPLICATE("42S01"),
+
+ NOT_FOUND("42S02"),
+
+ GENERAL_ERROR("HY000");
+
+ private final String value;
}
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/test/java/org/apache/shardingsphere/error/code/StandardSQLErrorCodeTest.java
b/shardingsphere-error/shardingsphere-common-error/src/test/java/org/apache/shardingsphere/error/code/StandardSQLErrorCodeTest.java
index 21f90a212ac..00357fd3ee7 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/test/java/org/apache/shardingsphere/error/code/StandardSQLErrorCodeTest.java
+++
b/shardingsphere-error/shardingsphere-common-error/src/test/java/org/apache/shardingsphere/error/code/StandardSQLErrorCodeTest.java
@@ -27,21 +27,21 @@ public final class StandardSQLErrorCodeTest {
@Test
public void assertCircuitBreakMode() {
assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getVendorCode(),
is(1000));
- assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getSqlState(),
is("C1000"));
+
assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getSqlState().getValue(),
is("C1000"));
assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getReason(),
is("Circuit break mode is ON"));
}
@Test
public void assertUnsupportedCommand() {
assertThat(StandardSQLErrorCode.UNSUPPORTED_COMMAND.getVendorCode(),
is(1998));
- assertThat(StandardSQLErrorCode.UNSUPPORTED_COMMAND.getSqlState(),
is("C1998"));
+
assertThat(StandardSQLErrorCode.UNSUPPORTED_COMMAND.getSqlState().getValue(),
is("C1998"));
assertThat(StandardSQLErrorCode.UNSUPPORTED_COMMAND.getReason(),
is("Unsupported command: %s"));
}
@Test
public void assertUnknownException() {
assertThat(StandardSQLErrorCode.UNKNOWN_EXCEPTION.getVendorCode(),
is(1999));
- assertThat(StandardSQLErrorCode.UNKNOWN_EXCEPTION.getSqlState(),
is("C1999"));
+
assertThat(StandardSQLErrorCode.UNKNOWN_EXCEPTION.getSqlState().getValue(),
is("C1999"));
assertThat(StandardSQLErrorCode.UNKNOWN_EXCEPTION.getReason(),
is("Unknown exception: %s"));
}
}
diff --git
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCode.java
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCode.java
index 9c1ecc601a3..1f2d1624175 100644
---
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCode.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.error.mysql.code;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.error.code.SQLErrorCode;
+import org.apache.shardingsphere.error.sqlstate.SQLState;
+import org.apache.shardingsphere.error.sqlstate.XOpenSQLState;
/**
* Server error code for MySQL.
@@ -30,37 +32,37 @@ import org.apache.shardingsphere.error.code.SQLErrorCode;
@Getter
public enum MySQLErrorCode implements SQLErrorCode {
- ER_DBACCESS_DENIED_ERROR("42000", 1044, "Access denied for user '%s'@'%s'
to database '%s'"),
+ ER_DBACCESS_DENIED_ERROR(XOpenSQLState.SYNTAX_ERROR, 1044, "Access denied
for user '%s'@'%s' to database '%s'"),
- ER_ACCESS_DENIED_ERROR("28000", 1045, "Access denied for user '%s'@'%s'
(using password: %s)"),
+ ER_ACCESS_DENIED_ERROR(XOpenSQLState.INVALID_AUTHORIZATION_SPECIFICATION,
1045, "Access denied for user '%s'@'%s' (using password: %s)"),
- ER_NO_DB_ERROR("3D000", 1046, "No database selected"),
+ ER_NO_DB_ERROR(XOpenSQLState.INVALID_CATALOG_NAME, 1046, "No database
selected"),
- ER_BAD_DB_ERROR("42000", 1049, "Unknown database '%s'"),
+ ER_BAD_DB_ERROR(XOpenSQLState.SYNTAX_ERROR, 1049, "Unknown database '%s'"),
- ER_INTERNAL_ERROR("HY000", 1815, "Internal error: %s"),
+ ER_INTERNAL_ERROR(XOpenSQLState.GENERAL_ERROR, 1815, "Internal error: %s"),
- ER_UNSUPPORTED_PS("HY000", 1295, "This command is not supported in the
prepared statement protocol yet"),
+ ER_UNSUPPORTED_PS(XOpenSQLState.GENERAL_ERROR, 1295, "This command is not
supported in the prepared statement protocol yet"),
- ER_DB_CREATE_EXISTS_ERROR("HY000", 1007, "Can't create database '%s';
database exists"),
+ ER_DB_CREATE_EXISTS_ERROR(XOpenSQLState.GENERAL_ERROR, 1007, "Can't create
database '%s'; database exists"),
- ER_DB_DROP_NOT_EXISTS_ERROR("HY000", 1008, "Can't drop database '%s';
database doesn't exist"),
+ ER_DB_DROP_NOT_EXISTS_ERROR(XOpenSQLState.GENERAL_ERROR, 1008, "Can't drop
database '%s'; database doesn't exist"),
- ER_TABLE_EXISTS_ERROR("42S01", 1050, "Table '%s' already exists"),
+ ER_TABLE_EXISTS_ERROR(XOpenSQLState.DUPLICATE, 1050, "Table '%s' already
exists"),
- ER_NO_SUCH_TABLE("42S02", 1146, "Table '%s' doesn't exist"),
+ ER_NO_SUCH_TABLE(XOpenSQLState.NOT_FOUND, 1146, "Table '%s' doesn't
exist"),
- ER_CON_COUNT_ERROR("HY000", 1040, "Too many connections"),
+ ER_CON_COUNT_ERROR(XOpenSQLState.GENERAL_ERROR, 1040, "Too many
connections"),
- ER_UNKNOWN_CHARACTER_SET("42000", 1115, "Unknown character set: '%s'"),
+ ER_UNKNOWN_CHARACTER_SET(XOpenSQLState.SYNTAX_ERROR, 1115, "Unknown
character set: '%s'"),
- ER_WRONG_VALUE_COUNT_ON_ROW("21S01", 1136, "Column count doesn't match
value count at row %d"),
+
ER_WRONG_VALUE_COUNT_ON_ROW(XOpenSQLState.MISMATCH_INSERT_VALUES_AND_COLUMNS,
1136, "Column count doesn't match value count at row %d"),
- ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE("HY000", 3176,
+ ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE(XOpenSQLState.GENERAL_ERROR,
3176,
"Please do not modify the %s table with an XA transaction. This is
an internal system table used to store GTIDs for committed transactions. "
+ "Although modifying it can lead to an inconsistent GTID
state, if necessary you can modify it with a non-XA transaction.");
- private final String sqlState;
+ private final SQLState sqlState;
private final int vendorCode;
diff --git
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
index b5d86764327..80a8c5ab713 100644
---
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
+++
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLExceptionMapper.java
@@ -74,7 +74,7 @@ public final class MySQLExceptionMapper implements
DialectSQLExceptionMapper {
}
private SQLException toSQLException(final SQLErrorCode errorCode, final
Object... messageArguments) {
- return new SQLException(String.format(errorCode.getReason(),
messageArguments), errorCode.getSqlState(), errorCode.getVendorCode());
+ return new SQLException(String.format(errorCode.getReason(),
messageArguments), errorCode.getSqlState().getValue(),
errorCode.getVendorCode());
}
@Override
diff --git
a/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCodeTest.java
b/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCodeTest.java
index 0dc33055a6c..4949d671fe4 100644
---
a/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCodeTest.java
+++
b/shardingsphere-error/shardingsphere-mysql-error/src/test/java/org/apache/shardingsphere/error/mysql/code/MySQLErrorCodeTest.java
@@ -27,21 +27,21 @@ public final class MySQLErrorCodeTest {
@Test
public void assertAccessDeniedError() {
assertThat(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getVendorCode(),
is(1045));
- assertThat(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState(),
is("28000"));
+
assertThat(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getSqlState().getValue(),
is("28000"));
assertThat(MySQLErrorCode.ER_ACCESS_DENIED_ERROR.getReason(),
is("Access denied for user '%s'@'%s' (using password: %s)"));
}
@Test
public void assertBadDbError() {
assertThat(MySQLErrorCode.ER_BAD_DB_ERROR.getVendorCode(), is(1049));
- assertThat(MySQLErrorCode.ER_BAD_DB_ERROR.getSqlState(), is("42000"));
+ assertThat(MySQLErrorCode.ER_BAD_DB_ERROR.getSqlState().getValue(),
is("42000"));
assertThat(MySQLErrorCode.ER_BAD_DB_ERROR.getReason(), is("Unknown
database '%s'"));
}
@Test
public void assertErrorOnModifyingGtidExecutedTable() {
assertThat(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getVendorCode(),
is(3176));
-
assertThat(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getSqlState(),
is("HY000"));
+
assertThat(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getSqlState().getValue(),
is("HY000"));
assertThat(MySQLErrorCode.ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE.getReason(),
is("Please do not modify the %s table with an XA transaction. "
+ "This is an internal system table used to store GTIDs for
committed transactions. "
+ "Although modifying it can lead to an inconsistent GTID
state, if necessary you can modify it with a non-XA transaction."));
diff --git
a/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
index ac83d845b92..d427b892556 100644
---
a/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
@@ -31,36 +31,8 @@ public enum PostgreSQLErrorCode {
SUCCESSFUL_COMPLETION("00000", "successful_completion"),
- WARNING("01000", "warning"),
-
- DYNAMIC_RESULT_SETS_RETURNED("0100C", "dynamic_result_sets_returned"),
-
- IMPLICIT_ZERO_BIT_PADDING("01008", "implicit_zero_bit_padding"),
-
- NULL_VALUE_ELIMINATED_IN_SET_FUNCTION("01003",
"null_value_eliminated_in_set_function"),
-
PRIVILEGE_NOT_GRANTED("01007", "privilege_not_granted"),
- PRIVILEGE_NOT_REVOKED("01006", "privilege_not_revoked"),
-
- STRING_DATA_RIGHT_TRUNCATION("01004", "string_data_right_truncation"),
-
- DEPRECATED_FEATURE("01P01", "deprecated_feature"),
-
- CONNECTION_EXCEPTION("08000", "connection_exception"),
-
- CONNECTION_DOES_NOT_EXIST("08003", "connection_does_not_exist"),
-
- CONNECTION_FAILURE("08006", "connection_failure"),
-
- SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION("08001",
"sqlclient_unable_to_establish_sqlconnection"),
-
- SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION("08004",
"sqlserver_rejected_establishment_of_sqlconnection"),
-
- TRANSACTION_RESOLUTION_UNKNOWN("08007", "transaction_resolution_unknown"),
-
- MODIFYING_SQL_DATA_NOT_PERMITTED("38002",
"modifying_sql_data_not_permitted"),
-
PROTOCOL_VIOLATION("08P01", "protocol_violation"),
FEATURE_NOT_SUPPORTED("0A000", "feature_not_supported"),
@@ -69,16 +41,10 @@ public enum PostgreSQLErrorCode {
INVALID_AUTHORIZATION_SPECIFICATION("28000",
"invalid_authorization_specification"),
- SYNTAX_ERROR("42601", "syntax_error"),
-
- INVALID_PARAMETER_VALUE("22023", "invalid_parameter_value"),
-
INVALID_PASSWORD("28P01", "invalid_password"),
INVALID_CATALOG_NAME("3D000", "invalid_catalog_name"),
- INVALID_SCHEMA_NAME("3F000", "invalid_schema_name"),
-
UNDEFINED_COLUMN("42703", "undefined_column"),
TOO_MANY_CONNECTIONS("53300", "too_many_connections"),
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/sqlstate/PostgreSQLState.java
similarity index 60%
copy from
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
copy to
shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/sqlstate/PostgreSQLState.java
index dfb62e7d363..d53d33a9199 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
+++
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/sqlstate/PostgreSQLState.java
@@ -15,31 +15,30 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.error.code;
+package org.apache.shardingsphere.error.postgresql.sqlstate;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.error.sqlstate.SQLState;
/**
- * SQL error code.
+ * PostgreSQL SQL state.
*/
-public interface SQLErrorCode {
+@RequiredArgsConstructor
+@Getter
+public enum PostgreSQLState implements SQLState {
+
+ PROTOCOL_VIOLATION("08P01"),
+
+ DUPLICATE_DATABASE("42P04"),
+
+ INVALID_PASSWORD("28P01"),
+
+ UNDEFINED_COLUMN("42703"),
- /**
- * Get SQL state.
- *
- * @return SQL state
- */
- String getSqlState();
+ TOO_MANY_CONNECTIONS("53300"),
- /**
- * Get database vendor code.
- *
- * @return vendor code
- */
- int getVendorCode();
+ SYSTEM_ERROR("58000");
- /**
- * Get reason.
- *
- * @return reason
- */
- String getReason();
+ private final String value;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/exception/DistSQLErrorCode.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/exception/DistSQLErrorCode.java
index 2b853860871..029af54a79e 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/exception/DistSQLErrorCode.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/exception/DistSQLErrorCode.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.excep
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.error.code.SQLErrorCode;
+import org.apache.shardingsphere.error.sqlstate.SQLState;
/**
* Dist SQL error code.
@@ -28,11 +29,11 @@ import org.apache.shardingsphere.error.code.SQLErrorCode;
@Getter
public enum DistSQLErrorCode implements SQLErrorCode {
- UNSUPPORTED_VARIABLE("11001", 11001, "Could not support variable `%s`."),
+ UNSUPPORTED_VARIABLE(DistSQLState.UNSUPPORTED_VARIABLE, 11001, "Could not
support variable `%s`."),
- INVALID_VALUE("11002", 11002, "Invalid value `%s`.");
+ INVALID_VALUE(DistSQLState.INVALID_VALUE, 11002, "Invalid value `%s`.");
- private final String sqlState;
+ private final SQLState sqlState;
private final int vendorCode;
diff --git
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/exception/DistSQLState.java
similarity index 67%
copy from
shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
copy to
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/exception/DistSQLState.java
index dfb62e7d363..cd10fd9ef07 100644
---
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/SQLErrorCode.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/exception/DistSQLState.java
@@ -15,31 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.error.code;
+package
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.error.sqlstate.SQLState;
/**
- * SQL error code.
+ * Dist SQL state.
*/
-public interface SQLErrorCode {
+@RequiredArgsConstructor
+@Getter
+public enum DistSQLState implements SQLState {
- /**
- * Get SQL state.
- *
- * @return SQL state
- */
- String getSqlState();
+ UNSUPPORTED_VARIABLE("11001"),
- /**
- * Get database vendor code.
- *
- * @return vendor code
- */
- int getVendorCode();
+ INVALID_VALUE("11002");
- /**
- * Get reason.
- *
- * @return reason
- */
- String getReason();
+ private final String value;
}