From 52de64001dcf8caaf18ce37721d2bf0d613c736e Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 6 Sep 2008 00:34:29 +0000 Subject: [PATCH] Allow the cache to be explicitly bypassed. --- .../jdbc/depot/DepotRepository.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/DepotRepository.java b/src/java/com/samskivert/jdbc/depot/DepotRepository.java index 6c6c84b..fe096fb 100644 --- a/src/java/com/samskivert/jdbc/depot/DepotRepository.java +++ b/src/java/com/samskivert/jdbc/depot/DepotRepository.java @@ -155,21 +155,34 @@ public abstract class DepotRepository /** * Loads all persistent objects that match the specified clauses. * - * We have two strategies for doing this: one performs the query as-is, the second executes - * two passes: first fetching only key columns and consulting the cache for each such key; - * then, in the second pass, fetching the full entity only for keys that were not found in - * the cache. + * We have two strategies for doing this: one performs the query as-is, the second executes two + * passes: first fetching only key columns and consulting the cache for each such key; then, in + * the second pass, fetching the full entity only for keys that were not found in the cache. * * The more complex strategy could save a lot of data shuffling. On the other hand, its - * complexity is an inherent drawback, and it does execute two separate database queries - * for what the simple method does in one. + * complexity is an inherent drawback, and it does execute two separate database queries for + * what the simple method does in one. */ protected List findAll ( Class type, Collection clauses) throws DatabaseException + { + return findAll(type, false, clauses); + } + + /** + * Loads all persistent objects that match the specified clauses. + * + * @param skipCache if true, our normal mixed select strategy that allows cached records to be + * loaded from the cache will not be used even if it otherwise could. See {@link + * #findAll(Class,Collection)} for details on the mixed strategy. + */ + protected List findAll ( + Class type, boolean skipCache, Collection clauses) + throws DatabaseException { DepotMarshaller marsh = _ctx.getMarshaller(type); - boolean useExplicit = + boolean useExplicit = !skipCache || (marsh.getTableName() == null) || !marsh.hasPrimaryKey() || !_ctx.isUsingCache(); // queries on @Computed records or the presence of FieldOverrides use the simple algorithm @@ -177,9 +190,8 @@ public abstract class DepotRepository useExplicit |= (clause instanceof FieldOverride); } - return _ctx.invoke(useExplicit ? - new FindAllQuery.Explicitly(_ctx, type, clauses) : - new FindAllQuery.WithCache(_ctx, type, clauses)); + return _ctx.invoke(useExplicit ? new FindAllQuery.Explicitly(_ctx, type, clauses) : + new FindAllQuery.WithCache(_ctx, type, clauses)); } /**