@RequiresSession
  public boolean exists(PrincipalEntity principalEntity, ResourceEntity resourceEntity, PermissionEntity permissionEntity) {
    TypedQuery<PrivilegeEntity> query = entityManagerProvider.get().createQuery(
        "SELECT privilege FROM PrivilegeEntity privilege WHERE privilege.principal = :principal AND privilege.resource = :resource AND privilege.permission = :permission", PrivilegeEntity.class);

    query.setParameter("principal", principalEntity);
    query.setParameter("resource", resourceEntity);
    query.setParameter("permission", permissionEntity);

    List<PrivilegeEntity> privilegeEntities = daoUtils.selectList(query);
    return !(privilegeEntities == null || privilegeEntities.isEmpty());
  }
Determine whether or not the privilege entity exists defined by the given principal, resource and
permission exists.

@param principalEntity   the principal entity
@param resourceEntity    the resource entity
@param permissionEntity  the permission entity

@return true if the privilege entity already exists
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrivilegeDAO.java