storeHook(targetEntityName, isPK, convert(isPK, targetEntityName, oldEntity), convert(false, targetEntityName, newEntity));
}
}
protected void storeHook(String entityName, boolean isPK, List oldValues, List newValues) {
UtilCache entityCache = null;
synchronized (UtilCache.utilCacheTable) {
entityCache = (UtilCache) UtilCache.utilCacheTable.get(getCacheName(entityName));
}
// for info about cache clearing
if (newValues == null || newValues.size() == 0 || newValues.get(0) == null) {
//Debug.logInfo("In storeHook (cache clear) for entity name [" + entityName + "], got entity cache with name: " + (entityCache == null ? "[No cache found to remove from]" : entityCache.getName()), module);
}
if (entityCache == null) {
return;
}
Iterator cacheKeyIter = entityCache.getCacheLineKeys().iterator();
while (cacheKeyIter.hasNext()) {
EntityCondition condition = (EntityCondition) cacheKeyIter.next();
//Debug.logInfo("In storeHook entityName [" + entityName + "] checking against condition: " + condition, module);
boolean shouldRemove = false;
if (condition == null) {
shouldRemove = true;
} else if (oldValues == null) {
Iterator newValueIter = newValues.iterator();
while (newValueIter.hasNext() && !shouldRemove) {
Map newValue = (Map) newValueIter.next();
shouldRemove |= condition.mapMatches(getDelegator(), newValue);
}
} else {
boolean oldMatched = false;
Iterator oldValueIter = oldValues.iterator();
while (oldValueIter.hasNext() && !shouldRemove) {
Map oldValue = (Map) oldValueIter.next();
if (condition.mapMatches(getDelegator(), oldValue)) {
oldMatched = true;
//Debug.logInfo("In storeHook, oldMatched for entityName [" + entityName + "]; shouldRemove is false", module);
if (newValues != null) {
Iterator newValueIter = newValues.iterator();
while (newValueIter.hasNext() && !shouldRemove) {
Map newValue = (Map) newValueIter.next();
shouldRemove |= isNull(newValue) || condition.mapMatches(getDelegator(), newValue);
//Debug.logInfo("In storeHook, for entityName [" + entityName + "] shouldRemove is now " + shouldRemove, module);
}
} else {
shouldRemove = true;
}
}
}
// QUESTION: what is this? why would we do this?
if (!oldMatched && isPK) {
//Debug.logInfo("In storeHook, for entityName [" + entityName + "] oldMatched is false and isPK is true, so setting shouldRemove to true (will remove from cache)", module);
shouldRemove = true;
}
}
if (shouldRemove) {
if (Debug.verboseOn()) Debug.logVerbose("In storeHook, matched condition, removing from cache for entityName [" + entityName + "] in cache with name [" + entityCache.getName() + "] entry with condition: " + condition, module);
// doesn't work anymore since this is a copy of the cache keySet, can call remove directly though with a concurrent mod exception: cacheKeyIter.remove();
entityCache.remove(condition);
}
}
}