These are two examples of the actual code in our app using iBatis batch.
Code:
public void insertUserRolesById(final List lst, final String user_id) {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
Iterator itr = lst.iterator();
executor.startBatch();
executor.delete("Users.deleteUserRolesById", user_id);
while (itr.hasNext()) {
HashMap m = (HashMap) itr.next();
executor.insert("Users.insertUserRolesById", m);
}
int rowsaffected = executor.executeBatch();
logger.info("rows afftected by insertUserRolesById: " + rowsaffected);
return new Integer(rowsaffected);
}
});
}
Code:
public void updateElement(final MWDomain fbo) {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
executor.update("AuthMaint.updateConEditionStatus", fbo.getUpdateContentEdition());
executor.update("AuthMaint.updateCatExtendName", fbo.getUpdateCatExtendName());
Iterator itr = fbo.getContentEdition().iterator();
while (itr.hasNext())
executor.insert("AuthMaint.insertContentEdition", ((HashMap) itr.next()));
itr = fbo.getRepItem().iterator();
while (itr.hasNext())
executor.insert("AuthMaint.insertRepItem", ((HashMap) itr.next()));
itr = fbo.getDocMap().iterator();
while (itr.hasNext())
executor.insert("AuthMaint.insertDocMap", ((HashMap) itr.next()));
int rowsaffected = executor.executeBatch();
logger.info("rows afftected by updateFamily: " + rowsaffected);
return null;
}
});
}