use of org.apache.cayenne.annotation.PreRemove in project cayenne by apache.
the class CacheInvalidationFilter method preCommit.
/**
* A callback method that records cache group to flush at the end of the commit.
*/
@PrePersist
@PreRemove
@PreUpdate
protected void preCommit(Object object) {
// TODO: for some reason we can't use Persistent as the argument type... (is it fixed in Cayenne 4.0.M4?)
Persistent p = (Persistent) object;
Function<Persistent, Collection<CacheGroupDescriptor>> invalidationFunction = mappedHandlers.get(p.getClass());
if (invalidationFunction == null) {
invalidationFunction = skipHandler;
for (InvalidationHandler handler : handlers) {
Function<Persistent, Collection<CacheGroupDescriptor>> function = handler.canHandle(p.getClass());
if (function != null) {
invalidationFunction = function;
break;
}
}
mappedHandlers.put(p.getClass(), invalidationFunction);
}
Collection<CacheGroupDescriptor> objectGroups = invalidationFunction.apply(p);
if (!objectGroups.isEmpty()) {
getOrCreateTxGroups().addAll(objectGroups);
}
}
Aggregations