mirror of https://github.com/apache/openjpa.git
OPENJPA-2414: FinderCache does not consider active Fetch Groups/FetchPlan added Fields
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1516853 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea05b25d46
commit
ee6f4acc3f
|
@ -107,6 +107,12 @@ public class FinderCacheImpl
|
|||
if (fetch.getReadLockLevel() != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// FinderCache only operates with Default Fetch Plans
|
||||
if (!fetch.isDefaultPUFetchGroupConfigurationOnly()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean ignore = isHinted(fetch, QueryHints.HINT_IGNORE_FINDER);
|
||||
boolean invalidate = isHinted(fetch, QueryHints.HINT_INVALIDATE_FINDER);
|
||||
if (invalidate) {
|
||||
|
@ -144,6 +150,12 @@ public class FinderCacheImpl
|
|||
if (fetch.getReadLockLevel() != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// FinderCache only operates with Default Fetch Plans
|
||||
if (!fetch.isDefaultPUFetchGroupConfigurationOnly()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean recache = isHinted(fetch, QueryHints.HINT_RECACHE_FINDER);
|
||||
if (isExcluded(mapping)) {
|
||||
return recache ? put(mapping, select) : null;
|
||||
|
|
|
@ -500,6 +500,14 @@ public class DelegatingFetchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isDefaultPUFetchGroupConfigurationOnly() {
|
||||
try {
|
||||
return _fetch.isDefaultPUFetchGroupConfigurationOnly();
|
||||
} catch (RuntimeException re) {
|
||||
throw translate(re);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getHint(String name) {
|
||||
try {
|
||||
return _fetch.getHint(name);
|
||||
|
|
|
@ -414,6 +414,12 @@ public interface FetchConfiguration
|
|||
*/
|
||||
public boolean isHintSet(String key);
|
||||
|
||||
/**
|
||||
* Affirm if the Fetch Plan currently matches the Persistence Unit's configured default.
|
||||
*
|
||||
*/
|
||||
public boolean isDefaultPUFetchGroupConfigurationOnly();
|
||||
|
||||
/**
|
||||
* Root classes for recursive operations. This set is not thread safe.
|
||||
*/
|
||||
|
|
|
@ -145,6 +145,7 @@ public class FetchConfigurationImpl
|
|||
public Map<String,Object> hints = null;
|
||||
public boolean fetchGroupContainsDefault = false;
|
||||
public boolean fetchGroupContainsAll = false;
|
||||
public boolean fetchGroupIsPUDefault = false;
|
||||
public boolean extendedPathLookup = false;
|
||||
public DataCacheRetrieveMode cacheRetrieveMode = DataCacheRetrieveMode.USE;
|
||||
public DataCacheStoreMode cacheStoreMode = DataCacheStoreMode.USE;
|
||||
|
@ -186,8 +187,11 @@ public class FetchConfigurationImpl
|
|||
setFlushBeforeQueries(conf.getFlushBeforeQueriesConstant());
|
||||
setLockTimeout(conf.getLockTimeout());
|
||||
setQueryTimeout(conf.getQueryTimeout());
|
||||
clearFetchGroups();
|
||||
addFetchGroups(Arrays.asList(conf.getFetchGroupsList()));
|
||||
|
||||
String[] fetchGroupList = conf.getFetchGroupsList();
|
||||
clearFetchGroups((fetchGroupList == null || fetchGroupList.length == 0));
|
||||
|
||||
addFetchGroups(Arrays.asList(fetchGroupList));
|
||||
setMaxFetchDepth(conf.getMaxFetchDepth());
|
||||
}
|
||||
|
||||
|
@ -339,6 +343,10 @@ public class FetchConfigurationImpl
|
|||
}
|
||||
|
||||
public FetchConfiguration addFetchGroup(String name) {
|
||||
return addFetchGroup(name, true);
|
||||
}
|
||||
|
||||
public FetchConfiguration addFetchGroup(String name, boolean recomputeIsDefault) {
|
||||
if (StringUtils.isEmpty(name))
|
||||
throw new UserException(_loc.get("null-fg"));
|
||||
|
||||
|
@ -347,11 +355,15 @@ public class FetchConfigurationImpl
|
|||
if (_state.fetchGroups == null)
|
||||
_state.fetchGroups = new HashSet<String>();
|
||||
_state.fetchGroups.add(name);
|
||||
|
||||
if (FetchGroup.NAME_ALL.equals(name))
|
||||
_state.fetchGroupContainsAll = true;
|
||||
else if (FetchGroup.NAME_DEFAULT.equals(name))
|
||||
_state.fetchGroupContainsDefault = true;
|
||||
} finally {
|
||||
if (recomputeIsDefault) {
|
||||
verifyDefaultPUFetchGroups();
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
return this;
|
||||
|
@ -361,11 +373,17 @@ public class FetchConfigurationImpl
|
|||
if (groups == null || groups.isEmpty())
|
||||
return this;
|
||||
for (String group : groups)
|
||||
addFetchGroup(group);
|
||||
addFetchGroup(group, false);
|
||||
|
||||
verifyDefaultPUFetchGroups();
|
||||
return this;
|
||||
}
|
||||
|
||||
public FetchConfiguration removeFetchGroup(String group) {
|
||||
return removeFetchGroup(group, true);
|
||||
}
|
||||
|
||||
public FetchConfiguration removeFetchGroup(String group, boolean recomputeIsDefault) {
|
||||
lock();
|
||||
try {
|
||||
if (_state.fetchGroups != null) {
|
||||
|
@ -376,6 +394,9 @@ public class FetchConfigurationImpl
|
|||
_state.fetchGroupContainsDefault = false;
|
||||
}
|
||||
} finally {
|
||||
if (recomputeIsDefault) {
|
||||
verifyDefaultPUFetchGroups();
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
return this;
|
||||
|
@ -386,8 +407,9 @@ public class FetchConfigurationImpl
|
|||
try {
|
||||
if (_state.fetchGroups != null && groups != null)
|
||||
for (String group : groups)
|
||||
removeFetchGroup(group);
|
||||
removeFetchGroup(group, false);
|
||||
} finally {
|
||||
verifyDefaultPUFetchGroups();
|
||||
unlock();
|
||||
}
|
||||
return this;
|
||||
|
@ -413,18 +435,53 @@ public class FetchConfigurationImpl
|
|||
_state.fetchGroups.add(FetchGroup.NAME_DEFAULT); // OPENJPA-2413
|
||||
}
|
||||
} finally {
|
||||
verifyDefaultPUFetchGroups();
|
||||
unlock();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public FetchConfiguration resetFetchGroups() {
|
||||
clearFetchGroups();
|
||||
String[] fetchGroupList = _state.ctx.getConfiguration().getFetchGroupsList();
|
||||
clearFetchGroups((fetchGroupList == null || fetchGroupList.length == 0));
|
||||
|
||||
if (_state.ctx != null)
|
||||
addFetchGroups(Arrays.asList(_state.ctx.getConfiguration().
|
||||
getFetchGroupsList()));
|
||||
addFetchGroups(Arrays.asList(fetchGroupList));
|
||||
|
||||
verifyDefaultPUFetchGroups();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the current selection of FetchGroups is equivalent to the Configuration's default FetchGroups
|
||||
*/
|
||||
private void verifyDefaultPUFetchGroups() {
|
||||
_state.fetchGroupIsPUDefault = false;
|
||||
|
||||
if (_state.fields != null && !_state.fields.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_state.fetchGroups != null && _state.ctx != null) {
|
||||
List<String> defaultPUFetchGroups = Arrays.asList(_state.ctx.getConfiguration().getFetchGroupsList());
|
||||
if (_state.fetchGroups.size() != defaultPUFetchGroups.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String fetchGroupName : defaultPUFetchGroups) {
|
||||
if (!_state.fetchGroups.contains(fetchGroupName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_state.fetchGroupIsPUDefault = true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDefaultPUFetchGroupConfigurationOnly() {
|
||||
return _state.fetchGroupIsPUDefault;
|
||||
}
|
||||
|
||||
public Set<String> getFields() {
|
||||
if (_state.fields == null) return Collections.emptySet();
|
||||
|
@ -444,6 +501,7 @@ public class FetchConfigurationImpl
|
|||
if (_state.fields == null)
|
||||
_state.fields = new HashSet<String>();
|
||||
_state.fields.add(field);
|
||||
_state.fetchGroupIsPUDefault = false;
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
|
@ -468,8 +526,13 @@ public class FetchConfigurationImpl
|
|||
public FetchConfiguration removeField(String field) {
|
||||
lock();
|
||||
try {
|
||||
if (_state.fields != null)
|
||||
if (_state.fields != null) {
|
||||
_state.fields.remove(field);
|
||||
|
||||
if (_state.fields.size() == 0) {
|
||||
verifyDefaultPUFetchGroups();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
unlock();
|
||||
}
|
||||
|
@ -493,6 +556,7 @@ public class FetchConfigurationImpl
|
|||
if (_state.fields != null)
|
||||
_state.fields.clear();
|
||||
} finally {
|
||||
verifyDefaultPUFetchGroups();
|
||||
unlock();
|
||||
}
|
||||
return this;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue