From 709bf862abc3207f3b13be381acebd297abb42a2 Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Wed, 31 Mar 2010 23:13:45 +0000 Subject: [PATCH] data initializilation from data cache - use input fetch, not the conetxt configuration; reduce checks git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@929744 13f79535-47bb-0310-9956-ffa450edef68 --- .../datacache/ConcurrentDataCache.java | 5 +++ .../datacache/DataCacheStoreManager.java | 39 +++++++++---------- .../kernel/FetchConfigurationImpl.java | 4 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentDataCache.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentDataCache.java index fe2137f90..73e55be04 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentDataCache.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ConcurrentDataCache.java @@ -152,4 +152,9 @@ public class ConcurrentDataCache protected boolean unpinInternal(Object key) { return _cache.unpin (key); } + + protected boolean recacheUpdates() { + return true; + } + } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java index 15c58491d..433503e5b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java @@ -290,7 +290,7 @@ public class DataCacheStoreManager edata.set(i); } } - if(edata.cardinality()==oids.size()){ + if (edata.cardinality() == oids.size()){ return true; } } @@ -323,36 +323,33 @@ public class DataCacheStoreManager } public boolean initialize(OpenJPAStateManager sm, PCState state, FetchConfiguration fetch, Object edata) { - boolean fromDatabase; DataCache cache = _mgr.selectCache(sm); - DataCachePCData data = null; - boolean updateCache = _ctx.getFetchConfiguration().getCacheRetrieveMode() != DataCacheRetrieveMode.BYPASS - && _ctx.getPopulateDataCache(); - if (cache == null || sm.isEmbedded() - || _ctx.getFetchConfiguration().getCacheRetrieveMode() == DataCacheRetrieveMode.BYPASS - || _ctx.getFetchConfiguration().getCacheStoreMode() == DataCacheStoreMode.REFRESH) { + if (cache == null) { + return super.initialize(sm, state, fetch, edata); + } + DataCachePCData data = cache.get(sm.getObjectId()); + boolean fromDatabase = false; + boolean alreadyCached = data != null; + if (sm.isEmbedded() + || fetch.getCacheRetrieveMode() == DataCacheRetrieveMode.BYPASS + || fetch.getCacheStoreMode() == DataCacheStoreMode.REFRESH) { fromDatabase = super.initialize(sm, state, fetch, edata); } else { - data = cache.get(sm.getObjectId()); - if (data != null && !isLocking(fetch)) { - //### the 'data.type' access here probably needs to be - //### addressed for bug 511 + if (alreadyCached && !isLocking(fetch)) { sm.initialize(data.getType(), state); data.load(sm, fetch, edata); - // no need to update the cache. - updateCache = false; - fromDatabase = true; } else { - // initialize from store manager fromDatabase = super.initialize(sm, state, fetch, edata); } } - - if (cache != null && (fromDatabase && updateCache)) { - // update cache if the result came from the database and configured to store or refresh the cache. + // update cache if the result came from the database and configured to use or refresh the cache. + boolean updateCache = fromDatabase && _ctx.getPopulateDataCache() + && ((fetch.getCacheStoreMode() == DataCacheStoreMode.USE && !alreadyCached) + || (fetch.getCacheStoreMode() == DataCacheStoreMode.REFRESH)); + if (updateCache) { cacheStateManager(cache, sm, data); } - return fromDatabase; + return fromDatabase || alreadyCached; } private void cacheStateManager(DataCache cache, OpenJPAStateManager sm, DataCachePCData data) { @@ -387,7 +384,7 @@ public class DataCacheStoreManager public boolean load(OpenJPAStateManager sm, BitSet fields, FetchConfiguration fetch, int lockLevel, Object edata) { DataCache cache = _mgr.selectCache(sm); - if (cache == null || sm.isEmbedded() || bypass(_ctx.getFetchConfiguration(), StoreManager.FORCE_LOAD_NONE)) + if (cache == null || sm.isEmbedded() || bypass(fetch, StoreManager.FORCE_LOAD_NONE)) return super.load(sm, fields, fetch, lockLevel, edata); DataCachePCData data = cache.get(sm.getObjectId()); diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java index 8bea486fd..ee455c86d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfigurationImpl.java @@ -146,8 +146,8 @@ public class FetchConfigurationImpl public boolean fetchGroupContainsDefault = false; public boolean fetchGroupContainsAll = false; public boolean extendedPathLookup = false; - public DataCacheRetrieveMode cacheRetrieveMode; - public DataCacheStoreMode cacheStoreMode; + public DataCacheRetrieveMode cacheRetrieveMode = DataCacheRetrieveMode.USE; + public DataCacheStoreMode cacheStoreMode = DataCacheStoreMode.USE; } private final ConfigurationState _state;