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. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2188 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -27,16 +27,6 @@ package com.samskivert.jdbc.depot;
|
|||||||
*/
|
*/
|
||||||
public interface CacheInvalidator
|
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.
|
* 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.
|
* 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)
|
Class<T> type, final WhereClause key, CacheInvalidator invalidator, Object... fieldsValues)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
if (invalidator != null) {
|
if (invalidator instanceof ValidatingCacheInvalidator) {
|
||||||
invalidator.validateFlushType(type); // sanity check
|
((ValidatingCacheInvalidator)invalidator).validateFlushType(type); // sanity check
|
||||||
}
|
}
|
||||||
key.validateQueryType(type); // and another
|
key.validateQueryType(type); // and another
|
||||||
|
|
||||||
@@ -521,8 +521,8 @@ public abstract class DepotRepository
|
|||||||
{
|
{
|
||||||
requireNotComputed(type, "updateLiteral");
|
requireNotComputed(type, "updateLiteral");
|
||||||
|
|
||||||
if (invalidator != null) {
|
if (invalidator instanceof ValidatingCacheInvalidator) {
|
||||||
invalidator.validateFlushType(type); // sanity check
|
((ValidatingCacheInvalidator)invalidator).validateFlushType(type); // sanity check
|
||||||
}
|
}
|
||||||
key.validateQueryType(type); // and another
|
key.validateQueryType(type); // and another
|
||||||
|
|
||||||
@@ -667,8 +667,8 @@ public abstract class DepotRepository
|
|||||||
Class<T> type, final WhereClause key, CacheInvalidator invalidator)
|
Class<T> type, final WhereClause key, CacheInvalidator invalidator)
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
if (invalidator != null) {
|
if (invalidator instanceof ValidatingCacheInvalidator) {
|
||||||
invalidator.validateFlushType(type); // sanity check
|
((ValidatingCacheInvalidator)invalidator).validateFlushType(type); // sanity check
|
||||||
}
|
}
|
||||||
key.validateQueryType(type); // and another
|
key.validateQueryType(type); // and another
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import com.samskivert.util.StringUtil;
|
|||||||
* a convenience, and may also be instantiated explicitly.
|
* a convenience, and may also be instantiated explicitly.
|
||||||
*/
|
*/
|
||||||
public class Key<T extends PersistentRecord> extends WhereClause
|
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. */
|
/** An expression that contains our key columns and values. */
|
||||||
public static class WhereCondition<U extends PersistentRecord> implements SQLExpression
|
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.
|
return this; // TODO: Optimally return a special class here containing only _values.
|
||||||
}
|
}
|
||||||
|
|
||||||
// from CacheInvalidator
|
// from ValidatingCacheInvalidator
|
||||||
public void validateFlushType (Class<?> pClass)
|
public void validateFlushType (Class<?> pClass)
|
||||||
{
|
{
|
||||||
if (!pClass.equals(condition.getPersistentClass())) {
|
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.
|
* 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
|
public class MultiKey<T extends PersistentRecord> extends WhereClause
|
||||||
implements CacheInvalidator
|
implements ValidatingCacheInvalidator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructs a new single-column {@code MultiKey} with the given value range.
|
* 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
|
// nothing to add
|
||||||
}
|
}
|
||||||
|
|
||||||
// from CacheInvalidator
|
// from ValidatingCacheInvalidator
|
||||||
public void validateFlushType (Class<?> pClass)
|
public void validateFlushType (Class<?> pClass)
|
||||||
{
|
{
|
||||||
if (!pClass.equals(_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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user