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/22 03:32:51 UTC
[shardingsphere] branch master updated: Support base-seata transaction for jdbc (#17846)
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 a5d12f96884 Support base-seata transaction for jdbc (#17846)
a5d12f96884 is described below
commit a5d12f96884aff9f48be74a36d24ef64dd5d156e
Author: Guocheng Tang <to...@apache.org>
AuthorDate: Sun May 22 11:32:45 2022 +0800
Support base-seata transaction for jdbc (#17846)
* Support base-seata transaction for jdbc
* add LocalExampleScenario
---
.../example/generator/core/ExampleGenerator.java | 4 +-
.../generator/core/impl/JDBCExampleGenerator.java | 11 ++--
.../generator/core/impl/ProxyExampleGenerator.java | 2 +-
.../YamlExampleConfigurationSupportedValue.java | 2 +-
.../generator/scenario/ExampleScenarioFactory.java | 12 +++-
.../transaction/TransactionExampleScenario.java | 26 +++++++++
.../transaction/type/LocalExampleScenario.java | 52 +++++++++++++++++
.../transaction/type/SeataExampleScenario.java | 57 ++++++++++++++++++
.../type/XAAtomikosExampleScenario.java | 52 +++++++++++++++++
.../type/XABitronixExampleScenario.java | 52 +++++++++++++++++
.../type/XANarayanaExampleScenario.java | 52 +++++++++++++++++
...scenario.transaction.TransactionExampleScenario | 22 +++++++
.../src/main/resources/config.yaml | 3 +-
.../template/jdbc/java/config/Configuration.ftl | 6 +-
.../jdbc/java/repository/jdbc/OrderRepository.ftl | 8 ++-
.../src/main/resources/template/jdbc/pom.ftl | 11 ++++
.../resources/template/jdbc/resources/file.ftl | 57 ++++++++++++++++++
.../resources/template/jdbc/resources/registry.ftl | 68 ++++++++++++++++++++++
.../resources/template/jdbc/resources/seata.ftl | 23 ++++++++
19 files changed, 505 insertions(+), 15 deletions(-)
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java
index 8c23604f33e..e47844572d2 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/ExampleGenerator.java
@@ -42,7 +42,7 @@ public interface ExampleGenerator extends TypedSPI {
for (String eachTransaction : exampleConfig.getTransactions()) {
for (String eachFramework : exampleConfig.getFrameworks()) {
for (String eachFeature : GenerateUtil.generateCombination(exampleConfig.getFeatures())) {
- generate(templateConfig, buildDataModel(exampleConfig.getProps(), eachMode, eachTransaction, eachFramework, eachFeature), eachFramework, eachFeature);
+ generate(templateConfig, buildDataModel(exampleConfig.getProps(), eachMode, eachTransaction, eachFramework, eachFeature), eachFeature, eachFramework, eachTransaction);
}
}
}
@@ -70,5 +70,5 @@ public interface ExampleGenerator extends TypedSPI {
* @throws IOException IO exception
* @throws TemplateException template exception
*/
- void generate(final Configuration templateConfig, final Map<String, String> dataModel, final String framework, final String feature) throws IOException, TemplateException;
+ void generate(final Configuration templateConfig, final Map<String, String> dataModel, final String framework, final String feature, String transaction) throws IOException, TemplateException;
}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/JDBCExampleGenerator.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/JDBCExampleGenerator.java
index 81358b4f76a..5102ff9bb7c 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/JDBCExampleGenerator.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/JDBCExampleGenerator.java
@@ -36,11 +36,12 @@ public final class JDBCExampleGenerator implements ExampleGenerator {
+ "${package}/${framework?replace('-', '/')}";
@Override
- public void generate(final Configuration templateConfig, final Map<String, String> dataModel, final String framework, final String feature) throws IOException, TemplateException {
- GenerateUtil.generateDirs(templateConfig, dataModel, new ExampleScenarioFactory(feature, framework).getJavaClassPaths(), OUTPUT_PATH + JAVA_CLASS_PATH);
- GenerateUtil.generateDirs(templateConfig, dataModel, new ExampleScenarioFactory(feature, framework).getResourcePaths(), OUTPUT_PATH + RESOURCES_PATH);
- GenerateUtil.generateFile(templateConfig, getType(), dataModel, new ExampleScenarioFactory(feature, framework).getJavaClassTemplateMap(), OUTPUT_PATH + JAVA_CLASS_PATH);
- GenerateUtil.generateFile(templateConfig, getType(), dataModel, new ExampleScenarioFactory(feature, framework).getResourceTemplateMap(), OUTPUT_PATH + RESOURCES_PATH);
+ public void generate(final Configuration templateConfig, final Map<String, String> dataModel, final String feature, final String framework, final String transaction) throws IOException, TemplateException {
+ ExampleScenarioFactory exampleScenarioFactory = new ExampleScenarioFactory(feature, framework, transaction);
+ GenerateUtil.generateDirs(templateConfig, dataModel, exampleScenarioFactory.getJavaClassPaths(), OUTPUT_PATH + JAVA_CLASS_PATH);
+ GenerateUtil.generateDirs(templateConfig, dataModel, exampleScenarioFactory.getResourcePaths(), OUTPUT_PATH + RESOURCES_PATH);
+ GenerateUtil.generateFile(templateConfig, getType(), dataModel, exampleScenarioFactory.getJavaClassTemplateMap(), OUTPUT_PATH + JAVA_CLASS_PATH);
+ GenerateUtil.generateFile(templateConfig, getType(), dataModel, exampleScenarioFactory.getResourceTemplateMap(), OUTPUT_PATH + RESOURCES_PATH);
String outputPath = GenerateUtil.generatePath(templateConfig, dataModel, OUTPUT_PATH);
GenerateUtil.processFile(templateConfig, dataModel, getType() + "/pom.ftl", outputPath + "pom.xml");
}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/ProxyExampleGenerator.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/ProxyExampleGenerator.java
index 9c5aea0a834..8a7b39a23d8 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/ProxyExampleGenerator.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/core/impl/ProxyExampleGenerator.java
@@ -31,7 +31,7 @@ import java.util.Map;
*/
public final class ProxyExampleGenerator implements ExampleGenerator {
- public void generate(final Configuration templateConfig, final Map<String, String> dataModel, final String framework, final String feature) throws IOException, TemplateException {
+ public void generate(final Configuration templateConfig, final Map<String, String> dataModel, final String framework, final String feature, final String transaction) throws IOException, TemplateException {
GenerateUtil.generateDirs(templateConfig, dataModel, Collections.singleton("conf"), OUTPUT_PATH + RESOURCES_PATH);
String outputPath = GenerateUtil.generatePath(templateConfig, dataModel, OUTPUT_PATH);
processFile(templateConfig, dataModel, outputPath);
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 ba5c5d446f3..259c4bcf31e 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
@@ -35,7 +35,7 @@ public enum YamlExampleConfigurationSupportedValue {
MODES("modes", new HashSet<>(Arrays.asList("memory", "proxy", "cluster-zookeeper", "cluster-etcd", "standalone-file"))),
- TRANSACTIONS("transactions", new HashSet<>(Arrays.asList("local", "xa-atomikos", "xa-narayana", "xa-bitronix"))),
+ TRANSACTIONS("transactions", new HashSet<>(Arrays.asList("local", "xa-atomikos", "xa-narayana", "xa-bitronix", "base-seata"))),
FEATURES("features", new HashSet<>(Arrays.asList("shadow", "sharding", "readwrite-splitting", "encrypt", "db-discovery"))),
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
index e6e07ab2b06..cb9b29dba9d 100644
--- a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/ExampleScenarioFactory.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.example.generator.scenario;
import org.apache.shardingsphere.example.generator.scenario.feature.FeatureExampleScenario;
import org.apache.shardingsphere.example.generator.scenario.framework.FrameworkExampleScenario;
+import org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
@@ -39,14 +40,18 @@ public final class ExampleScenarioFactory {
private final FrameworkExampleScenario frameworkScenario;
+ private final TransactionExampleScenario transactionScenario;
+
static {
ShardingSphereServiceLoader.register(FeatureExampleScenario.class);
ShardingSphereServiceLoader.register(FrameworkExampleScenario.class);
+ ShardingSphereServiceLoader.register(TransactionExampleScenario.class);
}
- public ExampleScenarioFactory(final String feature, final String framework) {
+ public ExampleScenarioFactory(final String feature, final String framework, final String transaction) {
featureScenarios = getFeatureScenarios(feature);
frameworkScenario = getFrameworkScenario(framework);
+ transactionScenario = getTransactionScenario(transaction);
}
private Collection<FeatureExampleScenario> getFeatureScenarios(final String feature) {
@@ -58,6 +63,10 @@ public final class ExampleScenarioFactory {
return TypedSPIRegistry.getRegisteredService(FrameworkExampleScenario.class, framework);
}
+ private TransactionExampleScenario getTransactionScenario(final String transaction) {
+ return TypedSPIRegistry.getRegisteredService(TransactionExampleScenario.class, transaction);
+ }
+
/**
* Get java class template map.
*
@@ -87,6 +96,7 @@ public final class ExampleScenarioFactory {
result.putAll(each.getResourceTemplateMap());
}
result.putAll(frameworkScenario.getResourceTemplateMap());
+ result.putAll(transactionScenario.getResourceTemplateMap());
result.put("resources/logback.ftl", "logback.xml");
return result;
}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/TransactionExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/TransactionExampleScenario.java
new file mode 100644
index 00000000000..f370d55dec1
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/TransactionExampleScenario.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.generator.scenario.transaction;
+
+import org.apache.shardingsphere.example.generator.scenario.ExampleScenario;
+
+/**
+ * Transaction example scenario.
+ */
+public interface TransactionExampleScenario extends ExampleScenario {
+}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/LocalExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/LocalExampleScenario.java
new file mode 100644
index 00000000000..ea5867cb873
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/LocalExampleScenario.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.generator.scenario.transaction.type;
+
+import org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class LocalExampleScenario implements TransactionExampleScenario {
+
+ @Override
+ public Map<String, String> getJavaClassTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Map<String, String> getResourceTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Collection<String> getJavaClassPaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Collection<String> getResourcePaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public String getType() {
+ return "local";
+ }
+}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/SeataExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/SeataExampleScenario.java
new file mode 100644
index 00000000000..ad217e66be5
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/SeataExampleScenario.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.generator.scenario.transaction.type;
+
+import org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class SeataExampleScenario implements TransactionExampleScenario {
+
+ @Override
+ public Map<String, String> getJavaClassTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Map<String, String> getResourceTemplateMap() {
+ Map<String, String> result = new HashMap<>(4, 1);
+ result.put("resources/file.ftl", "file.conf");
+ result.put("resources/registry.ftl", "registry.conf");
+ result.put("resources/seata.ftl", "seata.conf");
+ return result;
+ }
+
+ @Override
+ public Collection<String> getJavaClassPaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Collection<String> getResourcePaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public String getType() {
+ return "base-seata";
+ }
+}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XAAtomikosExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XAAtomikosExampleScenario.java
new file mode 100644
index 00000000000..be28dbe755e
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XAAtomikosExampleScenario.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.generator.scenario.transaction.type;
+
+import org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class XAAtomikosExampleScenario implements TransactionExampleScenario {
+
+ @Override
+ public Map<String, String> getJavaClassTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Map<String, String> getResourceTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Collection<String> getJavaClassPaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Collection<String> getResourcePaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public String getType() {
+ return "xa-atomikos";
+ }
+}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XABitronixExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XABitronixExampleScenario.java
new file mode 100644
index 00000000000..bb4c507d440
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XABitronixExampleScenario.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.generator.scenario.transaction.type;
+
+import org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class XABitronixExampleScenario implements TransactionExampleScenario {
+
+ @Override
+ public Map<String, String> getJavaClassTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Map<String, String> getResourceTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Collection<String> getJavaClassPaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Collection<String> getResourcePaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public String getType() {
+ return "xa-bitronix";
+ }
+}
diff --git a/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XANarayanaExampleScenario.java b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XANarayanaExampleScenario.java
new file mode 100644
index 00000000000..157dc027e9f
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/scenario/transaction/type/XANarayanaExampleScenario.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.example.generator.scenario.transaction.type;
+
+import org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+public class XANarayanaExampleScenario implements TransactionExampleScenario {
+
+ @Override
+ public Map<String, String> getJavaClassTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Map<String, String> getResourceTemplateMap() {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public Collection<String> getJavaClassPaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Collection<String> getResourcePaths() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public String getType() {
+ return "xa-narayana";
+ }
+}
diff --git a/examples/shardingsphere-example-generator/src/main/resources/META-INF/services/org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario b/examples/shardingsphere-example-generator/src/main/resources/META-INF/services/org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario
new file mode 100644
index 00000000000..1d67d291e75
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/META-INF/services/org.apache.shardingsphere.example.generator.scenario.transaction.TransactionExampleScenario
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.example.generator.scenario.transaction.type.LocalExampleScenario
+org.apache.shardingsphere.example.generator.scenario.transaction.type.SeataExampleScenario
+org.apache.shardingsphere.example.generator.scenario.transaction.type.XAAtomikosExampleScenario
+org.apache.shardingsphere.example.generator.scenario.transaction.type.XABitronixExampleScenario
+org.apache.shardingsphere.example.generator.scenario.transaction.type.XANarayanaExampleScenario
diff --git a/examples/shardingsphere-example-generator/src/main/resources/config.yaml b/examples/shardingsphere-example-generator/src/main/resources/config.yaml
index be73e1c4745..7d0ceafd9f6 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/config.yaml
+++ b/examples/shardingsphere-example-generator/src/main/resources/config.yaml
@@ -23,12 +23,13 @@ products:
modes:
- memory
-# supported: local
+# supported: local, xa-atomikos, xa-narayana, base-seata
transactions:
- local
- xa-atomikos
- xa-narayana
- xa-bitronix
+ - base-seata
# 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 73280b86768..078d1b92613 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
@@ -148,10 +148,14 @@ public final class Configuration {
<#if transaction!="local">
private TransactionRuleConfiguration createTransactionRuleConfiguration() {
- <#if transaction=="xa-narayana">
+ <#if transaction=="xa-atomikos">
+ return new TransactionRuleConfiguration("XA", "Atomikos", new Properties());
+ <#elseif transaction=="xa-narayana">
return new TransactionRuleConfiguration("XA", "Narayana", new Properties());
<#elseif transaction=="xa-bitronix">
return new TransactionRuleConfiguration("XA", "Bitronix", new Properties());
+ <#elseif transaction=="base-seata">
+ return new TransactionRuleConfiguration("BASE", "Seata", new Properties());
</#if>
}
</#if>
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl
index c264d4a046f..125a0def2e7 100644
--- a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/java/repository/jdbc/OrderRepository.ftl
@@ -110,10 +110,12 @@ public final class OrderRepository {
String sql = "INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (?, ?, ?, ?)";
<#if transaction?contains("xa")>
TransactionTypeHolder.set(TransactionType.XA);
+ <#elseif transaction?contains("base")>
+ TransactionTypeHolder.set(TransactionType.BASE);
</#if>
try (Connection connection = dataSource.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
- <#if transaction?contains("xa")>
+ <#if transaction!="local">
connection.setAutoCommit(false);
</#if>
preparedStatement.setInt(1, order.getUserId());
@@ -126,10 +128,10 @@ public final class OrderRepository {
order.setOrderId(resultSet.getLong(1));
}
}
- <#if transaction?contains("xa")>
+ <#if transaction!="local">
connection.commit();
</#if>
- }<#if transaction?contains("xa")> finally {
+ }<#if transaction!="local"> finally {
TransactionTypeHolder.clear();
}
</#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 b737570d52b..6215d37981e 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
@@ -84,6 +84,17 @@
<artifactId>btm</artifactId>
<version>2.1.3</version>
</dependency>
+ <#elseif transaction=="base-seata">
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-base-seata-at</artifactId>
+ <version>${r'${project.version}'}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.seata</groupId>
+ <artifactId>seata-all</artifactId>
+ <version>1.4.2</version>
+ </dependency>
</#if>
<#if framework?contains("jpa")>
<dependency>
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/file.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/file.ftl
new file mode 100644
index 00000000000..96199b120d8
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/file.ftl
@@ -0,0 +1,57 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+transport {
+ # tcp udt unix-domain-socket
+ type = "TCP"
+ #NIO NATIVE
+ server = "NIO"
+ #enable heartbeat
+ heartbeat = true
+ #thread factory for netty
+ thread-factory {
+ boss-thread-prefix = "NettyBoss"
+ worker-thread-prefix = "NettyServerNIOWorker"
+ server-executor-thread-prefix = "NettyServerBizHandler"
+ share-boss-worker = false
+ client-selector-thread-prefix = "NettyClientSelector"
+ client-selector-thread-size = 1
+ client-worker-thread-prefix = "NettyClientWorkerThread"
+ # netty boss thread size,will not be used for UDT
+ boss-thread-size = 1
+ #auto default pin or 8
+ worker-thread-size = 8
+ }
+}
+service {
+ #vgroup->rgroup
+ vgroupMapping.my_test_tx_group = "default"
+ #only support single node
+ default.grouplist = "127.0.0.1:8091"
+ #degrade current not support
+ enableDegrade = false
+ #disable
+ disable = false
+}
+
+client {
+ async.commit.buffer.limit = 10000
+ lock {
+ retry.internal = 10
+ retry.times = 30
+ }
+}
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/registry.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/registry.ftl
new file mode 100644
index 00000000000..0489d85737a
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/registry.ftl
@@ -0,0 +1,68 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+registry {
+ # file 、nacos 、eureka、redis、zk
+ type = "file"
+
+ nacos {
+ serverAddr = "localhost"
+ namespace = "public"
+ cluster = "default"
+ }
+ eureka {
+ serviceUrl = "http://localhost:1001/eureka"
+ application = "default"
+ weight = "1"
+ }
+ redis {
+ serverAddr = "localhost:6379"
+ db = "0"
+ }
+ zk {
+ cluster = "default"
+ serverAddr = "127.0.0.1:2181"
+ session.timeout = 6000
+ connect.timeout = 2000
+ }
+ file {
+ name = "file.conf"
+ }
+}
+
+config {
+ # file、nacos 、apollo、zk
+ type = "file"
+
+ nacos {
+ serverAddr = "localhost"
+ namespace = "public"
+ cluster = "default"
+ }
+ apollo {
+ app.id = "fescar-server"
+ apollo.meta = "http://192.168.1.204:8801"
+ }
+ zk {
+ serverAddr = "127.0.0.1:2181"
+ session.timeout = 6000
+ connect.timeout = 2000
+ }
+ file {
+ name = "file.conf"
+ }
+}
diff --git a/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/seata.ftl b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/seata.ftl
new file mode 100644
index 00000000000..cc997288a85
--- /dev/null
+++ b/examples/shardingsphere-example-generator/src/main/resources/template/jdbc/resources/seata.ftl
@@ -0,0 +1,23 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+sharding.transaction.seata.at.enable = true
+
+client {
+ application.id = jdbc-test
+ transaction.service.group = my_test_tx_group
+}