From a24ef499f38c0ff48cf56627b7bbfeb3ed73b1a6 Mon Sep 17 00:00:00 2001 From: Jody Grassel Date: Tue, 29 Oct 2013 16:23:36 +0000 Subject: [PATCH] OPENJPA-2414: FinderCache does not consider active Fetch Groups/FetchPlan added Fields git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.3.x@1536793 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/kernel/FinderCacheImpl.java | 4 ++-- .../apache/openjpa/conf/Compatibility.java | 15 ++++++++++++++ .../kernel/DelegatingFetchConfiguration.java | 8 ++++++++ .../openjpa/kernel/FetchConfiguration.java | 5 +++++ .../kernel/FetchConfigurationImpl.java | 20 ++++++++++++++++--- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java index 15383c3d4..8ef106144 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/FinderCacheImpl.java @@ -109,7 +109,7 @@ public class FinderCacheImpl } // FinderCache only operates with Default Fetch Plans - if (!fetch.isDefaultPUFetchGroupConfigurationOnly()) { + if (!fetch.isFetchConfigurationSQLCacheAdmissible()) { return null; } @@ -152,7 +152,7 @@ public class FinderCacheImpl } // FinderCache only operates with Default Fetch Plans - if (!fetch.isDefaultPUFetchGroupConfigurationOnly()) { + if (!fetch.isFetchConfigurationSQLCacheAdmissible()) { return null; } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java index a422597a7..e25a14671 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java @@ -77,6 +77,7 @@ public class Compatibility { private boolean _singletonLifecycleEventManager = false; private boolean _filterPCRegistryClasses = false; // OPENJPA-2288 private boolean _returnNullOnEmptyAggregateResult = true; // OPENJPA-1794 + private boolean _cacheNonDefaultFetchPlanQueries = false; // OPENJPA-2414 /** * Whether to require exact identity value types when creating object @@ -763,4 +764,18 @@ public class Compatibility { public void setReturnNullOnAggregateResult(boolean returnNullOnEmptyAggregateResult) { _returnNullOnEmptyAggregateResult = returnNullOnEmptyAggregateResult; } + + /** + * Whether the SQL generated for queries executed with a modified fetch plan are cached. + */ + public boolean getCacheNonDefaultFetchPlanQueries() { + return _cacheNonDefaultFetchPlanQueries; + } + + /** + * Whether the SQL generated for queries executed with a modified fetch plan are cached. + */ + public void setCacheNonDefaultFetchPlanQueries(boolean bool) { + _cacheNonDefaultFetchPlanQueries = bool; + } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingFetchConfiguration.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingFetchConfiguration.java index 4a7543259..ea55c009d 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingFetchConfiguration.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingFetchConfiguration.java @@ -595,4 +595,12 @@ public class DelegatingFetchConfiguration throw translate(re); } } + + public boolean isFetchConfigurationSQLCacheAdmissible() { + try { + return _fetch.isFetchConfigurationSQLCacheAdmissible(); + } catch (RuntimeException re) { + throw translate(re); + } + } } diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfiguration.java b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfiguration.java index 436703a43..72c92bd7b 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfiguration.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/FetchConfiguration.java @@ -474,4 +474,9 @@ public interface FetchConfiguration * @since 0.4.1 */ public FetchConfiguration traverse(FieldMetaData fm); + + /** + * Whether SQL generated by the FetchConfiguration's current configuration should be cached. + */ + public boolean isFetchConfigurationSQLCacheAdmissible(); } 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 0b9e30d99..90fce5092 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 @@ -148,7 +148,8 @@ public class FetchConfigurationImpl public boolean fetchGroupIsPUDefault = false; public boolean extendedPathLookup = false; public DataCacheRetrieveMode cacheRetrieveMode = DataCacheRetrieveMode.USE; - public DataCacheStoreMode cacheStoreMode = DataCacheStoreMode.USE; + public DataCacheStoreMode cacheStoreMode = DataCacheStoreMode.USE; + public boolean cacheNonDefaultFetchPlanQueries = false; } private final ConfigurationState _state; @@ -193,6 +194,8 @@ public class FetchConfigurationImpl addFetchGroups(Arrays.asList(fetchGroupList)); setMaxFetchDepth(conf.getMaxFetchDepth()); + + _state.cacheNonDefaultFetchPlanQueries = conf.getCompatibilityInstance().getCacheNonDefaultFetchPlanQueries(); } /** @@ -201,6 +204,7 @@ public class FetchConfigurationImpl public Object clone() { FetchConfigurationImpl clone = newInstance(null); clone._state.ctx = _state.ctx; + clone._state.cacheNonDefaultFetchPlanQueries = _state.cacheNonDefaultFetchPlanQueries; clone._parent = _parent; clone._fromField = _fromField; clone._fromType = _fromType; @@ -346,7 +350,7 @@ public class FetchConfigurationImpl return addFetchGroup(name, true); } - public FetchConfiguration addFetchGroup(String name, boolean recomputeIsDefault) { + private FetchConfiguration addFetchGroup(String name, boolean recomputeIsDefault) { if (StringUtils.isEmpty(name)) throw new UserException(_loc.get("null-fg")); @@ -383,7 +387,7 @@ public class FetchConfigurationImpl return removeFetchGroup(group, true); } - public FetchConfiguration removeFetchGroup(String group, boolean recomputeIsDefault) { + private FetchConfiguration removeFetchGroup(String group, boolean recomputeIsDefault) { lock(); try { if (_state.fetchGroups != null) { @@ -482,6 +486,15 @@ public class FetchConfigurationImpl public boolean isDefaultPUFetchGroupConfigurationOnly() { return _state.fetchGroupIsPUDefault; } + + public boolean isFetchConfigurationSQLCacheAdmissible() { + if (_state == null || _state.cacheNonDefaultFetchPlanQueries) { + return false; + } else { + // Only pctx-default matching FetchConfiguration generated SQL is cache permissible + return _state.fetchGroupIsPUDefault; + } + } public Set getFields() { if (_state.fields == null) return Collections.emptySet(); @@ -518,6 +531,7 @@ public class FetchConfigurationImpl _state.fields = new HashSet(); _state.fields.addAll(fields); } finally { + verifyDefaultPUFetchGroups(); unlock(); } return this;