Batch Update

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.
}