Let's not force validation on every Tom, Dick and Harry. This is a little

verbose, so maybe I'll change my mind again later and do something yet again
different.
This commit is contained in:
Michael Bayne
2007-08-15 19:47:16 +00:00
parent a68a6534a4
commit d414292ac3
5 changed files with 48 additions and 20 deletions
@@ -27,16 +27,6 @@ package com.samskivert.jdbc.depot;
*/
public interface CacheInvalidator
{
/**
* Validates that this invalidator operates on the supplied persistent record class. This helps
* to catch programmer errors where one record type is used for a query clause and another is
* used for the cache invalidator.
*
* @exception IllegalArgumentException thrown if the supplied persistent record class does not
* match the class that this invalidator will flush from the cache.
*/
public void validateFlushType (Class<?> pClass);
/**
* 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.
@@ -392,8 +392,8 @@ public abstract class DepotRepository
Class<T> type, final WhereClause key, CacheInvalidator invalidator, Object... fieldsValues)
throws PersistenceException
{
if (invalidator != null) {
invalidator.validateFlushType(type); // sanity check
if (invalidator instanceof ValidatingCacheInvalidator) {
((ValidatingCacheInvalidator)invalidator).validateFlushType(type); // sanity check
}
key.validateQueryType(type); // and another
@@ -521,8 +521,8 @@ public abstract class DepotRepository
{
requireNotComputed(type, "updateLiteral");
if (invalidator != null) {
invalidator.validateFlushType(type); // sanity check
if (invalidator instanceof ValidatingCacheInvalidator) {
((ValidatingCacheInvalidator)invalidator).validateFlushType(type); // sanity check
}
key.validateQueryType(type); // and another
@@ -667,8 +667,8 @@ public abstract class DepotRepository
Class<T> type, final WhereClause key, CacheInvalidator invalidator)
throws PersistenceException
{
if (invalidator != null) {
invalidator.validateFlushType(type); // sanity check
if (invalidator instanceof ValidatingCacheInvalidator) {
((ValidatingCacheInvalidator)invalidator).validateFlushType(type); // sanity check
}
key.validateQueryType(type); // and another
+2 -2
View File
@@ -41,7 +41,7 @@ import com.samskivert.util.StringUtil;
* a convenience, and may also be instantiated explicitly.
*/
public class Key<T extends PersistentRecord> extends WhereClause
implements SQLExpression, CacheKey, CacheInvalidator, Serializable
implements SQLExpression, CacheKey, ValidatingCacheInvalidator, Serializable
{
/** An expression that contains our key columns and values. */
public static class WhereCondition<U extends PersistentRecord> implements SQLExpression
@@ -188,7 +188,7 @@ public class Key<T extends PersistentRecord> extends WhereClause
return this; // TODO: Optimally return a special class here containing only _values.
}
// from CacheInvalidator
// from ValidatingCacheInvalidator
public void validateFlushType (Class<?> pClass)
{
if (!pClass.equals(condition.getPersistentClass())) {
@@ -33,7 +33,7 @@ import com.samskivert.jdbc.depot.expression.ExpressionVisitor;
* it can be sent into e.g. {@link DepotRepository#deleteAll) and have it clean up after itself.
*/
public class MultiKey<T extends PersistentRecord> extends WhereClause
implements CacheInvalidator
implements ValidatingCacheInvalidator
{
/**
* Constructs a new single-column {@code MultiKey} with the given value range.
@@ -112,7 +112,7 @@ public class MultiKey<T extends PersistentRecord> extends WhereClause
// nothing to add
}
// from CacheInvalidator
// from ValidatingCacheInvalidator
public void validateFlushType (Class<?> pClass)
{
if (!pClass.equals(_pClass)) {
@@ -0,0 +1,38 @@
//
// $Id$
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001-2007 Michael Bayne
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.jdbc.depot;
/**
* An augmented cache invalidator interface for invalidators that can ensure that they are
* operating on the proper persistent record class.
*/
public interface ValidatingCacheInvalidator extends CacheInvalidator
{
/**
* Validates that this invalidator operates on the supplied persistent record class. This helps
* to catch programmer errors where one record type is used for a query clause and another is
* used for the cache invalidator.
*
* @exception IllegalArgumentException thrown if the supplied persistent record class does not
* match the class that this invalidator will flush from the cache.
*/
public void validateFlushType (Class<?> pClass);
}