admin
2021-04-13 5300c070d95f9f3d6222b149e8431e77e9337637
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
package com.yeshi.buwan.service.manager;
 
import com.ks.goldcorn.pojo.DO.GoldCornGetSource;
import com.ks.goldcorn.service.remote.GoldCornGetSourceService;
import com.yeshi.buwan.dao.user.LoginUserDao;
import com.yeshi.buwan.domain.user.LoginUser;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
@Component
public class SeataManagerTest {
 
    @Resource
    private LoginUserDao loginUserDao;
 
    @Reference(version = "1.0")
    private GoldCornGetSourceService goldCornGetSourceService;
 
    @GlobalTransactional(timeoutMills = 30000, name = "buwan-order", rollbackFor = Exception.class)
    public void addGetResource() throws Exception {
//        loginUserDao.selectByPrimaryKeyForUpdate("50134");
        System.out.println("开始全局事务,XID = " + RootContext.getXID());
        LoginUser loginUser = new LoginUser();
        loginUser.setId("50134");
        loginUser.setName("test9");
        loginUserDao.updateSelective(loginUser);
 
        GoldCornGetSource get = new GoldCornGetSource();
        get.setAppId(15L);
        get.setSourceCode("test5");
        get.setSourceName("测试");
        get.setGoldCorn(1);
 
        goldCornGetSourceService.addSource(get);
        throw new Exception("手动报错");
    }
 
}