You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2022/10/02 02:22:40 UTC
[shardingsphere] branch master updated: Add DatabaseProtocolException (#21310)
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 d60fe0d0df4 Add DatabaseProtocolException (#21310)
d60fe0d0df4 is described below
commit d60fe0d0df40c7cee13845b569946c38da0c69ea
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Oct 2 10:22:30 2022 +0800
Add DatabaseProtocolException (#21310)
* Add MySQLProtocolException
* Add DatabaseProtocolException
---
.../content/user-manual/error-code/sql-error-code.cn.md | 3 ++-
.../content/user-manual/error-code/sql-error-code.en.md | 3 ++-
.../mysql/constant/MySQLNewParametersBoundFlag.java | 2 +-
.../protocol/mysql/exception/MySQLProtocolException.java | 8 ++++----
.../postgresql/exception/PostgreSQLProtocolException.java} | 14 +++++++-------
.../packet/command/PostgreSQLCommandPacketType.java | 3 ++-
.../command/query/extended/PostgreSQLColumnType.java | 3 ++-
.../query/extended/close/PostgreSQLComClosePacket.java | 3 ++-
.../packet/identifier/PostgreSQLMessagePacketType.java | 3 ++-
.../postgresql/constant/PostgreSQLColumnTypeTest.java | 3 ++-
.../command/PostgreSQLCommandPacketTypeLoaderTest.java | 3 ++-
.../packet/command/PostgreSQLCommandPacketTypeTest.java | 3 ++-
.../query/extended/close/PostgreSQLComClosePacketTest.java | 3 ++-
.../packet/identifier/PostgreSQLMessagePacketTypeTest.java | 3 ++-
.../dialect/SQLExceptionTransformEngine.java | 5 +++++
.../exception/protocol/DatabaseProtocolException.java | 10 +++++-----
.../sql/type/generic/DatabaseProtocolSQLException.java | 13 ++++++-------
.../frontend/exception/UnsupportedCommandException.java | 2 +-
18 files changed, 51 insertions(+), 36 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 0b5e857f41f..490bcb2a30b 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
@@ -227,4 +227,5 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| --------- | ----------- | ------ |
| HY004 | 30000 | Unknown exception: %s |
| 0A000 | 30001 | Unsupported SQL operation: %s |
-| 0A000 | 30002 | Unsupported command: %s |
+| 0A000 | 30002 | Database protocol exception: %s |
+| 0A000 | 30003 | Unsupported command: %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 e8900ee86ba..d8ecf684547 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
@@ -227,4 +227,5 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| --------- | ----------- | ------ |
| HY004 | 30000 | Unknown exception: %s |
| 0A000 | 30001 | Unsupported SQL operation: %s |
-| 0A000 | 30002 | Unsupported command: %s |
+| 0A000 | 30002 | Database protocol exception: %s |
+| 0A000 | 30003 | Unsupported command: %s |
diff --git a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLNewParametersBoundFlag.java b/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLNewParametersBoundFlag.java
index 1fff72932f7..84ae65ba0f4 100644
--- a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLNewParametersBoundFlag.java
+++ b/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLNewParametersBoundFlag.java
@@ -48,6 +48,6 @@ public enum MySQLNewParametersBoundFlag {
return each;
}
}
- throw new MySQLProtocolException(String.format("Can not find value `%s` in new parameters bound flag", value));
+ throw new MySQLProtocolException("Can not find value `%s` in new parameters bound flag.", value);
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java b/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java
index 56539a5bf4e..59696a27bd0 100644
--- a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java
+++ b/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java
@@ -17,16 +17,16 @@
package org.apache.shardingsphere.db.protocol.mysql.exception;
-import org.apache.shardingsphere.dialect.exception.SQLDialectException;
+import org.apache.shardingsphere.dialect.exception.protocol.DatabaseProtocolException;
/**
* MySQL protocol exception.
*/
-public final class MySQLProtocolException extends SQLDialectException {
+public final class MySQLProtocolException extends DatabaseProtocolException {
private static final long serialVersionUID = -2955235917749217233L;
- public MySQLProtocolException(final String reason) {
- super(reason);
+ public MySQLProtocolException(final String reason, final Object... arguments) {
+ super(String.format(reason, arguments));
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/exception/PostgreSQLProtocolException.java
similarity index 63%
copy from shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java
copy to shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/exception/PostgreSQLProtocolException.java
index 56539a5bf4e..2f3304e5894 100644
--- a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/exception/PostgreSQLProtocolException.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.mysql.exception;
+package org.apache.shardingsphere.db.protocol.postgresql.exception;
-import org.apache.shardingsphere.dialect.exception.SQLDialectException;
+import org.apache.shardingsphere.dialect.exception.protocol.DatabaseProtocolException;
/**
- * MySQL protocol exception.
+ * PostgreSQL protocol exception.
*/
-public final class MySQLProtocolException extends SQLDialectException {
+public final class PostgreSQLProtocolException extends DatabaseProtocolException {
- private static final long serialVersionUID = -2955235917749217233L;
+ private static final long serialVersionUID = -2345109476596144026L;
- public MySQLProtocolException(final String reason) {
- super(reason);
+ public PostgreSQLProtocolException(final String reason, final Object... arguments) {
+ super(String.format(reason, arguments));
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
index aab410480f4..d354fa3d32d 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.db.protocol.postgresql.packet.command;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLIdentifierTag;
import java.util.Arrays;
@@ -73,7 +74,7 @@ public enum PostgreSQLCommandPacketType implements CommandPacketType, PostgreSQL
return each;
}
}
- throw new IllegalArgumentException(String.format("Can not find `%s` in PostgreSQL command packet type", value));
+ throw new PostgreSQLProtocolException("Can not find `%s` in PostgreSQL command packet type.", value);
}
/**
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java
index 29569c738e3..58bf870b57a 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.binary.BinaryColumnType;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import java.sql.Types;
import java.util.HashMap;
@@ -200,6 +201,6 @@ public enum PostgreSQLColumnType implements BinaryColumnType {
return each;
}
}
- throw new IllegalArgumentException(String.format("Can not find value `%s` in PostgreSQL column type", value));
+ throw new PostgreSQLProtocolException("Can not find value `%s` in PostgreSQL column type.", value);
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacket.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacket.java
index b5a92c384b3..05b3b5cbbc4 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacket.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ex
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLIdentifierTag;
@@ -73,7 +74,7 @@ public final class PostgreSQLComClosePacket extends PostgreSQLCommandPacket {
return each;
}
}
- throw new IllegalArgumentException(String.format("Close type must be 'S' or 'P'. Got '%c'", type));
+ throw new PostgreSQLProtocolException("Close type must be 'S' or 'P'. Got '%c'.", type);
}
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketType.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketType.java
index 1bb7c08ee7e..a3d19d8c8e2 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketType.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketType.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.db.protocol.postgresql.packet.identifier;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
/**
* Message packet for PostgreSQL.
@@ -103,6 +104,6 @@ public enum PostgreSQLMessagePacketType implements PostgreSQLIdentifierTag {
return each;
}
}
- throw new IllegalArgumentException(String.format("Can not find `%s` in PostgreSQL identifier tag type", value));
+ throw new PostgreSQLProtocolException("Can not find `%s` in PostgreSQL identifier tag type.", value);
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLColumnTypeTest.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLColumnTypeTest.java
index 7bfe1a80a0b..da3594d6fa4 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLColumnTypeTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLColumnTypeTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.constant;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLColumnType;
import org.junit.Test;
@@ -50,7 +51,7 @@ public final class PostgreSQLColumnTypeTest {
assertThat(sqlColumnType, is(PostgreSQLColumnType.POSTGRESQL_TYPE_INT8));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = PostgreSQLProtocolException.class)
public void assertValueOfExThrown() {
PostgreSQLColumnType.valueOf(9999);
}
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeLoaderTest.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeLoaderTest.java
index 7f20986c6ab..894a85256b8 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeLoaderTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeLoaderTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
import org.junit.Test;
@@ -36,7 +37,7 @@ public final class PostgreSQLCommandPacketTypeLoaderTest {
assertThat(PostgreSQLCommandPacketTypeLoader.getCommandPacketType(payload), is(PostgreSQLCommandPacketType.SIMPLE_QUERY));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = PostgreSQLProtocolException.class)
public void assertGetCommandPacketTypeError() {
PostgreSQLPacketPayload payload = mock(PostgreSQLPacketPayload.class, RETURNS_DEEP_STUBS);
when(payload.getByteBuf().getByte(anyInt())).thenReturn((byte) 'a');
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeTest.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeTest.java
index cb89948ea6a..aaa8a528d50 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketTypeTest.java
@@ -17,13 +17,14 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public final class PostgreSQLCommandPacketTypeTest {
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = PostgreSQLProtocolException.class)
public void assertValueOfUnknownCommandPacketType() {
PostgreSQLCommandPacketType.valueOf(-1);
}
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacketTest.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacketTest.java
index d30a9b6d708..3821a46ebd5 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacketTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/close/PostgreSQLComClosePacketTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.close;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.identifier.PostgreSQLIdentifierTag;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -60,7 +61,7 @@ public final class PostgreSQLComClosePacketTest {
assertThat(actual, is(PostgreSQLCommandPacketType.CLOSE_COMMAND));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = PostgreSQLProtocolException.class)
public void assertInvalidType() {
new PostgreSQLComClosePacket(payload);
}
diff --git a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketTypeTest.java b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketTypeTest.java
index a97cec964d8..dff9755d67e 100644
--- a/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketTypeTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-postgresql-protocol/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/identifier/PostgreSQLMessagePacketTypeTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.identifier;
+import org.apache.shardingsphere.db.protocol.postgresql.exception.PostgreSQLProtocolException;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -29,7 +30,7 @@ public final class PostgreSQLMessagePacketTypeTest {
assertThat(PostgreSQLMessagePacketType.valueOf(PostgreSQLMessagePacketType.AUTHENTICATION_REQUEST.getValue()), is(PostgreSQLMessagePacketType.AUTHENTICATION_REQUEST));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = PostgreSQLProtocolException.class)
public void assertGetValueWithIllegalArgument() {
PostgreSQLMessagePacketType.valueOf(-1);
}
diff --git a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java
index 7b776045151..6b9e627f885 100644
--- a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java
+++ b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/SQLExceptionTransformEngine.java
@@ -20,9 +20,11 @@ package org.apache.shardingsphere.dialect;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.dialect.exception.SQLDialectException;
+import org.apache.shardingsphere.dialect.exception.protocol.DatabaseProtocolException;
import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapper;
import org.apache.shardingsphere.dialect.mapper.SQLDialectExceptionMapperFactory;
import org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
+import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.DatabaseProtocolSQLException;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnknownSQLException;
import java.sql.SQLException;
@@ -49,6 +51,9 @@ public final class SQLExceptionTransformEngine {
return ((ShardingSphereSQLException) cause).toSQLException();
}
if (cause instanceof SQLDialectException) {
+ if (cause instanceof DatabaseProtocolException) {
+ return new DatabaseProtocolSQLException(cause.getMessage()).toSQLException();
+ }
Optional<SQLDialectExceptionMapper> dialectExceptionMapper = SQLDialectExceptionMapperFactory.findInstance(databaseType);
if (dialectExceptionMapper.isPresent()) {
return dialectExceptionMapper.get().convert((SQLDialectException) cause);
diff --git a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/protocol/DatabaseProtocolException.java
similarity index 75%
copy from shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java
copy to shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/protocol/DatabaseProtocolException.java
index 56539a5bf4e..34a8a32b7af 100644
--- a/shardingsphere-db-protocol/shardingsphere-mysql-protocol/src/main/java/org/apache/shardingsphere/db/protocol/mysql/exception/MySQLProtocolException.java
+++ b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/protocol/DatabaseProtocolException.java
@@ -15,18 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.db.protocol.mysql.exception;
+package org.apache.shardingsphere.dialect.exception.protocol;
import org.apache.shardingsphere.dialect.exception.SQLDialectException;
/**
- * MySQL protocol exception.
+ * Database protocol exception.
*/
-public final class MySQLProtocolException extends SQLDialectException {
+public abstract class DatabaseProtocolException extends SQLDialectException {
- private static final long serialVersionUID = -2955235917749217233L;
+ private static final long serialVersionUID = -6035033415978907492L;
- public MySQLProtocolException(final String reason) {
+ public DatabaseProtocolException(final String reason) {
super(reason);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedCommandException.java b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/DatabaseProtocolSQLException.java
similarity index 64%
copy from shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedCommandException.java
copy to shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/DatabaseProtocolSQLException.java
index 7c535dffecf..8ab25610c09 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedCommandException.java
+++ b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/external/sql/type/generic/DatabaseProtocolSQLException.java
@@ -15,19 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.frontend.exception;
+package org.apache.shardingsphere.infra.util.exception.external.sql.type.generic;
import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.GenericSQLException;
/**
- * Unsupported command exception.
+ * Database protocol SQL exception.
*/
-public final class UnsupportedCommandException extends GenericSQLException {
+public final class DatabaseProtocolSQLException extends GenericSQLException {
- private static final long serialVersionUID = 8010680371699936338L;
+ private static final long serialVersionUID = -6035033415978907492L;
- public UnsupportedCommandException(final String commandType) {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 2, "Unsupported command: %s", commandType);
+ public DatabaseProtocolSQLException(final String reason) {
+ super(XOpenSQLState.GENERAL_ERROR, 2, "Database protocol exception: %s", reason);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedCommandException.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedCommandException.java
index 7c535dffecf..d8854af0f7f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedCommandException.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/UnsupportedCommandException.java
@@ -28,6 +28,6 @@ public final class UnsupportedCommandException extends GenericSQLException {
private static final long serialVersionUID = 8010680371699936338L;
public UnsupportedCommandException(final String commandType) {
- super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 2, "Unsupported command: %s", commandType);
+ super(XOpenSQLState.FEATURE_NOT_SUPPORTED, 3, "Unsupported command: %s", commandType);
}
}