@RequiresSession
  public boolean isAllTasksCompleted(long requestId) {
    TypedQuery<Long> query = entityManagerProvider.get().createQuery(
        "SELECT task.taskId FROM HostRoleCommandEntity task WHERE task.requestId = ?1 AND " +
          "task.stageId=(select max(stage.stageId) FROM StageEntity stage WHERE stage.requestId=?1) " +
          "AND task.status NOT IN ?2",
        Long.class
    );
    query.setMaxResults(1); //we don't need all
    return daoUtils.selectList(query, requestId, HostRoleStatus.getCompletedStates()).isEmpty();
  }
Given a collection of request ids, load the corresponding entities
@param requestIds  the collection of request ids
@param refreshHint {@code true} to hint JPA that the list should be refreshed
@return the list entities. An empty list if the requestIds are not provided
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java