From d414292ac376717ba9b039f924f3474fd1635704 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 15 Aug 2007 19:47:16 +0000 Subject: [PATCH] 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. --- .../jdbc/depot/CacheInvalidator.java | 10 ----- .../jdbc/depot/DepotRepository.java | 12 +++--- src/java/com/samskivert/jdbc/depot/Key.java | 4 +- .../com/samskivert/jdbc/depot/MultiKey.java | 4 +- .../depot/ValidatingCacheInvalidator.java | 38 +++++++++++++++++++ 5 files changed, 48 insertions(+), 20 deletions(-) create mode 100644 src/java/com/samskivert/jdbc/depot/ValidatingCacheInvalidator.java diff --git a/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java b/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java index 7ecd9ad..0fec7ce 100644 --- a/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java +++ b/src/java/com/samskivert/jdbc/depot/CacheInvalidator.java @@ -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. diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 1bb5a20..653b975 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -392,8 +392,8 @@ public abstract class DepotRepository Class 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 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 diff --git a/src/java/com/samskivert/jdbc/depot/Key.java b/src/java/com/samskivert/jdbc/depot/Key.java index f460435..2fc9ccb 100644 --- a/src/java/com/samskivert/jdbc/depot/Key.java +++ b/src/java/com/samskivert/jdbc/depot/Key.java @@ -41,7 +41,7 @@ import com.samskivert.util.StringUtil; * a convenience, and may also be instantiated explicitly. */ public class Key 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 implements SQLExpression @@ -188,7 +188,7 @@ public class Key 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())) { diff --git a/src/java/com/samskivert/jdbc/depot/MultiKey.java b/src/java/com/samskivert/jdbc/depot/MultiKey.java index 46c1d66..75205f3 100644 --- a/src/java/com/samskivert/jdbc/depot/MultiKey.java +++ b/src/java/com/samskivert/jdbc/depot/MultiKey.java @@ -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 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 extends WhereClause // nothing to add } - // from CacheInvalidator + // from ValidatingCacheInvalidator public void validateFlushType (Class pClass) { if (!pClass.equals(_pClass)) { diff --git a/src/java/com/samskivert/jdbc/depot/ValidatingCacheInvalidator.java b/src/java/com/samskivert/jdbc/depot/ValidatingCacheInvalidator.java new file mode 100644 index 0000000..0d51f56 --- /dev/null +++ b/src/java/com/samskivert/jdbc/depot/ValidatingCacheInvalidator.java @@ -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); +}