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

zhonghongsheng 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 baf290cdfc3 Refactor StandardSQLErrorCode (#20143)
baf290cdfc3 is described below

commit baf290cdfc34d59f905ad2b4b074516a507c8f04
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 13 17:26:28 2022 +0800

    Refactor StandardSQLErrorCode (#20143)
---
 .../error/code/StandardSQLErrorCode.java           | 17 ++++----
 .../error/sqlstate/ShardingSphereSQLState.java     | 47 ----------------------
 .../error/sqlstate/XOpenSQLState.java              |  2 +
 .../error/code/StandardSQLErrorCodeTest.java       |  8 ++--
 .../shardingsphere-authority-distsql/pom.xml       |  2 +-
 .../mysql/err/MySQLErrPacketFactoryTest.java       |  8 ++--
 6 files changed, 18 insertions(+), 66 deletions(-)

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 a3f9148e573..5972ba132e4 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
@@ -20,7 +20,6 @@ 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;
 
 /**
@@ -30,21 +29,19 @@ import 
org.apache.shardingsphere.error.sqlstate.XOpenSQLState;
 @Getter
 public enum StandardSQLErrorCode implements SQLErrorCode {
     
-    CIRCUIT_BREAK_MODE(ShardingSphereSQLState.CIRCUIT_BREAK_MODE, 1000, 
"Circuit break mode is ON"),
+    CIRCUIT_BREAK_MODE(XOpenSQLState.GENERAL_WARNING, 1000, "Circuit break 
open, the request has been ignored"),
     
-    SCALING_JOB_NOT_EXIST(ShardingSphereSQLState.SCALING_JOB_NOT_EXIST, 1201, 
"Scaling job `%s` does not exist"),
+    SCALING_JOB_NOT_EXIST(XOpenSQLState.GENERAL_ERROR, 1201, "Scaling job `%s` 
does not exist"),
     
-    SCALING_OPERATE_FAILED(ShardingSphereSQLState.SCALING_OPERATE_FAILED, 
1209, "Scaling Operate Failed: `%s`"),
+    DATABASE_WRITE_LOCKED(XOpenSQLState.GENERAL_ERROR, 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(XOpenSQLState.GENERAL_ERROR, 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(XOpenSQLState.GENERAL_ERROR, 1302, "The table `%s` of schema 
`%s` is locked"),
     
-    TABLE_LOCKED(ShardingSphereSQLState.TABLE_LOCKED, 1302, "The table `%s` of 
schema `%s` is locked"),
+    UNSUPPORTED_COMMAND(XOpenSQLState.SYNTAX_ERROR, 1998, "Unsupported 
command: %s"),
     
-    UNSUPPORTED_COMMAND(ShardingSphereSQLState.UNSUPPORTED_COMMAND, 1998, 
"Unsupported command: %s"),
-    
-    UNKNOWN_EXCEPTION(ShardingSphereSQLState.UNKNOWN_EXCEPTION, 1999, "Unknown 
exception: %s"),
+    UNKNOWN_EXCEPTION(XOpenSQLState.SYNTAX_ERROR, 1999, "Unknown exception: 
%s"),
     
     RESOURCE_OR_RULE_NOT_EXIST(XOpenSQLState.SYNTAX_ERROR, 1305, "Data source 
or rule does not exist"),
     
diff --git 
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/ShardingSphereSQLState.java
 
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/ShardingSphereSQLState.java
deleted file mode 100644
index fc48dafe32b..00000000000
--- 
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/ShardingSphereSQLState.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.error.sqlstate;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * ShardingSphere SQL state.
- */
-@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/sqlstate/XOpenSQLState.java
 
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/XOpenSQLState.java
index a9d0b952447..74646354c57 100644
--- 
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/XOpenSQLState.java
+++ 
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/sqlstate/XOpenSQLState.java
@@ -29,6 +29,8 @@ public enum XOpenSQLState implements SQLState {
     
     SUCCESSFUL_COMPLETION("00000"),
     
+    GENERAL_WARNING("01000"),
+    
     PRIVILEGE_NOT_GRANTED("01007"),
     
     DATA_SOURCE_REJECTED_CONNECTION_ATTEMPT("08004"),
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 00357fd3ee7..5244c2a2759 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
@@ -26,22 +26,22 @@ public final class StandardSQLErrorCodeTest {
     
     @Test
     public void assertCircuitBreakMode() {
+        
assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getSqlState().getValue(), 
is("01000"));
         assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getVendorCode(), 
is(1000));
-        
assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getSqlState().getValue(), 
is("C1000"));
-        assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getReason(), 
is("Circuit break mode is ON"));
+        assertThat(StandardSQLErrorCode.CIRCUIT_BREAK_MODE.getReason(), 
is("Circuit break open, the request has been ignored"));
     }
     
     @Test
     public void assertUnsupportedCommand() {
+        
assertThat(StandardSQLErrorCode.UNSUPPORTED_COMMAND.getSqlState().getValue(), 
is("42000"));
         assertThat(StandardSQLErrorCode.UNSUPPORTED_COMMAND.getVendorCode(), 
is(1998));
-        
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.getSqlState().getValue(), 
is("42000"));
         assertThat(StandardSQLErrorCode.UNKNOWN_EXCEPTION.getVendorCode(), 
is(1999));
-        
assertThat(StandardSQLErrorCode.UNKNOWN_EXCEPTION.getSqlState().getValue(), 
is("C1999"));
         assertThat(StandardSQLErrorCode.UNKNOWN_EXCEPTION.getReason(), 
is("Unknown exception: %s"));
     }
 }
diff --git 
a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-distsql/pom.xml
 
b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-distsql/pom.xml
index 30c019d31e8..98cf6479422 100644
--- 
a/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-distsql/pom.xml
+++ 
b/shardingsphere-kernel/shardingsphere-authority/shardingsphere-authority-distsql/pom.xml
@@ -27,7 +27,7 @@
     <artifactId>shardingsphere-authority-distsql</artifactId>
     <packaging>pom</packaging>
     <name>${project.artifactId}</name>
-
+    
     <modules>
         <module>shardingsphere-authority-distsql-statement</module>
         <module>shardingsphere-authority-distsql-parser</module>
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
index 52228d44a97..918d9a8cf18 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
@@ -177,8 +177,8 @@ public final class MySQLErrPacketFactoryTest {
         MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
CircuitBreakException());
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getErrorCode(), is(1000));
-        assertThat(actual.getSqlState(), is("C1000"));
-        assertThat(actual.getErrorMessage(), is("Circuit break mode is ON"));
+        assertThat(actual.getSqlState(), is("01000"));
+        assertThat(actual.getErrorMessage(), is("Circuit break open, the 
request has been ignored"));
     }
     
     @Test
@@ -199,7 +199,7 @@ public final class MySQLErrPacketFactoryTest {
         MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
UnsupportedCommandException("No reason"));
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getErrorCode(), is(1998));
-        assertThat(actual.getSqlState(), is("C1998"));
+        assertThat(actual.getSqlState(), is("42000"));
         assertThat(actual.getErrorMessage(), is("Unsupported command: No 
reason"));
     }
     
@@ -208,7 +208,7 @@ public final class MySQLErrPacketFactoryTest {
         MySQLErrPacket actual = MySQLErrPacketFactory.newInstance(new 
ReflectiveOperationException("No reason"));
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getErrorCode(), is(1999));
-        assertThat(actual.getSqlState(), is("C1999"));
+        assertThat(actual.getSqlState(), is("42000"));
         assertThat(actual.getErrorMessage(), is("Unknown exception: No 
reason"));
     }
 }

Reply via email to