NutzCN Logo
问答 nutz指导一下在代码上添加事务?
发布于 2874天前 作者 qq_6427b776 1651 次浏览 复制 上一个帖子 下一个帖子
标签:

具体场景:
1、 我想在下面的5个批量插入内容中,进行一个事务操作,一旦某一个批量报错了,马上回滚。
this.batchInsertList(assetScanResultList, 100, 1);
this.batchInsertList(assetScanResultPortList, 100, 1);
this.batchInsertList(insertUnknownList, 100, 1);
this.batchInsertList(updateUnknownList, 100, 2);
this.batchInsertList(assetScanUnknownPortList, 100, 1);
2、 batchInsertList的方法如下:
private void batchInsertList(List destList, int perNum, int mode) {
Dao dao = Mvcs.ctx.getDefaultIoc().get(Dao.class);
int totalSize = destList.size();
int times = totalSize / perNum;
if (mode == 1) {
for (int i = 0; i <= times; i++) {
List insertList = PageUtil.setListPage(destList, times + 1,
perNum);
dao.fastInsert(insertList);
}
}
if (mode == 2) {
for (int i = 0; i <= times; i++) {
List updateList = PageUtil.setListPage(destList, times + 1,
perNum);
dao.updateIgnoreNull(updateList);
}
}
}
备注一下:我5个批量插入是在一个线程类的一个void 方法里面,并不是在controller里面的。

请各位大神指导一下

4 回复
Trans.exec(new Atom(){
    public void run() {
        this.batchInsertList(assetScanResultList, 100, 1);
        this.batchInsertList(assetScanResultPortList, 100, 1);
        this.batchInsertList(insertUnknownList, 100, 1);
        this.batchInsertList(updateUnknownList, 100, 2);
        this.batchInsertList(assetScanUnknownPortList, 100, 1);
    }
 });

@wendal 直接这样就OK?能否解释一下,这样的原理是什么?

@qq_6427b776 兽兽哥,run方法里面的方法不能用呀?

神马run方法?

添加回复
请先登陆
回到顶部