Skip to content

Commit

Permalink
Fix transaction exception sonar issue (apache#25904)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingZC authored May 26, 2023
1 parent 89aaeba commit aec5503
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public ResultSet executeQuery() throws SQLException {
}
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());
Expand Down Expand Up @@ -376,7 +376,7 @@ public int executeUpdate() throws SQLException {
}
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());
Expand Down Expand Up @@ -445,7 +445,7 @@ public boolean execute() throws SQLException {
}
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());
Expand Down Expand Up @@ -484,7 +484,7 @@ private boolean executeWithImplicitCommitTransaction() throws SQLException {
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());
Expand All @@ -499,7 +499,7 @@ private int executeUpdateWithImplicitCommitTransaction() throws SQLException {
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());
Expand Down Expand Up @@ -690,7 +690,7 @@ public int[] executeBatch() throws SQLException {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public ResultSet executeQuery(final String sql) throws SQLException {
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());
Expand Down Expand Up @@ -282,7 +282,7 @@ public int executeUpdate(final String sql) throws SQLException {
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());
Expand All @@ -300,7 +300,7 @@ public int executeUpdate(final String sql, final int autoGeneratedKeys) throws S
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());
Expand All @@ -315,7 +315,7 @@ public int executeUpdate(final String sql, final int[] columnIndexes) throws SQL
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());
Expand All @@ -330,7 +330,7 @@ public int executeUpdate(final String sql, final String[] columnNames) throws SQ
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());
Expand Down Expand Up @@ -366,7 +366,7 @@ private int executeUpdateWithImplicitCommitTransaction(final ExecuteUpdateCallba
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());
Expand Down Expand Up @@ -574,7 +574,7 @@ private boolean executeWithImplicitCommitTransaction(final ExecuteCallback callb
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void closeEngine(final ShardingSphereTransactionManagerEngine engine) {
try {
engine.close();
// CHECKSTYLE:OFF
} catch (final Exception ex) {
} catch (final RuntimeException ex) {
// CHECKSTYLE:ON
log.error("Close transaction engine failed", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private ResponseHeader doExecuteWithImplicitCommitTransaction(final Collection<E
result = doExecute(executionContexts);
transactionManager.commit();
// CHECKSTYLE:OFF
} catch (final Exception ex) {
} catch (final RuntimeException ex) {
// CHECKSTYLE:ON
transactionManager.rollback();
String databaseName = databaseConnectionManager.getConnectionSession().getDatabaseName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, NestedTransactionTestCase, SetTransactionTypeTestCase, ReadwriteSplittingInTransactionTestCase
transaction.it.env.cases=TransactionDeadlockTestCase, MultiJDBCConnectionsTestCase, MultiTransactionInConnectionTestCase, MultiOperationsCommitAndRollbackTestCase, MySQLAutoCommitTestCase, PostgreSQLAutoCommitTestCase, BroadcastTableTransactionTestCase, ExceptionInTransactionTestCase, MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase, MySQLSavePointTestCase, MySQLLocalTruncateTestCase, MySQLXATruncateTestCase, OpenGaussCursorTestCase, NestedTransactionTestCase, ReadwriteSplittingInTransactionTestCase
# transaction.it.env.transtypes=LOCAL, XA, BASE
transaction.it.env.transtypes=LOCAL, XA
# transaction.it.env.xa.providers=Atomikos, Bitronix, Narayana
Expand Down

0 comments on commit aec5503

Please sign in to comment.