首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

ibatis批量平添

2012-09-22 
ibatis批量添加/*** 批量提交EtlTask* @param taskList*/public void insert(final ListEtlTask taskLis

ibatis批量添加
/**
     * 批量提交EtlTask
     * @param taskList
     */
    public void insert(final List<EtlTask> taskList) {

        try {
            this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
                public Object doInSqlMapClient(SqlMapExecutor executor)
                                                                       throws SQLException {
                    executor.startBatch();
                    int batch = 0;
                    for (EtlTask task : taskList) {
                           executor.insert("SERV_ETL_TASK.insertFromProgram", task);
                        batch++;
                        //每500条批量提交一次。
                        if (batch == 500) {
                            executor.executeBatch();
                            batch = 0;
                        }
                    }
                    executor.executeBatch();
                    return null;
                }
            });

        } catch (DataAccessException ex) {
            logger.error("每天初始化任务中,添加新 ETL Task 记录出错", ex);
            throw ex;
        }
    }

热点排行