Search in sources :

Example 1 with PreUpdate

use of org.apache.cayenne.annotation.PreUpdate 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);
    }
}
Also used : Collection(java.util.Collection) Persistent(org.apache.cayenne.Persistent) PrePersist(org.apache.cayenne.annotation.PrePersist) PreRemove(org.apache.cayenne.annotation.PreRemove) PreUpdate(org.apache.cayenne.annotation.PreUpdate)

Aggregations

Collection (java.util.Collection)1 Persistent (org.apache.cayenne.Persistent)1 PrePersist (org.apache.cayenne.annotation.PrePersist)1 PreRemove (org.apache.cayenne.annotation.PreRemove)1 PreUpdate (org.apache.cayenne.annotation.PreUpdate)1