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

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

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

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

@param kerberosKeytabEntity 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/KerberosKeytabDAO.java