return ((DataContext) actingContext).getQueryCache();
}
private boolean interceptRefreshQuery() {
if (query instanceof RefreshQuery) {
RefreshQuery refreshQuery = (RefreshQuery) query;
DataContext context = (DataContext) actingContext;
// handle four separate cases, but do not combine them as it will be
// unclear how to handle cascading behavior
// 1. refresh all
if (refreshQuery.isRefreshAll()) {
synchronized (context.getObjectStore()) {
invalidateLocally(context.getObjectStore(), context
.getObjectStore()
.getObjectIterator());
context.getQueryCache().clear();
}
// cascade
return !DONE;
}
// 2. invalidate object collection
Collection objects = refreshQuery.getObjects();
if (objects != null && !objects.isEmpty()) {
synchronized (context.getObjectStore()) {
invalidateLocally(context.getObjectStore(), objects.iterator());
}
// cascade
return !DONE;
}
// 3. refresh query - have to do it eagerly to refresh the objects involved
Query cachedQuery = refreshQuery.getQuery();
if (cachedQuery != null) {
String cacheKey = cachedQuery
.getMetaData(context.getEntityResolver())
.getCacheKey();
context.getQueryCache().remove(cacheKey);
this.response = context.performGenericQuery(cachedQuery);
// do not cascade to avoid running query twice
return DONE;
}
// 4. refresh groups...
String[] groups = refreshQuery.getGroupKeys();
if (groups != null && groups.length > 0) {
for (int i = 0; i < groups.length; i++) {
context.getQueryCache().removeGroup(groups[i]);
}