Executing a Batch update is similar to that of insert except that the query model is that of an update model and not insert model. Here also, the first step is defining the query model -
<update id="EMPLOYEE_BATCH_UPDATE_MYAPP" parameterClass ="java.util.HashMap">
UPDATE EMPLOYEE
SET EMP_NAME = #EmployeeName#, MOB_NO = #mobileNum#
WHERE EMP_ID = #EmployeeId#
</update>
Execution of the Database Request again is very similar to earlier examples -
try {
List<Map> batchData = getAllEmployeesToUpdate(); //Prepare the list of records to update
DatabaseRequest dbRequest = new DatabaseRequest();
dbRequest.setDataAccessMapKey("EMPLOYEE");
dbRequest.setOperation(DatabaseConstants.BATCH_UPDATE)
dbRequest.setOperationExtension("MYAPP");
dbRequest.setBatchData(paramData); //Add the batch data to the request
DatabaseResult dbResult = dbRequest.execute(); //Execute the request.
logger.debug("No. of rows affected = " + dbResult.getNoOfRowsAffected());
} catch (DatabaseException dbException) {
//Handle the exception appropriately.
}
References
The following links provided are purely as a point of reference for any additional reading around Data Access Layer and common libraries or frameworks available.
- IBATIS in Action – This is a good book by the author of the iBATIS framework that will set the tone for anyone looking to learn iBATIS
- Online Tutorial on iBATIS - ↗
- Another online tutorial on iBATIS mapping - ↗