@RequiresSession
  public List<HostRoleCommandEntity> findByPKs(Collection<Long> taskIds) {
    TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery(
      "SELECT task FROM HostRoleCommandEntity task WHERE task.taskId IN ?1 " +
        "ORDER BY task.taskId",
      HostRoleCommandEntity.class);

    List<HostRoleCommandEntity> result = new ArrayList<>();
    SQLOperations.batch(taskIds, SQLConstants.IN_ARGUMENT_MAX_SIZE, (chunk, currentBatch, totalBatches, totalSize) -> {
      result.addAll(daoUtils.selectList(query, chunk));
      return 0;
    });

    return Lists.newArrayList(result);
  }
Loads the counts of tasks for a request and groups them by stage id.
This allows for very efficient loading when there are a huge number of stages
and tasks to iterate (for example, during a Stack Upgrade).
@param requestId the request id
@return the map of stage-to-summary objects
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java