Added a standard traverse-and-filter cache invalidator.
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
|
||||
package com.samskivert.jdbc.depot;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Implementors of this interface performs perform cache invalidation for calls to
|
||||
* {@link DepotRepository#updateLiteral}, {@link DepotRepository#updatePartial} and
|
||||
@@ -27,6 +29,30 @@ package com.samskivert.jdbc.depot;
|
||||
*/
|
||||
public interface CacheInvalidator
|
||||
{
|
||||
public static abstract class TraverseWithFilter<T extends Serializable>
|
||||
implements CacheInvalidator
|
||||
{
|
||||
public TraverseWithFilter (Class<T> pClass) {
|
||||
this(pClass.getName());
|
||||
}
|
||||
|
||||
public TraverseWithFilter (String cacheId) {
|
||||
_cacheId = cacheId;
|
||||
}
|
||||
|
||||
public void invalidate (PersistenceContext ctx) {
|
||||
ctx.cacheTraverse(_cacheId, new PersistenceContext.CacheEvictionFilter<T>() {
|
||||
protected boolean testForEviction (Serializable key, T record) {
|
||||
return TraverseWithFilter.this.testForEviction(key, record);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract boolean testForEviction (Serializable key, T record);
|
||||
|
||||
protected String _cacheId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Must invalidate all cache entries that depend on the records being modified or deleted.
|
||||
* This method is called just before the database statement is executed.
|
||||
|
||||
Reference in New Issue
Block a user