Spring+ibatis批量存储

1、
public class LocalDaoImpl extends SqlMapClientDaoSupport implements LocalDao {


    public void insertBuNaTaxBatLst(final PaginatedList list)
    {
         getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
                public Object doInSqlMapClient(SqlMapExecutor executor)
                        throws SQLException {
                    executor.startBatch();
                    // do some iBatis operations here
                    for(int i=0,count=list.size();i<count;i++)
                    {    
                        executor.insert("insertBuNaTaxBatLst", list.get(i));
                        if (i % 50 == 0) {
                            System.out.println("----" + i);//没有意义只为测试
                        }
                    }
                    executor.executeBatch();
                    return null;
                }
            });
    }


}
2、注意ibatis的事物默认情况下是自动提交的,如果发现速度上有问题可以留意一下,ibatis只有在显示的声明事物管理的情况下才自动将事物管理改为不自动方式。
3、还是startBatch(),据我测试分析这个鬼东西只有在executeBatch(),才把所有的语句提交到数据库,在提交之前缓存中保留了大量的sql语句和数据对象,很有可能out of memony,对此要留意,可以在大量数据要做插入时,分批用Batch,如:有40000条数据可将其分为4个Batch块,让后将这4个Batch用一个事物提交以保证数据完整性。

你可能感兴趣的:(spring,数据库,ibatis,object,测试,Class)