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 2020/07/26 07:40:55 UTC

[shardingsphere] branch master updated: Refactor the example for transaction (#6444)

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 1f6eab7  Refactor the example for transaction (#6444)
1f6eab7 is described below

commit 1f6eab7a5e942bec513af7a88fc4df7ad92537e5
Author: 孙念君 Sun Nianjun <ka...@outlook.com>
AuthorDate: Sun Jul 26 15:40:39 2020 +0800

    Refactor the example for transaction (#6444)
    
    * Refactor: add main for XA transaction (#5841)
    
    * Add: add exmaple main for transaction (#5841)
    
    * Add: add exmaple main for seata transaction (#5841)
---
 .../transaction/xa/raw/jdbc/ExampleMain.java       | 29 +++++++++++
 .../xa/spring/boot/ExampleMainApplication.java     | 46 ++++++++++++++++++
 .../xa/spring/namspace/ExampleMain.java            | 34 +++++++++++++
 .../base/seata/raw/jdbc/ExampleMain.java           | 38 +++++++++++++++
 .../seata/spring/boot/ExampleMainApplication.java  | 56 ++++++++++++++++++++++
 5 files changed, 203 insertions(+)

diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/raw/jdbc/ExampleMain.java b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/raw/jdbc/ExampleMain.java
new file mode 100644
index 0000000..b3ff63d
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/raw/jdbc/ExampleMain.java
@@ -0,0 +1,29 @@
+/*
+ * 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.transaction.xa.raw.jdbc;
+
+
+public class ExampleMain {
+    
+    public static void main(final String[] args) throws Exception {
+        XAOrderService orderService = new XAOrderService("/META-INF/sharding-databases-tables.yaml");
+        orderService.init();
+        orderService.insert();
+        orderService.cleanup();
+    }
+}
diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-spring-boot-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/spring/boot/ExampleMainApplication.java b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-spring-boot-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/spring/boot/ExampleMainApplication.java
new file mode 100644
index 0000000..2e6851c
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-spring-boot-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/spring/boot/ExampleMainApplication.java
@@ -0,0 +1,46 @@
+/*
+ * 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.transaction.xa.spring.boot;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.Profile;
+
+import javax.annotation.PostConstruct;
+
+@SpringBootApplication
+@Import(TransactionConfiguration.class)
+@Profile("sharding-databases-tables")
+public class ExampleMainApplication {
+    
+    @Autowired
+    XAOrderService orderService;
+    
+    public static void main(final String[] args) {
+        SpringApplication.run(ExampleMainApplication.class, args);
+    }
+    
+    @PostConstruct
+    public void executeOrderService() {
+        orderService.init();
+        orderService.selectAll();
+        orderService.cleanup();
+    }
+}
diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-spring-namespace-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/spring/namspace/ExampleMain.java b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-spring-namespace-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/spring/namspace/ExampleMain.java
new file mode 100644
index 0000000..30762c9
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-2pc-xa-spring-namespace-example/src/main/java/org/apache/shardingsphere/example/transaction/xa/spring/namspace/ExampleMain.java
@@ -0,0 +1,34 @@
+/*
+ * 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.transaction.xa.spring.namspace;
+
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.ImportResource;
+
+@ImportResource(locations = {"/META-INF/application-sharding-databases-tables.xml"})
+public class ExampleMain {
+    
+    public static void main(final String[] args) {
+        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ExampleMain.class);
+        XAOrderService xaOrderService = applicationContext.getBean("XAOrderService", XAOrderService.class);
+        xaOrderService.init();
+        xaOrderService.init();
+        xaOrderService.selectAll();
+        xaOrderService.cleanup();
+    }
+}
diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-base-seata-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/transaction/base/seata/raw/jdbc/ExampleMain.java b/examples/shardingsphere-jdbc-example/transaction-example/transaction-base-seata-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/transaction/base/seata/raw/jdbc/ExampleMain.java
new file mode 100644
index 0000000..185218b
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-base-seata-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/transaction/base/seata/raw/jdbc/ExampleMain.java
@@ -0,0 +1,38 @@
+/*
+ * 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.transaction.base.seata.raw.jdbc;
+
+/**
+ Requirement before running this test:
+ 1. create undo_log table in demo_ds_0 and demo_ds_1
+ 2. startup seata-server-1.0.0 (https://github.com/seata/seata/releases)
+ make sure:
+ - registry.type = "file"
+ - config.ype = "file"
+ - service.vgroup_mapping.my_test_tx_group = "default"
+ */
+public class ExampleMain {
+    
+    public static void main(final String[] args) throws Exception {
+        SeataATOrderService orderService = new SeataATOrderService("/META-INF/sharding-databases-tables.yaml");
+        orderService.init();
+        orderService.insert();
+        orderService.selectAll();
+        orderService.cleanup();
+    }
+}
diff --git a/examples/shardingsphere-jdbc-example/transaction-example/transaction-base-seata-spring-boot-example/src/main/java/org/apache/shardingsphere/example/transaction/base/seata/spring/boot/ExampleMainApplication.java b/examples/shardingsphere-jdbc-example/transaction-example/transaction-base-seata-spring-boot-example/src/main/java/org/apache/shardingsphere/example/transaction/base/seata/spring/boot/ExampleMainApplication.java
new file mode 100644
index 0000000..5b417de
--- /dev/null
+++ b/examples/shardingsphere-jdbc-example/transaction-example/transaction-base-seata-spring-boot-example/src/main/java/org/apache/shardingsphere/example/transaction/base/seata/spring/boot/ExampleMainApplication.java
@@ -0,0 +1,56 @@
+/*
+ * 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.transaction.base.seata.spring.boot;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Import;
+import org.springframework.context.annotation.Profile;
+
+import javax.annotation.PostConstruct;
+
+/**
+ Requirement before running this test:
+ 1. create undo_log table in demo_ds_0 and demo_ds_1
+ 2. startup seata-server-1.0.0 (https://github.com/seata/seata/releases)
+ make sure:
+ - registry.type = "file"
+ - config.ype = "file"
+ - service.vgroup_mapping.my_test_tx_group = "default"
+ */
+@SpringBootApplication
+@Import(TransactionConfiguration.class)
+@Profile("sharding-databases-tables")
+public class ExampleMainApplication {
+    
+    @Autowired
+    private SeataATOrderService orderService;
+    
+    public static void main(final String[] args) {
+        SpringApplication.run(ExampleMainApplication.class, args);
+    }
+    
+    @PostConstruct
+    public void executeOrderService() {
+        orderService.init();
+        orderService.selectAll();
+        orderService.cleanup();
+    }
+}