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

panjuan 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 0b657c8dc1a Refactor DataSourceSwapper (#25789)
0b657c8dc1a is described below

commit 0b657c8dc1a15a233c04e40dc67fca1f1abd7146
Author: Liang Zhang <[email protected]>
AuthorDate: Fri May 19 12:56:52 2023 +0800

    Refactor DataSourceSwapper (#25789)
---
 .../xa/jta/datasource/swapper/DataSourceSwapper.java        | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
index 54b481c81ce..305751eca8c 100644
--- 
a/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
+++ 
b/kernel/transaction/type/xa/core/src/main/java/org/apache/shardingsphere/transaction/xa/jta/datasource/swapper/DataSourceSwapper.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.transaction.xa.jta.datasource.swapper;
 import com.google.common.base.CaseFormat;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
-import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.transaction.xa.jta.datasource.properties.XADataSourceDefinition;
 import 
org.apache.shardingsphere.transaction.xa.jta.exception.XADataSourceInitializeException;
@@ -30,8 +29,6 @@ import javax.sql.XADataSource;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
@@ -61,17 +58,13 @@ public final class DataSourceSwapper {
     }
     
     private XADataSource createXADataSource() {
-        XADataSource result = null;
-        List<ReflectiveOperationException> exceptions = new LinkedList<>();
         for (String each : xaDataSourceDefinition.getXADriverClassNames()) {
             try {
-                result = loadXADataSource(each);
-            } catch (final ReflectiveOperationException ex) {
-                exceptions.add(ex);
+                return loadXADataSource(each);
+            } catch (final ReflectiveOperationException ignored) {
             }
         }
-        ShardingSpherePreconditions.checkState(null != result || 
exceptions.isEmpty(), () -> new 
XADataSourceInitializeException(xaDataSourceDefinition));
-        return result;
+        throw new XADataSourceInitializeException(xaDataSourceDefinition);
     }
     
     private XADataSource loadXADataSource(final String xaDataSourceClassName) 
throws ReflectiveOperationException {

Reply via email to