From 0c4914db55760dd3b0150b73ef5e50fa7413c42e Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 18 Sep 2007 00:08:32 +0000 Subject: [PATCH] Added a standard traverse-and-filter cache invalidator. --- .../jdbc/depot/CacheInvalidator.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java b/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java index 0fec7ce..034fdc3 100644 --- a/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java +++ b/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java @@ -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 + implements CacheInvalidator + { + public TraverseWithFilter (Class pClass) { + this(pClass.getName()); + } + + public TraverseWithFilter (String cacheId) { + _cacheId = cacheId; + } + + public void invalidate (PersistenceContext ctx) { + ctx.cacheTraverse(_cacheId, new PersistenceContext.CacheEvictionFilter() { + 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.