You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/09 02:15:12 UTC
[shardingsphere] branch master updated: Support xa-narayana transaction for jdbc (#17454)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 9e7953cd5ff Support xa-narayana transaction for jdbc (#17454)
9e7953cd5ff is described below
commit 9e7953cd5ff901b5d19276108af6da2f0ae63c1f
Author: Guocheng Tang <to...@apache.org>
AuthorDate: Mon May 9 10:15:06 2022 +0800
Support xa-narayana transaction for jdbc (#17454)
---
.../YamlExampleConfigurationSupportedValue.java | 2 +-
.../src/main/resources/config.yaml | 1 +
.../template/jdbc/java/config/Configuration.ftl | 12 ++++++++++
.../template/jdbc/java/main/JDBCExampleMain.ftl | 3 +++
.../src/main/resources/template/jdbc/pom.ftl | 27 ++++++++++++++++++++++
5 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationSupportedValue.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationSupportedValue.java
index 28c9a12f07c..769b154bb59 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationSupportedValue.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/yaml/config/YamlExampleConfigurationSupportedValue.java
@@ -34,7 +34,7 @@ public enum YamlExampleConfigurationSupportedValue {
MODES("modes", Sets.newHashSet("memory", "proxy", "cluster-zookeeper", "cluster-etcd", "standalone-file")),
- TRANSACTIONS("transactions", Sets.newHashSet("local", "xa-atomikos")),
+ TRANSACTIONS("transactions", Sets.newHashSet("local", "xa-atomikos", "xa-narayana")),
FEATURES("features", Sets.newHashSet("shadow", "sharding", "readwrite-splitting", "encrypt", "db-discovery")),
diff --git a/examples/shardingsphere-example-generator/src/main/resources/config.yaml b/examples/shardingsphere-example-generator/src/main/resources/config.yaml
index 7baefd2fc97..e8c6da34943 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/config.yaml
+++ b/examples/shardingsphere-example-generator/src/main/resources/config.yaml
@@ -27,6 +27,7 @@ modes:
transactions:
- local
- xa-atomikos
+ - xa-narayana
# supported: sharding,readwrite-splitting,encrypt,shadow,db-discovery
features:
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
index 07f04ef52b1..9e43a1cddf1 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/config/Configuration.ftl
@@ -56,6 +56,9 @@ import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDa
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
</#if>
+<#if transaction=="xa-narayana">
+import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
+</#if>
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -118,6 +121,9 @@ public final class Configuration {
private Collection<RuleConfiguration> createRuleConfiguration() {
Collection<RuleConfiguration> result = new LinkedList<>();
+ <#if transaction=="xa-narayana">
+ result.add(createTransactionRuleConfiguration());
+ </#if>
<#if feature?contains("db-discovery")>
result.add(createDatabaseDiscoveryRuleConfiguration());
</#if>
@@ -139,6 +145,12 @@ public final class Configuration {
<#list feature?split(",") as item>
<#include "${item}.ftl">
</#list>
+ <#if transaction=="xa-narayana">
+
+ private TransactionRuleConfiguration createTransactionRuleConfiguration() {
+ return new TransactionRuleConfiguration("XA", "Narayana", new Properties());
+ }
+ </#if>
private Properties createProperties() {
Properties result = new Properties();
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/JDBCExampleMain.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/JDBCExampleMain.ftl
index d7ff477422b..5fe2cc02237 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/JDBCExampleMain.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/main/JDBCExampleMain.ftl
@@ -31,5 +31,8 @@ public final class ExampleMain {
DataSource dataSource = config.createDataSource();
ExampleService exampleService = new ExampleService(dataSource);
exampleService.run();
+ <#if transaction=="xa-narayana">
+ System.exit(1);
+ </#if>
}
}
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
index 08ec3cbf4ee..02040e1ee51 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/pom.ftl
@@ -47,6 +47,33 @@
<version>${r'${project.version}'}</version>
</dependency>
</#if>
+ <#if transaction=="xa-narayana">
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-xa-narayana</artifactId>
+ <version>${r'${project.version}'}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.narayana.jta</groupId>
+ <artifactId>jta</artifactId>
+ <version>5.9.1.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.narayana.jts</groupId>
+ <artifactId>narayana-jts-integration</artifactId>
+ <version>5.9.1.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-transaction-spi</artifactId>
+ <version>7.6.0.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging</artifactId>
+ <version>3.2.1.Final</version>
+ </dependency>
+ </#if>
<#if framework?contains("jpa")>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>