use of org.apache.cayenne.util.ListResponse in project cayenne by apache.
the class ClientServerChannelQueryAction method interceptSinglePageQuery.
private boolean interceptSinglePageQuery() {
// retrieve range from the previously cached list
if (serverMetadata.getFetchOffset() >= 0 && serverMetadata.getFetchLimit() > 0 && serverMetadata.getCacheKey() != null) {
List cachedList = channel.getQueryCache().get(serverMetadata);
if (cachedList == null) {
// attempt to refetch... respawn the action...
Query originatingQuery = serverMetadata.getOriginatingQuery();
if (originatingQuery != null) {
ClientServerChannelQueryAction subaction = new ClientServerChannelQueryAction(channel, originatingQuery);
subaction.execute();
cachedList = channel.getQueryCache().get(serverMetadata);
if (cachedList == null) {
throw new CayenneRuntimeException("No cached list for %s", serverMetadata.getCacheKey());
}
} else {
return !DONE;
}
}
int startIndex = serverMetadata.getFetchOffset();
int endIndex = startIndex + serverMetadata.getFetchLimit();
// send back just one page... query sender will figure out where it fits in
// the incremental list
this.response = new ListResponse(new ArrayList<>(cachedList.subList(startIndex, endIndex)));
return DONE;
}
return !DONE;
}
use of org.apache.cayenne.util.ListResponse in project cayenne by apache.
the class DataContextQueryAction method interceptObjectFromDataRowsQuery.
private boolean interceptObjectFromDataRowsQuery() {
if (query instanceof ObjectsFromDataRowsQuery) {
ObjectsFromDataRowsQuery objectsFromDataRowsQuery = (ObjectsFromDataRowsQuery) query;
response = new ListResponse(actingDataContext.objectsFromDataRows(objectsFromDataRowsQuery.getDescriptor(), objectsFromDataRowsQuery.getDataRows()));
return DONE;
}
return !DONE;
}
use of org.apache.cayenne.util.ListResponse in project cayenne by apache.
the class DataDomainFiltersIT method testOnQuery_Blocking.
@Test
public void testOnQuery_Blocking() {
DataDomain domain = runtime.getDataDomain();
QueryResponse r1 = new ListResponse();
QueryResponse r2 = new ListResponse();
DataChannelQueryFilter f1 = (originatingContext, query, filterChain) -> r1;
DataChannelQueryFilter f2 = (originatingContext, query, filterChain) -> r2;
domain.queryFilters.add(f1);
domain.queryFilters.add(f2);
ObjectSelect<Artist> query = ObjectSelect.query(Artist.class);
QueryResponse response = domain.onQuery(context, query);
assertSame(r2, response);
}
use of org.apache.cayenne.util.ListResponse in project cayenne by apache.
the class DataDomainQueryAction method interceptOIDQuery.
private boolean interceptOIDQuery() {
if (query instanceof ObjectIdQuery) {
ObjectIdQuery oidQuery = (ObjectIdQuery) query;
ObjectId oid = oidQuery.getObjectId();
// translate and run the query. See for instance CAY-1651
if (oid.isTemporary() && !oid.isReplacementIdAttached()) {
response = new ListResponse();
return DONE;
}
DataRow row = null;
if (cache != null && !oidQuery.isFetchMandatory()) {
row = polymorphicRowFromCache(oid);
}
// refresh is forced or not found in cache
if (row == null) {
if (oidQuery.isFetchAllowed()) {
runQueryInTransaction();
} else {
response = new ListResponse();
}
} else {
response = new ListResponse(row);
}
return DONE;
}
return !DONE;
}
use of org.apache.cayenne.util.ListResponse in project cayenne by apache.
the class DataDomainQueryAction method interceptSharedCache.
/*
* Wraps execution in shared cache checks
*/
private boolean interceptSharedCache() {
if (metadata.getCacheKey() == null) {
return !DONE;
}
boolean cache = QueryCacheStrategy.SHARED_CACHE == metadata.getCacheStrategy();
boolean cacheOrCacheRefresh = cache || QueryCacheStrategy.SHARED_CACHE_REFRESH == metadata.getCacheStrategy();
if (!cacheOrCacheRefresh) {
return !DONE;
}
QueryCache queryCache = domain.getQueryCache();
QueryCacheEntryFactory factory = getCacheObjectFactory();
if (cache) {
List cachedResults = queryCache.get(metadata, factory);
// there was a preexisting cache entry
if (response == null) {
response = new ListResponse(cachedResults);
}
if (cachedResults instanceof ListWithPrefetches) {
this.prefetchResultsByPath = ((ListWithPrefetches) cachedResults).getPrefetchResultsByPath();
}
} else {
// on cache-refresh request, fetch without blocking and fill the
// cache
queryCache.put(metadata, factory.createObject());
}
return DONE;
}
Aggregations