Unverified Commit 06528345 authored by zhaojun's avatar zhaojun Committed by GitHub
Browse files

Merge pull request #160 from cherrylzhao/dev

add sharding-transaction-seata-spring-boot & namespace.
parents 91b0e6e5 b33d5b00
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ public class SagaTransactionalService {
    }
    
    /**
     * process success, XA transaction will be committed.
     * process success.
     */
    @ShardingTransactionType(TransactionType.BASE)
    @Transactional
@@ -44,7 +44,7 @@ public class SagaTransactionalService {
    }
    
    /**
     * process failure, XA transaction will be rollback.
     * process failure.
     */
    @ShardingTransactionType(TransactionType.BASE)
    @Transactional
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@
    
    <modules>
        <module>transaction-base-seata-raw-jdbc-example</module>
        <module>transaction-base-seata-spring-boot-example</module>
        <module>transaction-base-seata-spring-namespace-example</module>
    </modules>
    
    <dependencies>
+58 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ 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.
  -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.apache.shardingsphere.example</groupId>
        <artifactId>transaction-base-seata-example</artifactId>
        <version>4.0.0-RC2-SNAPSHOT</version>
    </parent>
    <artifactId>transaction-base-seata-spring-boot-example</artifactId>
    
    <dependencies>
        <dependency>
            <groupId>org.apache.shardingsphere.example</groupId>
            <artifactId>repository-jpa</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-transaction-base-seata-at</artifactId>
        </dependency>
        <dependency>
            <groupId>io.shardingsphere</groupId>
            <artifactId>sharding-transaction-jdbc-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
    </dependencies>

</project>
 No newline at end of file
+58 −0
Original line number Diff line number Diff line
/*
 * 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.apache.shardingsphere.example.common.jpa.service.JPACommonService;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class SeataTransactionalService {
    
    private final JPACommonService jpaCommonService;
    
    @Autowired
    public SeataTransactionalService(final JPACommonService jpaCommonService) {
        this.jpaCommonService = jpaCommonService;
    }
    
    /**
     * process success.
     */
    @ShardingTransactionType(TransactionType.BASE)
    @Transactional
    public void processSuccess() {
        jpaCommonService.processSuccess();
    }
    
    /**
     * process failure.
     */
    @ShardingTransactionType(TransactionType.BASE)
    @Transactional
    public void processFailure() {
        jpaCommonService.processFailure();
    }
    
    public void printData() {
        jpaCommonService.printData();
    }
}
+47 −0
Original line number Diff line number Diff line
/*
 * 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.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan({"org.apache.shardingsphere.example"})
@EntityScan(basePackages = "org.apache.shardingsphere.example.common.jpa.entity")
@SpringBootApplication(exclude = JtaAutoConfiguration.class)
public class SpringBootExample {
    
    public static void main(final String[] args) {
        try (ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBootExample.class, args)) {
            processSeataTransaction(applicationContext);
        }
    }
    
    private static void processSeataTransaction(final ConfigurableApplicationContext applicationContext) {
        SeataTransactionalService transactionalService = applicationContext.getBean(SeataTransactionalService.class);
        transactionalService.processSuccess();
        try {
            transactionalService.processFailure();
        } catch (final Exception ex) {
            transactionalService.printData();
        }
    }
}
Loading