Commit aeaa98ba authored by cherrylzhao's avatar cherrylzhao
Browse files

migrate sharding-transaction-jdbc-spring & starter example to spi-impl-example.

parent 1ec71922
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -102,21 +102,11 @@
                <artifactId>sharding-jdbc-orchestration-spring-namespace</artifactId>
                <version>${sharding-sphere.version}</version>
            </dependency>
            <dependency>
                <groupId>io.shardingsphere</groupId>
                <artifactId>sharding-transaction-jdbc-spring</artifactId>
                <version>${sharding-sphere.spi.impl.version}</version>
            </dependency>
            <dependency>
                <groupId>io.shardingsphere</groupId>
                <artifactId>sharding-transaction-proxy-spring</artifactId>
                <version>${sharding-sphere.spi.impl.version}</version>
            </dependency>
            <dependency>
                <groupId>io.shardingsphere</groupId>
                <artifactId>sharding-transaction-jdbc-spring-boot-starter</artifactId>
                <version>${sharding-sphere.spi.impl.version}</version>
            </dependency>
            <dependency>
                <groupId>io.shardingsphere</groupId>
                <artifactId>sharding-transaction-proxy-spring-boot-starter</artifactId>
+0 −2
Original line number Diff line number Diff line
@@ -13,7 +13,5 @@

    <modules>
        <module>transaction-xa-raw-jdbc-example</module>
        <module>transaction-xa-spring-namespace-example</module>
        <module>transaction-xa-spring-boot-example</module>
    </modules>
</project>
+0 −41
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<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-2pc-xa-example</artifactId>
        <version>4.0.0-RC2-SNAPSHOT</version>
    </parent>

    <artifactId>transaction-xa-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-xa-core</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>
+0 −46
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.xa.spring.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
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
public class SpringBootExample {
    
    public static void main(final String[] args) {
        try (ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBootExample.class, args)) {
            processXATransaction(applicationContext);
        }
    }
    
    private static void processXATransaction(final ConfigurableApplicationContext applicationContext) {
        XATransactionalService transactionalService = applicationContext.getBean(XATransactionalService.class);
        transactionalService.processSuccess();
        try {
            transactionalService.processFailure();
        } catch (final Exception ex) {
            transactionalService.printData();
        }
    }
}
+0 −59
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.xa.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 XATransactionalService {
    
    private final JPACommonService jpaCommonService;
    
    @Autowired
    public XATransactionalService(final JPACommonService jpaCommonService) {
        this.jpaCommonService = jpaCommonService;
    }
    
    /**
     * process success, XA transaction will be committed.
     */
    @ShardingTransactionType(TransactionType.XA)
    @Transactional
    public void processSuccess() {
        jpaCommonService.processSuccess();
    }
    
    /**
     * process failure, XA transaction will be rollback.
     */
    @ShardingTransactionType(TransactionType.XA)
    @Transactional
    public void processFailure() {
        jpaCommonService.processFailure();
    }
    
    public void printData() {
        jpaCommonService.printData();
    }
}
Loading