@RequiresSession
  public List<GroupEntity> findGroupsByPrincipal(List<PrincipalEntity> principalList) {
    TypedQuery<GroupEntity> query = entityManagerProvider.get().createQuery(
        "SELECT grp FROM GroupEntity grp WHERE grp.principal IN :principalList", GroupEntity.class);

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

    return Lists.newArrayList(result);
  }
Find the group entities for the given list of principals

@param principalList  the list of principal entities

@return the list of groups matching the query
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/GroupDAO.java