You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by to...@apache.org on 2022/04/30 04:46:34 UTC

[shardingsphere] branch master updated: Refactor XATransactionManagerProviderFactory (#17221)

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

totalo 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 ed881bf3405 Refactor XATransactionManagerProviderFactory (#17221)
ed881bf3405 is described below

commit ed881bf340588a1a5cefea62e40906240c9e85e0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Apr 30 12:46:17 2022 +0800

    Refactor XATransactionManagerProviderFactory (#17221)
---
 .../xa/XAShardingSphereTransactionManager.java      |  4 ++--
 ...ava => XATransactionManagerProviderFactory.java} | 21 +++++----------------
 ...=> XATransactionManagerProviderFactoryTest.java} | 10 +++++-----
 .../src/test/resources/logback-test.xml             |  2 +-
 4 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
index 0e578f31f60..ba913077f07 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/XAShardingSphereTransactionManager.java
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.transaction.core.TransactionType;
 import org.apache.shardingsphere.transaction.rule.TransactionRule;
 import org.apache.shardingsphere.transaction.spi.ShardingSphereTransactionManager;
 import org.apache.shardingsphere.transaction.xa.jta.datasource.XATransactionDataSource;
-import org.apache.shardingsphere.transaction.xa.manager.XATransactionManagerProviderLoader;
+import org.apache.shardingsphere.transaction.xa.manager.XATransactionManagerProviderFactory;
 import org.apache.shardingsphere.transaction.xa.spi.XATransactionManagerProvider;
 
 import javax.sql.DataSource;
@@ -52,7 +52,7 @@ public final class XAShardingSphereTransactionManager implements ShardingSphereT
     
     @Override
     public void init(final DatabaseType databaseType, final Collection<ResourceDataSource> resourceDataSources, final TransactionRule transactionRule) {
-        xaTransactionManagerProvider = XATransactionManagerProviderLoader.getInstance().getXATransactionManagerProvider(transactionRule.getProviderType());
+        xaTransactionManagerProvider = XATransactionManagerProviderFactory.newInstance(transactionRule.getProviderType());
         xaTransactionManagerProvider.init();
         resourceDataSources.forEach(each -> cachedDataSources.put(each.getOriginalName(), newXATransactionDataSource(databaseType, each)));
     }
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderLoader.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManager [...]
similarity index 72%
rename from shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderLoader.java
rename to shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderFactory.java
index 7110ef0446c..8d42adaa2e7 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderLoader.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/main/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderFactory.java
@@ -27,33 +27,22 @@ import org.apache.shardingsphere.transaction.xa.spi.XATransactionManagerProvider
 import java.util.Properties;
 
 /**
- * XA transaction manager provider loader.
+ * XA transaction manager provider factory.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class XATransactionManagerProviderLoader {
-    
-    private static final XATransactionManagerProviderLoader INSTANCE = new XATransactionManagerProviderLoader();
+public final class XATransactionManagerProviderFactory {
     
     static {
         ShardingSphereServiceLoader.register(XATransactionManagerProvider.class);
     }
     
     /**
-     * Get instance of XA transaction manager provider SPI loader.
-     *
-     * @return instance of XA transaction manager provider SPI loader
-     */
-    public static XATransactionManagerProviderLoader getInstance() {
-        return INSTANCE;
-    }
-    
-    /**
-     * Get XA transaction manager provider.
+     * Create new instance of XA transaction manager provider.
      *
      * @param type XA transaction manager provider type
-     * @return XA transaction manager provider
+     * @return new instance of XA transaction manager provider
      */
-    public XATransactionManagerProvider getXATransactionManagerProvider(final String type) {
+    public static XATransactionManagerProvider newInstance(final String type) {
         return null == type
                 ? RequiredSPIRegistry.getRegisteredService(XATransactionManagerProvider.class)
                 : TypedSPIRegistry.getRegisteredService(XATransactionManagerProvider.class, type, new Properties());
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderLoaderTest.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionMan [...]
similarity index 70%
rename from shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderLoaderTest.java
rename to shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderFactoryTest.java
index a38b9e551f8..3d2401eb9d6 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderLoaderTest.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/manager/XATransactionManagerProviderFactoryTest.java
@@ -26,15 +26,15 @@ import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertThat;
 
 @RunWith(MockitoJUnitRunner.class)
-public final class XATransactionManagerProviderLoaderTest {
+public final class XATransactionManagerProviderFactoryTest {
     
     @Test
-    public void assertGetDefaultTransactionManagerProvider() {
-        assertThat(XATransactionManagerProviderLoader.getInstance().getXATransactionManagerProvider(null), instanceOf(AtomikosTransactionManagerProvider.class));
+    public void assertNewDefaultInstance() {
+        assertThat(XATransactionManagerProviderFactory.newInstance(null), instanceOf(AtomikosTransactionManagerProvider.class));
     }
     
     @Test
-    public void assertGetTransactionManagerProvider() {
-        assertThat(XATransactionManagerProviderLoader.getInstance().getXATransactionManagerProvider("Atomikos"), instanceOf(AtomikosTransactionManagerProvider.class));
+    public void assertNewInstance() {
+        assertThat(XATransactionManagerProviderFactory.newInstance("Atomikos"), instanceOf(AtomikosTransactionManagerProvider.class));
     }
 }
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/resources/logback-test.xml b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/resources/logback-test.xml
index bc05b3d5cab..399ef817994 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/resources/logback-test.xml
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/resources/logback-test.xml
@@ -25,7 +25,7 @@
     <logger name="org.apache.shardingsphere" level="warn" additivity="false">
         <appender-ref ref="console" />
     </logger>
-    <logger name="org.apache.shardingsphere.transaction.xa.manager.XATransactionManagerProviderLoader" level="off" />
+    <logger name="org.apache.shardingsphere.transaction.xa.manager.XATransactionManagerProviderFactory" level="off" />
     
     <root>
         <level value="error" />