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

sunnianjun 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 24627571ec7 Fix sonar issues (#29324)
24627571ec7 is described below

commit 24627571ec739b465685efaae62e3679544edfeb
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Dec 8 14:24:10 2023 +0800

    Fix sonar issues (#29324)
---
 .../ShowServiceProviderImplementationsExecutor.java     | 17 +++++++++--------
 .../driver/statement/ShardingPreparedStatementTest.java |  2 +-
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowServiceProviderImplementationsExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowServiceProviderImplementationsExecutor.java
index 5c9f4ec7520..dc666166ebc 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowServiceProviderImplementationsExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowServiceProviderImplementationsExecutor.java
@@ -41,20 +41,21 @@ public final class 
ShowServiceProviderImplementationsExecutor implements Queryab
     @Override
     public Collection<LocalDataQueryResultRow> getRows(final 
ShowServiceProviderImplementationsStatement sqlStatement) {
         Collection<LocalDataQueryResultRow> result = new LinkedList<>();
-        Class<?> clazz;
-        try {
-            clazz = Class.forName(sqlStatement.getServiceProviderInterface());
-        } catch (final ClassNotFoundException ex) {
-            throw new 
InvalidValueException(sqlStatement.getServiceProviderInterface());
-        }
-        Collection<?> shardingAlgorithms = 
ShardingSphereServiceLoader.getServiceInstances(clazz);
-        for (Object each : shardingAlgorithms) {
+        for (Object each : 
ShardingSphereServiceLoader.getServiceInstances(getServiceProviderImplementationClass(sqlStatement)))
 {
             TypedSPI implementation = (TypedSPI) each;
             result.add(new 
LocalDataQueryResultRow(implementation.getClass().getSimpleName(), 
implementation.getType(), implementation.getClass().getName()));
         }
         return result;
     }
     
+    private static Class<?> getServiceProviderImplementationClass(final 
ShowServiceProviderImplementationsStatement sqlStatement) {
+        try {
+            return Class.forName(sqlStatement.getServiceProviderInterface());
+        } catch (final ClassNotFoundException ex) {
+            throw new 
InvalidValueException(sqlStatement.getServiceProviderInterface());
+        }
+    }
+    
     @Override
     public Class<ShowServiceProviderImplementationsStatement> getType() {
         return ShowServiceProviderImplementationsStatement.class;
diff --git 
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
 
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
index ca3e1306b54..5dc4c76db16 100644
--- 
a/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
+++ 
b/test/e2e/driver/src/test/java/org/apache/shardingsphere/test/e2e/driver/statement/ShardingPreparedStatementTest.java
@@ -369,7 +369,7 @@ class ShardingPreparedStatementTest extends 
AbstractShardingDriverTest {
     }
     
     @Test
-    public void assertAddBatchWithMultiStatements() throws SQLException {
+    void assertAddBatchWithMultiStatements() throws SQLException {
         try (
                 Connection connection = 
getShardingSphereDataSource().getConnection();
                 PreparedStatement insertStatement = 
connection.prepareStatement(INSERT_WITH_GENERATE_KEY_SQL);

Reply via email to