You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/08/28 03:49:36 UTC

[shardingsphere] branch master updated: Refactor MySQLErrPacketFactory (#20608)

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

panjuan 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 6692919833e Refactor MySQLErrPacketFactory (#20608)
6692919833e is described below

commit 6692919833e3acc779c8bfcd11831b2a2cff93ea
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Aug 28 11:49:28 2022 +0800

    Refactor MySQLErrPacketFactory (#20608)
---
 .../frontend/mysql/err/MySQLErrPacketFactory.java    | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index 0eb92abeef7..68641318ad2 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -48,16 +48,13 @@ public final class MySQLErrPacketFactory {
     public static MySQLErrPacket newInstance(final Exception cause) {
         if (cause instanceof SQLException) {
             SQLException sqlException = (SQLException) cause;
-            return null == sqlException.getSQLState() ? new MySQLErrPacket(1, MySQLVendorError.ER_INTERNAL_ERROR, getErrorMessage(sqlException))
-                    : new MySQLErrPacket(1, sqlException.getErrorCode(), sqlException.getSQLState(), sqlException.getMessage());
-        }
-        if (cause instanceof SQLDialectException) {
-            SQLException sqlException = SQLDialectExceptionMapperFactory.getInstance("MySQL").convert((SQLDialectException) cause);
-            return new MySQLErrPacket(1, sqlException.getErrorCode(), sqlException.getSQLState(), sqlException.getMessage());
+            return null == sqlException.getSQLState() ? new MySQLErrPacket(1, MySQLVendorError.ER_INTERNAL_ERROR, getErrorMessage(sqlException)) : createErrPacket(sqlException);
         }
         if (cause instanceof ShardingSphereSQLException) {
-            SQLException sqlException = ((ShardingSphereSQLException) cause).toSQLException();
-            return new MySQLErrPacket(1, sqlException.getErrorCode(), sqlException.getSQLState(), sqlException.getMessage());
+            return createErrPacket(((ShardingSphereSQLException) cause).toSQLException());
+        }
+        if (cause instanceof SQLDialectException) {
+            return createErrPacket(SQLDialectExceptionMapperFactory.getInstance("MySQL").convert((SQLDialectException) cause));
         }
         if (cause instanceof DistSQLException) {
             DistSQLException distSQLException = (DistSQLException) cause;
@@ -69,11 +66,14 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof UnsupportedCharsetException) {
             return new MySQLErrPacket(1, MySQLVendorError.ER_UNKNOWN_CHARACTER_SET, cause.getMessage());
         }
-        SQLException unknownSQLException = new UnknownSQLException(cause).toSQLException();
-        return new MySQLErrPacket(1, unknownSQLException.getErrorCode(), unknownSQLException.getSQLState(), unknownSQLException.getMessage());
+        return createErrPacket(new UnknownSQLException(cause).toSQLException());
     }
     
     private static String getErrorMessage(final SQLException cause) {
         return null == cause.getNextException() || !Strings.isNullOrEmpty(cause.getMessage()) ? cause.getMessage() : cause.getNextException().getMessage();
     }
+    
+    private static MySQLErrPacket createErrPacket(final SQLException cause) {
+        return new MySQLErrPacket(1, cause.getErrorCode(), cause.getSQLState(), cause.getMessage());
+    }
 }