public boolean removeIfNotReferenced(KerberosPrincipalEntity kerberosPrincipalEntity) {
    if (kerberosPrincipalEntity != null) {
      if (CollectionUtils.isNotEmpty(kerberosPrincipalEntity.getKerberosKeytabPrincipalEntities())) {
        ArrayList<String> ids = new ArrayList<>();
        for (KerberosKeytabPrincipalEntity entity : kerberosPrincipalEntity.getKerberosKeytabPrincipalEntities()) {
          Long id = entity.getKkpId();

          if (id != null) {
            ids.add(String.valueOf(id));
          }
        }

        LOG.info(String.format("principal entry for %s is still referenced by [%s]", kerberosPrincipalEntity.getPrincipalName(), String.join(",", ids)));
      } else {
        LOG.info(String.format("principal entry for %s is no longer referenced. It will be removed.", kerberosPrincipalEntity.getPrincipalName()));
        remove(kerberosPrincipalEntity);
        return true;
      }
    }

    return false;
  }
Determines if there are any references to the {@link KerberosPrincipalEntity} before attempting
to remove it.  If there are any references to it, the entity will be not be removed.

@param kerberosPrincipalEntity the entity
@return <code>true</code>, if the entity was remove; <code>false</code> otherwise
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalDAO.java