随笔 - 32, 文章 - 1, 评论 - 5, 引用 - 0
数据加载中……

批处理异常问题

ibatis 批处理唯一性异常,执行到事务结束。

循环第二次执行批处理时会将表锁死。

SqlMapClient smc = this.getSqlMapClient();
        
int index = 0;
        
try {
            smc.startTransaction();
            smc.startBatch();
            
            TCuBillfileChecks check 
= new TCuBillfileChecks();
            check.setTaskname(taskName);
            
for (int i = 0; i < recordList.size(); i++{
                Record record 
= recordList.get(i);
                Object    custInfo 
= pojoFactory.generatePojo(taskName, billMonth, record);
                smc.insert(taskName 
+ ".insert_custinfo", custInfo);
                
if (index ++ > batchNum) {// 记录断点
                    check.setBillname(record.getAttribute("Source_FileName"));
                    check.setFilenum(Integer.parseInt(record.getAttribute(
"RowNum")));
                    smc.update(
"T_CU_BILLFILE_CHECKS.updateByPrimaryKey", check);
                    smc.executeBatch();
                    index 
= 0;
                }

            }


            check.setBillname(recordList.get(recordList.size() 
- 1).getAttribute("Source_FileName"));
            check.setFilenum(Integer.parseInt(recordList.get(recordList.size() 
- 1).getAttribute("RowNum")));
            smc.update(
"T_CU_BILLFILE_CHECKS.updateByPrimaryKey", check);
            smc.executeBatch();
        }
 catch (Exception e) {
            e.printStackTrace();
        }
 finally {
            
try {
                smc.commitTransaction();
                smc.endTransaction();
            }
 catch (Exception e) {
                e.printStackTrace();
            }

        }

posted on 2010-12-17 17:51 colorfire 阅读(379) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: