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 9c9c887629e Add UnknownCharsetException (#20617)
9c9c887629e is described below
commit 9c9c887629e30442ba2e1fbc1d81e14e75708866
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 28 16:09:50 2022 +0800
Add UnknownCharsetException (#20617)
---
.../connection/UnknownCharsetException.java | 34 ++++++++++++++++++++++
.../mysql/mapper/MySQLDialectExceptionMapper.java | 4 +++
.../mysql/executor/MySQLSetCharsetExecutor.java | 4 +--
.../frontend/mysql/err/MySQLErrPacketFactory.java | 4 ---
4 files changed, 40 insertions(+), 6 deletions(-)
diff --git
a/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/connection/UnknownCharsetException.java
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/connection/UnknownCharsetException.java
new file mode 100644
index 00000000000..d8eb42a87dd
--- /dev/null
+++
b/shardingsphere-dialect-exception/shardingsphere-dialect-exception-core/src/main/java/org/apache/shardingsphere/dialect/exception/connection/UnknownCharsetException.java
@@ -0,0 +1,34 @@
+/*
+ * 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.dialect.exception.connection;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.dialect.exception.SQLDialectException;
+
+/**
+ * Unknown charset exception.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class UnknownCharsetException extends SQLDialectException {
+
+ private static final long serialVersionUID = 6289715520954322551L;
+
+ private final String charset;
+}
diff --git
a/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
b/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
index c6fdfba72dd..9e95248e33e 100644
---
a/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
+++
b/shardingsphere-dialect-exception/shardingsphere-mysql-dialect-exception/src/main/java/org/apache/shardingsphere/dialect/mysql/mapper/MySQLDialectExceptionMapper.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.dialect.mysql.mapper;
import org.apache.shardingsphere.dialect.exception.SQLDialectException;
import
org.apache.shardingsphere.dialect.exception.connection.TooManyConnectionsException;
+import
org.apache.shardingsphere.dialect.exception.connection.UnknownCharsetException;
import
org.apache.shardingsphere.dialect.exception.connection.UnknownCollationException;
import
org.apache.shardingsphere.dialect.exception.connection.UnsupportedPreparedStatementException;
import
org.apache.shardingsphere.dialect.exception.data.InsertColumnsAndValuesMismatchedException;
@@ -75,6 +76,9 @@ public final class MySQLDialectExceptionMapper implements
SQLDialectExceptionMap
if (sqlDialectException instanceof
UnsupportedPreparedStatementException) {
return toSQLException(MySQLVendorError.ER_UNSUPPORTED_PS);
}
+ if (sqlDialectException instanceof UnknownCharsetException) {
+ return toSQLException(MySQLVendorError.ER_UNKNOWN_CHARACTER_SET,
((UnknownCharsetException) sqlDialectException).getCharset());
+ }
if (sqlDialectException instanceof UnknownCollationException) {
return toSQLException(MySQLVendorError.ER_UNKNOWN_COLLATION,
((UnknownCollationException) sqlDialectException).getCollationId());
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
index 6a190f1fbab..da023cbb2ea 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/admin/mysql/executor/MySQLSetCharsetExecutor.java
@@ -19,12 +19,12 @@ package
org.apache.shardingsphere.proxy.backend.handler.admin.mysql.executor;
import org.apache.shardingsphere.db.protocol.CommonConstants;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import
org.apache.shardingsphere.dialect.exception.connection.UnknownCharsetException;
import
org.apache.shardingsphere.proxy.backend.handler.admin.mysql.MySQLSessionVariableHandler;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import java.nio.charset.UnsupportedCharsetException;
import java.util.Collection;
import java.util.Locale;
import java.util.Set;
@@ -63,7 +63,7 @@ public final class MySQLSetCharsetExecutor implements
MySQLSessionVariableHandle
// CHECKSTYLE:OFF
} catch (Exception ex) {
// CHECKSTYLE:ON
- throw new UnsupportedCharsetException(value.toLowerCase());
+ throw new UnknownCharsetException(value.toLowerCase());
}
}
}
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 d111728685f..1e0763f53b6 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
@@ -29,7 +29,6 @@ import
org.apache.shardingsphere.infra.util.exception.sql.UnknownSQLException;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLException;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLVendorError;
-import java.nio.charset.UnsupportedCharsetException;
import java.sql.SQLException;
/**
@@ -59,9 +58,6 @@ public final class MySQLErrPacketFactory {
DistSQLException distSQLException = (DistSQLException) cause;
return new MySQLErrPacket(1,
DistSQLVendorError.valueOf(distSQLException), distSQLException.getVariable());
}
- if (cause instanceof UnsupportedCharsetException) {
- return new MySQLErrPacket(1,
MySQLVendorError.ER_UNKNOWN_CHARACTER_SET, cause.getMessage());
- }
return createErrPacket(new
UnknownSQLException(cause).toSQLException());
}