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 7b707e99033 Add SQLWrapperException (#20336)
7b707e99033 is described below

commit 7b707e99033ad092b504b11ee4bba07cfb2af1ce
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Aug 21 21:32:14 2022 +0800

    Add SQLWrapperException (#20336)
---
 ...MGRMySQLDatabaseDiscoveryProviderAlgorithm.java |  4 +--
 ...licationDatabaseDiscoveryProviderAlgorithm.java | 10 +++----
 .../util/exception/sql/SQLWrapperException.java    | 32 ++++++++++++++++++++++
 .../exception/sql/ShardingSphereSQLException.java  | 10 +++++--
 4 files changed, 46 insertions(+), 10 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
index b515fa74d42..daecd81abed 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MGRMySQLDatabaseDiscoveryProviderAlgorithm.java
@@ -24,8 +24,8 @@ import 
org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgori
 import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
 import 
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException;
 import 
org.apache.shardingsphere.infra.database.metadata.dialect.MySQLDataSourceMetaData;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
@@ -86,7 +86,7 @@ public final class MGRMySQLDatabaseDiscoveryProviderAlgorithm 
implements Databas
             try {
                 checkSingleDataSourceEnvironment(databaseName, dataSource);
             } catch (SQLException ex) {
-                throw new ShardingSphereException(ex);
+                throw new SQLWrapperException(ex);
             }
         }, executorService);
     }
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProvi
 [...]
index 3fe2fe0f70b..e34694ec067 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-provider/shardingsphere-db-discovery-mysql/src/main/java/org/apache/shardingsphere/dbdiscovery/mysql/type/MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm.java
@@ -22,18 +22,18 @@ import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import 
org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProviderAlgorithm;
 import org.apache.shardingsphere.dbdiscovery.spi.ReplicaDataSourceStatus;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
+import org.apache.shardingsphere.infra.util.exception.sql.SQLWrapperException;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
-import java.util.LinkedList;
-import java.util.Iterator;
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Properties;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutorService;
 
@@ -80,7 +80,7 @@ public final class 
MySQLNormalReplicationDatabaseDiscoveryProviderAlgorithm impl
             try {
                 return isPrimaryInstance(dataSource);
             } catch (SQLException ex) {
-                throw new ShardingSphereException(ex);
+                throw new SQLWrapperException(ex);
             }
         }, executorService);
     }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/SQLWrapperException.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/SQLWrapperException.java
new file mode 100644
index 00000000000..f489605ffa2
--- /dev/null
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/SQLWrapperException.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.util.exception.sql;
+
+import java.sql.SQLException;
+
+/**
+ * SQL wrapper exception.
+ */
+public final class SQLWrapperException extends ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = 8983736995662464009L;
+    
+    public SQLWrapperException(final SQLException cause) {
+        super(cause.getSQLState(), cause.getErrorCode(), cause.getMessage());
+    }
+}
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
index f60aafd5513..65e0ffeb6df 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/ShardingSphereSQLException.java
@@ -29,14 +29,18 @@ public abstract class ShardingSphereSQLException extends 
ShardingSphereInsideExc
     
     private static final long serialVersionUID = -8238061892944243621L;
     
-    private final SQLState sqlState;
+    private final String sqlState;
     
     private final int vendorCode;
     
     private final String reason;
     
-    @SuppressWarnings("ConfusingArgumentToVarargsMethod")
     public ShardingSphereSQLException(final SQLState sqlState, final int 
vendorCode, final String reason, final String... messageArguments) {
+        this(sqlState.getValue(), vendorCode, reason, messageArguments);
+    }
+    
+    @SuppressWarnings("ConfusingArgumentToVarargsMethod")
+    public ShardingSphereSQLException(final String sqlState, final int 
vendorCode, final String reason, final String... messageArguments) {
         this.sqlState = sqlState;
         this.vendorCode = vendorCode;
         this.reason = String.format(reason, messageArguments);
@@ -48,6 +52,6 @@ public abstract class ShardingSphereSQLException extends 
ShardingSphereInsideExc
      * @return SQL exception
      */
     public final SQLException toSQLException() {
-        return new SQLException(reason, sqlState.getValue(), vendorCode);
+        return new SQLException(reason, sqlState, vendorCode);
     }
 }

Reply via email to