/** * Selects the entry from the list with the maximum value for ID, removing the all other entries and their values. * Assumptions: {@code list} is non-null and contains at least two valid entries. * * @param list the list to be scanned * @return the entry with the maximum value. * @throws GenericEntityException if {@link #removeEntryAndValue(GenericValue)} does */ private GenericValue selectMaximumIdAndRemoveOthers(@Nonnull List<GenericValue> list) throws GenericEntityException { final GenericValue winner = selectMaximumId(list); for (GenericValue other : list) { // The reference to "winner" was selected from this list, so "!=" is sane //noinspection ObjectEquality if (other != winner) { removeEntryAndValue(other); } } return winner; }
private void removeEntryAndValue(GenericValue entry) throws GenericEntityException { removeEntryAndValue(entry.getLong(ID), entry.getInteger(TYPE)); }
@Override public void removeEntry(String entityName, long entityId, String propertyKey) { final EntityCondition condition = new EntityFieldMap(FieldMap.build( ENTITY_NAME, entityName, ENTITY_ID, entityId, PROPERTY_KEY, propertyKey), AND); try { final List<GenericValue> list = genericDelegator.findByCondition(PROPERTY_ENTRY, condition, SELECT_ID_AND_TYPE, null); if (list != null) { for (GenericValue entry : list) { removeEntryAndValue(entry); } } } catch (GenericEntityException gee) { throw new PropertyImplementationException(gee); } finally { // remove cache entry regardless of whether or not we actually find anything invalidateCacheEntry(entityName, entityId, propertyKey); } }
removeEntryAndValue(entry); invalidateCacheEntry(entityName, entityId, entry.getString(PROPERTY_KEY));