虽然设置:
queryRequest.setLimit(Integer.MAX_VALUE);
确实照顾许多类型,它不适用于所有类型。
例如,类型Defect和Iteration似乎在单个页面中返回数千个结果(对 Rally 的单个查询调用),而其他类型(例如User和HierarchicalRequirement )忽略了该限制,而是迫使我使用分页(设置 Start然后重新查询)以获取所有结果。
这是我如何处理两者的示例:
// NOTE : no pagination needed for defect or iteration, but required for hierarchicalrequirement or user
QueryRequest queryRequest = new QueryRequest("hierarchicalrequirement");
queryRequest.setFetch(new Fetch(new String[] {"ObjectID", "CreationDate", "LastUpdateDate", "FormattedId"}));
queryRequest.setQueryFilter(new QueryFilter("CreationDate", ">=", "2013-01-01T07:00:00.000Z"));
queryRequest.setLimit(Integer.MAX_VALUE);
int responseTotalResultsCount = Integer.MAX_VALUE;// So we enter while loop first time
int actualResultsProcessedSoFar = 0;
// Handle both cases
while ((queryRequest.getStart()) < responseTotalResultsCount && actualResultsProcessedSoFar < responseTotalResultsCount) {
QueryResponse queryResponse = restApi.query(queryRequest);
responseTotalResultsCount = queryResponse.getTotalResultCount();// Set to correct value here
JsonArray results = queryResponse.getResults();
if (results.size() == 0) {
return;
} else {
for (JsonElement jsonElement : queryResponse.getResults()) {
// Process this particular JsonElement here
// If no pagination required, this counter lets us exit while loop
actualResultsProcessedSoFar++;
}// end for loop
}// end if (results.size() == 0)
// Setting this to handle pagination, if required
queryRequest.setStart(queryRequest.getStart() + queryRequest.getPageSize());
} // end while loop