executeBatch
executeBatch(String sessionID, CommandImpl[] commands)
executeBatch 方法使您可以通过对运行时服务器的单一请求来执行多个方法。
*
sessionID - 用于标识会话标识的字符串。此会话标识用于此方法调用所运行的所有命令。
*
commandImpl[] - 一组 CommandImpl 对象,一个对象对应于您要执行的一个命令。
调用此方法的结果等效于显式调用 Command 数组中的每个方法。此方法可在最大程度上降低对运行时服务器的实际请求的数量。运行时服务器连续运行每个方法;对于每个调用,将在对应于此方法调用的 Response 对象中捕获任何错误或警告。 如果遇到错误,那么 executeBatch 将继续运行批处理中的其余调用。如果运行任何方法导致了错误,那么 BatchResponse 对象的顶级状态将反映此错误。如果没有发生错误,那么顶级状态反映了可能发生的任何警告。如果未发生警告,那么顶级状态反映成功运行了批处理。
返回值
运行时服务器对应于包含 BatchResponse 对象的 executeBatch
示例
以下示例表明如何通过单一 executeBatch 调用来调用所有 getOffer 和 postEvent 方法,以及有关如何处理响应的建议。
/** Define all variables for all members of the executeBatch*/
String sessionId="MySessionID-123";
String interactionPoint = "Overview Page Banner 1";
int numberRequested=1;
String eventName = "logOffer";

/** build the getOffers command */
Command getOffersCommand = new CommandImpl();
getOffersCommand.setMethodIdentifier(Command.COMMAND_GETOFFERS);
getOffersCommand.setInteractionPoint(interactionPoint);
getOffersCommand.setNumberRequested(numberRequested);

/** build the postEvent command */
Command postEventCommand = new CommandImpl();
postEventCommand.setMethodIdentifier(Command.COMMAND_POSTEVENT);
postEventCommand.setEventParameters(postEventParameters);
postEventCommand.setEvent(eventName);

/** Build command array */
Command[] commands =
{
getOffersCommand,
postEventCommand,
};

/** Make the call */
BatchResponse batchResponse = api.executeBatch(sessionId, commands);

/** Process the response appropriately */
// Top level status code is a short cut to determine if there
// are any non-successes in the array of Response objects
if(batchResponse.getBatchStatusCode() == Response.STATUS_SUCCESS)
{
System.out.println("ExecuteBatch ran perfectly!");
}
else if(batchResponse.getBatchStatusCode() == Response.STATUS_WARNING)
{
System.out.println("ExecuteBatch call processed with at least one warning");
}
else
{
System.out.println("ExecuteBatch call processed with at least one error");
}

// Iterate through the array, and print out the message for any non-successes
for(Response response : batchResponse.getResponses())
{
if(response.getStatusCode()!=Response.STATUS_SUCCESS)
{
printDetailMessageOfWarningOrError("executeBatchCommand",
response.getAdvisoryMessages());
}
}