Skip to content

Commit

Permalink
Refactor the example for transaction (apache#6444)
Browse files Browse the repository at this point in the history
* Refactor: add main for XA transaction (apache#5841)

* Add: add exmaple main for transaction (apache#5841)

* Add: add exmaple main for seata transaction (apache#5841)
  • Loading branch information
taojintianxia authored Jul 26, 2020
1 parent e5b33b1 commit 1f6eab7
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 1f6eab7

Please sign in to comment.