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

zhangliang 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 8cedcc14f36 Add ServerSQLException (#28136)
8cedcc14f36 is described below

commit 8cedcc14f36be6d0dd55e66850f5d5fe4dddc249
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 17 13:25:59 2023 +0800

    Add ServerSQLException (#28136)
    
    * Refactor OpenGaussErrorPacketFactory and PostgreSQLErrorPacketFactory
    
    * Refactor OpenGaussErrorPacketFactory and PostgreSQLErrorPacketFactory
    
    * Add ServerSQLException
---
 .../sql/type/generic/ServerSQLException.java       | 32 ++++++++++++++++++++++
 .../dialect/SQLExceptionTransformEngine.java       | 13 ++++++---
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git 
a/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/ServerSQLException.java
 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/ServerSQLException.java
new file mode 100644
index 00000000000..3ffe3a108d3
--- /dev/null
+++ 
b/infra/exception/core/src/main/java/org/apache/shardingsphere/infra/exception/core/external/sql/type/generic/ServerSQLException.java
@@ -0,0 +1,32 @@
+/*
+ * 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.infra.exception.core.external.sql.type.generic;
+
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Server SQL exception.
+ */
+public final class ServerSQLException extends GenericSQLException {
+    
+    private static final long serialVersionUID = -4072647406344887711L;
+    
+    public ServerSQLException(final Exception cause) {
+        super(cause.getMessage(), cause, XOpenSQLState.GENERAL_ERROR, 0);
+    }
+}
diff --git 
a/infra/exception/dialect/core/src/main/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngine.java
 
b/infra/exception/dialect/core/src/main/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngine.java
index 9b4a5b62580..2e46f6c3f94 100644
--- 
a/infra/exception/dialect/core/src/main/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngine.java
+++ 
b/infra/exception/dialect/core/src/main/java/org/apache/shardingsphere/infra/exception/dialect/SQLExceptionTransformEngine.java
@@ -19,14 +19,16 @@ package org.apache.shardingsphere.infra.exception.dialect;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import 
org.apache.shardingsphere.infra.exception.dialect.exception.SQLDialectException;
-import 
org.apache.shardingsphere.infra.exception.dialect.exception.protocol.DatabaseProtocolException;
-import 
org.apache.shardingsphere.infra.exception.dialect.mapper.SQLDialectExceptionMapper;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.exception.core.external.server.ShardingSphereServerException;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.ShardingSphereSQLException;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.DatabaseProtocolSQLException;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.ServerSQLException;
 import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.generic.UnknownSQLException;
+import 
org.apache.shardingsphere.infra.exception.dialect.exception.SQLDialectException;
+import 
org.apache.shardingsphere.infra.exception.dialect.exception.protocol.DatabaseProtocolException;
+import 
org.apache.shardingsphere.infra.exception.dialect.mapper.SQLDialectExceptionMapper;
 
 import java.sql.SQLException;
 import java.util.Optional;
@@ -60,6 +62,9 @@ public final class SQLExceptionTransformEngine {
                 return 
dialectExceptionMapper.get().convert((SQLDialectException) cause);
             }
         }
+        if (cause instanceof ShardingSphereServerException) {
+            return new ServerSQLException(cause).toSQLException();
+        }
         return new UnknownSQLException(cause).toSQLException();
     }
 }

Reply via email to