论坛首页 Java企业应用论坛

ibatis批处理

浏览 3897 次
锁定老帖子 主题:ibatis批处理
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-09-05  
public Integer saveTemp(final List<Temp>temp){ 
		int size=0; 
		getSqlMapClientTemplate().execute(new SqlMapClientCallback(){ 
		public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException { 
		   executor.startBatch(); 
		   int count=0;
		   for(Temp Temp:temp){
		    count++; 
		    if(temp.size()%100==0){ 
			    logger.debug("执行第["+count+"]个200条数据..."); 
			    executor.insert("Temp.saveTemp",Temp); 
		     } 
		    } 
		    int size=executor.executeBatch(); 
		    logger.debug("本次批量操作共执行了["+size+"]条数据...");
			return null; 
		    } 
		}); 
		return size; 
		}
	
	public void batchInsert(final List<Temp> temp) throws Exception{
	    this.getSqlMapClientTemplate().execute(new SqlMapClientCallback(){ 
	    public Object doInSqlMapClient(SqlMapExecutor executor) 
	            throws SQLException { 
	    executor.startBatch(); 
	    int batch = 0; 
	    for(Temp Temp:temp){ 
	    //调用获取sequence的方法。如果没有的话就去掉这行代码。 
	    //TreeCate.setTreeCateId(getNextId()); 
	    //参数1为:ibatis中需要执行的语句的id 
	    executor.insert("Temp.saveTemp", Temp); 
	    batch++; 
	    //每500条批量提交一次。 
	    if(batch==50000){ 
	    executor.executeBatch(); 
	    batch = 0; 
	    } 
	    } 
	    executor.executeBatch(); 
	    return null; 
	    } 
	    }); 
	} 
 
   发表时间:2011-10-16  
这个批处理操作,楼主可以对照一下:
http://yin-bp.iteye.com/blog/1197172
0 请登录后投票
   发表时间:2011-12-23  
大哥,不知道你这个批处理自己试过没有?如果我的sql是动态的,比如带<isNotEmpty> 等,这时候的批量就会失效,求解决方案。
0 请登录后投票
   发表时间:2011-12-23  
前一个月之前,我用ibatis 的时候,发现了这个问题,不是针对你的代码的。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics