TestTxService.java 3.1 KB
Newer Older
C
congshuo_cnki 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
package com.cs.service;

import com.cs.entities.Test01;
import com.cs.mapper.TestTxMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class TestTxService {

    @Autowired
    private TestTxMapper testTxMapper;

    @Autowired
    private TestTxService02 testTxService02;

    public Test01 selectTestById(Integer id){
        return testTxMapper.selectTestById(id);
    }


    /**
     * REQUIRED 外部不存在事务时,开启新的事务,外部存在事务时,将进入外部事务中,
     * 如果【调用端发生异常】,则调用和被调用端的事务都将回滚--【有异议】
     *
     * 【相同类中】 REQUIRED 内部调 REQUIRED(异常) 全部失效 - 回滚
     * 【相同类中】 REQUIRED(异常) 内部调 REQUIRED 全部失效 - 回滚
     * 【相同类中】 无事务(异常) 内部调 REQUIRED 全部生效 - 不回滚
     * 【相同类中】 无事务(异常) 内部调 REQUIRED(异常) 全部生效 - 不回滚
     * 【相同类中】 无事务 内部调 REQUIRED(异常) 全部生效 - 不回滚 书上讲的不对
     * 【相同类中】 REQUIRED(异常) 内部调 无事务(异常) 全部失效 - 回滚
     * 【相同类中】 REQUIRED(异常) 内部调 无事务 全部失效 - 回滚
     * 【相同类中】 REQUIRED 内部调 无事务(异常) 全部失效 - 回滚
     *
     * 【不同类中】 REQUIRED 内部调 REQUIRED(异常) 全部失效 - 回滚
     * 【不同类中】 REQUIRED(异常) 内部调 REQUIRED 全部失效 - 回滚
     * 【不同类中】 无事务(异常) 内部调 REQUIRED 全部生效 - 不回滚
     * 【不同类中】 无事务(异常) 内部调 REQUIRED(异常) 外部不回滚-内部回滚
     * 【不同类中】 无事务 内部调 REQUIRED(异常) 外部不回滚-内部回滚  书上讲的不对
     * 【不同类中】 REQUIRED(异常) 内部调 无事务(异常) 全部失效 - 回滚
     * 【不同类中】 REQUIRED(异常) 内部调 无事务 全部失效 - 回滚
     * 【不同类中】 REQUIRED 内部调 无事务(异常) 全部失效 - 回滚
     * @param test01
     * @return
     */


    /**
     *  @Author: CS
     *  @Description:
     *  【相同类中】 REQUIRED 内部调 REQUIRED(异常) 全部失效 - 回滚
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public Integer updateTestById(Test01 test01){
        Integer integer = testTxMapper.updateTestById(test01);
        this.updateTestById01();
//        Integer integer1 = testTxService02.updateTest01ById();
        Integer i = 1 /0;
        return integer;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public Integer updateTestById01(){
        Test01 test01 = new Test01();
        test01.setId(2);
        test01.setName("内部修改");
        Integer integer = testTxMapper.updateTestById(test01);
//        Integer i = 1 /0;
        return integer;
    }


}