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

zhaojinchao 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 e250b6187eb Reuse SQLWrapperException (#30789)
e250b6187eb is described below

commit e250b6187ebf5c5475614ce1177ba5c111d17294
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Apr 6 15:45:52 2024 +0800

    Reuse SQLWrapperException (#30789)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 -
 .../user-manual/error-code/sql-error-code.en.md    |  1 -
 .../core/checker/DataSourceCheckEngine.java        |  8 ++---
 .../PrepareJobWithInvalidConnectionException.java  | 35 ----------------------
 .../datasource/DataSourceCheckEngineTest.java      |  6 ++--
 .../postgresql/ingest/PostgreSQLWALDumperTest.java |  3 +-
 .../MySQLXATransactionPrivilegeChecker.java        |  4 +--
 .../repository/standalone/jdbc/JDBCRepository.java |  2 +-
 .../data/pipeline/util/DataSourceExecuteUtils.java | 13 ++++----
 .../engine/ShowProcessListE2EIT.java               |  3 +-
 10 files changed, 21 insertions(+), 55 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 61b8ded28f1..b16d06f2d22 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
@@ -129,7 +129,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 18087       | HY000     | Source data source required \`%s = %s\`, now is 
\`%s\`.                           |
 | 18088       | HY000     | User \`%s\` does exist.                            
                               |
 | 18089       | 08000     | Check privileges failed on source data source, 
reason is: %s                      |
-| 18090       | 08000     | Data sources can not connect, reason is: %s        
                               |
 | 18091       | HY000     | Importer job write data failed.                    
                               |
 | 18092       | 08000     | Get binlog position failed by job \`%s\`, reason 
is: %s                           |
 | 18095       | HY000     | Can not find consistency check job of \`%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 cde9edbe585..07de23c6f2b 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
@@ -130,7 +130,6 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 18087       | HY000     | Source data source required \`%s = %s\`, now is 
\`%s\`.                           |
 | 18088       | HY000     | User \`%s\` does exist.                            
                               |
 | 18089       | 08000     | Check privileges failed on source data source, 
reason is: %s                      |
-| 18090       | 08000     | Data sources can not connect, reason is: %s        
                               |
 | 18091       | HY000     | Importer job write data failed.                    
                               |
 | 18092       | 08000     | Get binlog position failed by job \`%s\`, reason 
is: %s                           |
 | 18095       | HY000     | Can not find consistency check job of \`%s\`.      
                               |
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/checker/DataSourceCheckEngine.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/checker/DataSourceCheckEngine.java
index 29ed6c7be20..55a55d10058 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/checker/DataSourceCheckEngine.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/checker/DataSourceCheckEngine.java
@@ -17,13 +17,13 @@
 
 package org.apache.shardingsphere.data.pipeline.core.checker;
 
-import 
org.apache.shardingsphere.data.pipeline.core.exception.job.PrepareJobWithInvalidConnectionException;
 import 
org.apache.shardingsphere.data.pipeline.core.exception.job.PrepareJobWithTargetTableNotEmptyException;
 import 
org.apache.shardingsphere.data.pipeline.core.importer.ImporterConfiguration;
 import 
org.apache.shardingsphere.data.pipeline.core.sqlbuilder.sql.PipelinePrepareSQLBuilder;
 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.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
 import 
org.apache.shardingsphere.infra.metadata.caseinsensitive.CaseInsensitiveQualifiedTable;
 
 import javax.sql.DataSource;
@@ -51,7 +51,7 @@ public final class DataSourceCheckEngine {
      * Check data source connections.
      *
      * @param dataSources data sources
-     * @throws PrepareJobWithInvalidConnectionException prepare job with 
invalid connection exception
+     * @throws SQLWrapperException SQL wrapper exception
      */
     public void checkConnection(final Collection<DataSource> dataSources) {
         try {
@@ -59,7 +59,7 @@ public final class DataSourceCheckEngine {
                 each.getConnection().close();
             }
         } catch (final SQLException ex) {
-            throw new PrepareJobWithInvalidConnectionException(ex);
+            throw new SQLWrapperException(ex);
         }
     }
     
@@ -96,7 +96,7 @@ public final class DataSourceCheckEngine {
                 }
             }
         } catch (final SQLException ex) {
-            throw new PrepareJobWithInvalidConnectionException(ex);
+            throw new SQLWrapperException(ex);
         }
     }
     
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/PrepareJobWithInvalidConnectionException.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/PrepareJobWithInvalidConnectionException.java
deleted file mode 100644
index 22c2237ff61..00000000000
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/exception/job/PrepareJobWithInvalidConnectionException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.data.pipeline.core.exception.job;
-
-import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.PipelineSQLException;
-import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-
-import java.sql.SQLException;
-
-/**
- * Prepare job with invalid connection exception.
- */
-public final class PrepareJobWithInvalidConnectionException extends 
PipelineSQLException {
-    
-    private static final long serialVersionUID = 208040912786493973L;
-    
-    public PrepareJobWithInvalidConnectionException(final SQLException cause) {
-        super(XOpenSQLState.CONNECTION_EXCEPTION, 90, String.format("Data 
sources can not connect, reason is: %s", cause.getMessage()), cause);
-    }
-}
diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourceCheckEngineTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourceCheckEngineTest.java
index baa9d6fe8ba..ed7b92aeeab 100644
--- 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourceCheckEngineTest.java
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/preparer/datasource/DataSourceCheckEngineTest.java
@@ -18,11 +18,11 @@
 package org.apache.shardingsphere.data.pipeline.core.preparer.datasource;
 
 import 
org.apache.shardingsphere.data.pipeline.core.checker.DataSourceCheckEngine;
-import 
org.apache.shardingsphere.data.pipeline.core.exception.job.PrepareJobWithInvalidConnectionException;
 import 
org.apache.shardingsphere.data.pipeline.core.exception.job.PrepareJobWithTargetTableNotEmptyException;
 import 
org.apache.shardingsphere.data.pipeline.core.importer.ImporterConfiguration;
-import 
org.apache.shardingsphere.infra.metadata.caseinsensitive.CaseInsensitiveQualifiedTable;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
+import 
org.apache.shardingsphere.infra.metadata.caseinsensitive.CaseInsensitiveQualifiedTable;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -80,7 +80,7 @@ class DataSourceCheckEngineTest {
     @Test
     void assertCheckConnectionFailed() throws SQLException {
         when(dataSource.getConnection()).thenThrow(new SQLException("error"));
-        assertThrows(PrepareJobWithInvalidConnectionException.class, () -> 
dataSourceCheckEngine.checkConnection(dataSources));
+        assertThrows(SQLWrapperException.class, () -> 
dataSourceCheckEngine.checkConnection(dataSources));
     }
     
     @Test
diff --git 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLWALDumperTest.java
 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLWALDumperTest.java
index 0bc1417ecfd..f353cd1d16c 100644
--- 
a/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLWALDumperTest.java
+++ 
b/kernel/data-pipeline/dialect/postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/PostgreSQLWALDumperTest.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.DumperCommonCo
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.incremental.IncrementalDumperContext;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.mapper.ActualAndLogicTableNameMapper;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.mapper.TableAndSchemaNameMapper;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
 import 
org.apache.shardingsphere.infra.metadata.caseinsensitive.CaseInsensitiveIdentifier;
 import 
org.apache.shardingsphere.data.pipeline.core.metadata.loader.StandardPipelineTableMetaDataLoader;
 import 
org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.PostgreSQLLogicalReplication;
@@ -100,7 +101,7 @@ class PostgreSQLWALDumperTest {
                 Statement statement = connection.createStatement()) {
             statement.execute(sql);
         } catch (final SQLException ex) {
-            throw new RuntimeException("Init table failed.", ex);
+            throw new SQLWrapperException(ex);
         }
     }
     
diff --git 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/checker/dialect/MySQLXATransactionPrivilegeChecker.java
 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/checker/dialect/MySQLXATransactionPrivilegeChecker.java
index fba038c0a32..e0c79ccb55a 100644
--- 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/checker/dialect/MySQLXATransactionPrivilegeChecker.java
+++ 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/checker/dialect/MySQLXATransactionPrivilegeChecker.java
@@ -17,7 +17,7 @@
 
 package 
org.apache.shardingsphere.transaction.xa.jta.datasource.checker.dialect;
 
-import org.apache.shardingsphere.infra.exception.generic.UnknownSQLException;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
 import 
org.apache.shardingsphere.transaction.xa.jta.datasource.checker.XATransactionPrivilegeChecker;
 import 
org.apache.shardingsphere.transaction.xa.jta.exception.XATransactionPrivilegeCheckException;
 
@@ -46,7 +46,7 @@ public final class MySQLXATransactionPrivilegeChecker 
implements XATransactionPr
                 checkPrivilege(connection);
             }
         } catch (final SQLException ex) {
-            throw new UnknownSQLException(ex);
+            throw new SQLWrapperException(ex);
         }
     }
     
diff --git 
a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
 
b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
index 95d7b3a54e9..c056dbb49d8 100644
--- 
a/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
+++ 
b/mode/type/standalone/repository/provider/jdbc/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepository.java
@@ -114,8 +114,8 @@ public final class JDBCRepository implements 
StandalonePersistRepository {
             }
         } catch (final SQLException ex) {
             log.error("Get children {} data by key: {} failed", getType(), 
key, ex);
+            return Collections.emptyList();
         }
-        return Collections.emptyList();
     }
     
     @Override
diff --git 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/DataSourceExecuteUtils.java
 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/DataSourceExecuteUtils.java
index d98ca47eb43..fef5a80f393 100644
--- 
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/DataSourceExecuteUtils.java
+++ 
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/util/DataSourceExecuteUtils.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.test.e2e.data.pipeline.util;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
@@ -37,13 +38,13 @@ public final class DataSourceExecuteUtils {
      *
      * @param dataSource data source
      * @param sql SQL
-     * @throws RuntimeException runtime exception
+     * @throws SQLWrapperException SQL wrapper exception
      */
     public static void execute(final DataSource dataSource, final String sql) {
         try (Connection connection = dataSource.getConnection()) {
             connection.createStatement().execute(sql);
         } catch (final SQLException ex) {
-            throw new RuntimeException(ex);
+            throw new SQLWrapperException(ex);
         }
     }
     
@@ -53,7 +54,7 @@ public final class DataSourceExecuteUtils {
      * @param dataSource data source
      * @param sql SQL
      * @param parameters parameters
-     * @throws RuntimeException runtime exception
+     * @throws SQLWrapperException SQL wrapper exception
      */
     public static void execute(final DataSource dataSource, final String sql, 
final Object[] parameters) {
         try (Connection connection = dataSource.getConnection()) {
@@ -63,7 +64,7 @@ public final class DataSourceExecuteUtils {
             }
             preparedStatement.execute();
         } catch (final SQLException ex) {
-            throw new RuntimeException(ex);
+            throw new SQLWrapperException(ex);
         }
     }
     
@@ -73,7 +74,7 @@ public final class DataSourceExecuteUtils {
      * @param dataSource data source
      * @param sql SQL
      * @param parameters parameters
-     * @throws RuntimeException runtime exception
+     * @throws SQLWrapperException SQL wrapper exception
      */
     public static void execute(final DataSource dataSource, final String sql, 
final List<Object[]> parameters) {
         try (Connection connection = dataSource.getConnection()) {
@@ -94,7 +95,7 @@ public final class DataSourceExecuteUtils {
                 preparedStatement.executeBatch();
             }
         } catch (final SQLException ex) {
-            throw new RuntimeException(ex);
+            throw new SQLWrapperException(ex);
         }
     }
 }
diff --git 
a/test/e2e/operation/showprocesslist/src/test/java/org/apache/shardingsphere/test/e2e/showprocesslist/engine/ShowProcessListE2EIT.java
 
b/test/e2e/operation/showprocesslist/src/test/java/org/apache/shardingsphere/test/e2e/showprocesslist/engine/ShowProcessListE2EIT.java
index c3437d6c07e..c1d9ee91478 100644
--- 
a/test/e2e/operation/showprocesslist/src/test/java/org/apache/shardingsphere/test/e2e/showprocesslist/engine/ShowProcessListE2EIT.java
+++ 
b/test/e2e/operation/showprocesslist/src/test/java/org/apache/shardingsphere/test/e2e/showprocesslist/engine/ShowProcessListE2EIT.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.test.e2e.showprocesslist.engine;
 
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.test.e2e.showprocesslist.container.composer.ClusterShowProcessListContainerComposer;
 import 
org.apache.shardingsphere.test.e2e.showprocesslist.env.ShowProcessListEnvironment;
@@ -77,7 +78,7 @@ class ShowProcessListE2EIT {
                     Statement statement = connection.createStatement()) {
                 statement.executeQuery(SELECT_SLEEP);
             } catch (final SQLException ex) {
-                throw new RuntimeException(ex);
+                throw new SQLWrapperException(ex);
             }
         };
     }

Reply via email to