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

duanzhengqiang 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 aec550364aa Fix transaction exception sonar issue (#25904)
aec550364aa is described below

commit aec550364aaed7958486bf069f71bad06ac67bce
Author: ZhangCheng <[email protected]>
AuthorDate: Fri May 26 14:00:00 2023 +0800

    Fix transaction exception sonar issue (#25904)
---
 .../core/statement/ShardingSpherePreparedStatement.java    | 12 ++++++------
 .../jdbc/core/statement/ShardingSphereStatement.java       | 14 +++++++-------
 .../shardingsphere/transaction/rule/TransactionRule.java   |  2 +-
 .../proxy/backend/connector/DatabaseConnector.java         |  2 +-
 .../transaction/src/test/resources/env/it-env.properties   |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git 
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
 
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index bccd7b0326a..49e6dbea5f4 100644
--- 
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ 
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -278,7 +278,7 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
             }
             result = new ShardingSphereResultSet(resultSets, mergedResult, 
this, transparentStatement, executionContext, columnLabelAndIndexMap);
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -376,7 +376,7 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
             }
             return isNeedImplicitCommitTransaction(executionContext) ? 
executeUpdateWithImplicitCommitTransaction() : useDriverToExecuteUpdate();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -445,7 +445,7 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
             }
             return isNeedImplicitCommitTransaction(executionContext) ? 
executeWithImplicitCommitTransaction() : useDriverToExecute();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -484,7 +484,7 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
             result = useDriverToExecute();
             connection.commit();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             connection.rollback();
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -499,7 +499,7 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
             result = useDriverToExecuteUpdate();
             connection.commit();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             connection.rollback();
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -690,7 +690,7 @@ public final class ShardingSpherePreparedStatement extends 
AbstractPreparedState
             initBatchPreparedStatementExecutor();
             return 
batchPreparedStatementExecutor.executeBatch(executionContext.getSqlStatementContext());
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
diff --git 
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
 
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index ec79c7f43e0..ab0dc1421ef 100644
--- 
a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ 
b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -186,7 +186,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
             result = new ShardingSphereResultSet(getResultSets(), 
mergedResult, this, 
isTransparentStatement(queryContext.getSqlStatementContext(),
                     
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getRuleMetaData()),
 executionContext);
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -282,7 +282,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         try {
             return executeUpdate0(sql, (actualSQL, statement) -> 
statement.executeUpdate(actualSQL), Statement::executeUpdate);
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -300,7 +300,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
             return executeUpdate0(sql, (actualSQL, statement) -> 
statement.executeUpdate(actualSQL, autoGeneratedKeys),
                     (statement, actualSQL) -> 
statement.executeUpdate(actualSQL, autoGeneratedKeys));
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -315,7 +315,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         try {
             return executeUpdate0(sql, (actualSQL, statement) -> 
statement.executeUpdate(actualSQL, columnIndexes), (statement, actualSQL) -> 
statement.executeUpdate(actualSQL, columnIndexes));
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -330,7 +330,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
         try {
             return executeUpdate0(sql, (actualSQL, statement) -> 
statement.executeUpdate(actualSQL, columnNames), (statement, actualSQL) -> 
statement.executeUpdate(actualSQL, columnNames));
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             handleExceptionInTransaction(connection, metaDataContexts);
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -366,7 +366,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
             result = useDriverToExecuteUpdate(updateCallback, 
sqlStatementContext);
             connection.commit();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             connection.rollback();
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
@@ -574,7 +574,7 @@ public final class ShardingSphereStatement extends 
AbstractStatementAdapter {
             result = useDriverToExecute(callback);
             connection.commit();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             connection.rollback();
             throw SQLExceptionTransformEngine.toSQLException(ex, 
metaDataContexts.getMetaData().getDatabase(connection.getDatabaseName()).getProtocolType().getType());
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
index 0398d8929ce..771afa39bac 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java
@@ -136,7 +136,7 @@ public final class TransactionRule implements GlobalRule, 
ResourceHeldRule<Shard
         try {
             engine.close();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             log.error("Close transaction engine failed", ex);
         }
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
index 34651bdbcfc..cae5f926f7a 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
@@ -246,7 +246,7 @@ public final class DatabaseConnector implements 
DatabaseBackendHandler {
             result = doExecute(executionContexts);
             transactionManager.commit();
             // CHECKSTYLE:OFF
-        } catch (final Exception ex) {
+        } catch (final RuntimeException ex) {
             // CHECKSTYLE:ON
             transactionManager.rollback();
             String databaseName = 
databaseConnectionManager.getConnectionSession().getDatabaseName();
diff --git 
a/test/e2e/operation/transaction/src/test/resources/env/it-env.properties 
b/test/e2e/operation/transaction/src/test/resources/env/it-env.properties
index 8fa557c6cf6..cd60dd43d0f 100644
--- a/test/e2e/operation/transaction/src/test/resources/env/it-env.properties
+++ b/test/e2e/operation/transaction/src/test/resources/env/it-env.properties
@@ -17,7 +17,7 @@
 # transaction.it.type=NONE,DOCKER,NATIVE
 transaction.it.env.type=NONE
 # transaction.it.env.cases=ClassicTransferTestCase, 
PostgreSQLSavePointTestCase 
-transaction.it.env.cases=TransactionDeadlockTestCase, 
MultiJDBCConnectionsTestCase, MultiTransactionInConnectionTestCase, 
MultiOperationsCommitAndRollbackTestCase, MySQLAutoCommitTestCase, 
PostgreSQLAutoCommitTestCase, BroadcastTableTransactionTestCase, 
ExceptionInTransactionTestCase, MultiTableCommitAndRollbackTestCase, 
SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase, 
MySQLSavePointTestCase, MySQLLocalTruncateTestCase, MySQLXATruncateTestCase, 
OpenGaussCursorTestCase, Nes [...]
+transaction.it.env.cases=TransactionDeadlockTestCase, 
MultiJDBCConnectionsTestCase, MultiTransactionInConnectionTestCase, 
MultiOperationsCommitAndRollbackTestCase, MySQLAutoCommitTestCase, 
PostgreSQLAutoCommitTestCase, BroadcastTableTransactionTestCase, 
ExceptionInTransactionTestCase, MultiTableCommitAndRollbackTestCase, 
SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase, 
MySQLSavePointTestCase, MySQLLocalTruncateTestCase, MySQLXATruncateTestCase, 
OpenGaussCursorTestCase, Nes [...]
 # transaction.it.env.transtypes=LOCAL, XA, BASE
 transaction.it.env.transtypes=LOCAL, XA
 # transaction.it.env.xa.providers=Atomikos, Bitronix, Narayana

Reply via email to