Search in sources :

Example 1 with ListResponse

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;
}
Also used : Query(org.apache.cayenne.query.Query) IncrementalListResponse(org.apache.cayenne.util.IncrementalListResponse) ListResponse(org.apache.cayenne.util.ListResponse) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ListResponse

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;
}
Also used : ListResponse(org.apache.cayenne.util.ListResponse)

Example 3 with ListResponse

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);
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) DataChannelSyncFilter(org.apache.cayenne.DataChannelSyncFilter) DataChannelSyncFilterChain(org.apache.cayenne.DataChannelSyncFilterChain) ServerCase(org.apache.cayenne.unit.di.server.ServerCase) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) CayenneProjects(org.apache.cayenne.unit.di.server.CayenneProjects) ArrayList(java.util.ArrayList) Query(org.apache.cayenne.query.Query) Artist(org.apache.cayenne.testdo.testmap.Artist) Assert.assertSame(org.junit.Assert.assertSame) DataChannelQueryFilterChain(org.apache.cayenne.DataChannelQueryFilterChain) List(java.util.List) PostPersist(org.apache.cayenne.annotation.PostPersist) Inject(org.apache.cayenne.di.Inject) GraphDiff(org.apache.cayenne.graph.GraphDiff) QueryResponse(org.apache.cayenne.QueryResponse) DataChannelQueryFilter(org.apache.cayenne.DataChannelQueryFilter) ObjectSelect(org.apache.cayenne.query.ObjectSelect) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) UseServerRuntime(org.apache.cayenne.unit.di.server.UseServerRuntime) Assert.assertEquals(org.junit.Assert.assertEquals) ListResponse(org.apache.cayenne.util.ListResponse) Artist(org.apache.cayenne.testdo.testmap.Artist) ListResponse(org.apache.cayenne.util.ListResponse) QueryResponse(org.apache.cayenne.QueryResponse) DataChannelQueryFilter(org.apache.cayenne.DataChannelQueryFilter) Test(org.junit.Test)

Example 4 with ListResponse

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;
}
Also used : ListResponse(org.apache.cayenne.util.ListResponse) ObjectId(org.apache.cayenne.ObjectId) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) DataRow(org.apache.cayenne.DataRow)

Example 5 with ListResponse

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;
}
Also used : QueryCache(org.apache.cayenne.cache.QueryCache) ListResponse(org.apache.cayenne.util.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) QueryCacheEntryFactory(org.apache.cayenne.cache.QueryCacheEntryFactory)

Aggregations

ListResponse (org.apache.cayenne.util.ListResponse)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Query (org.apache.cayenne.query.Query)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataChannelQueryFilter (org.apache.cayenne.DataChannelQueryFilter)1 DataChannelQueryFilterChain (org.apache.cayenne.DataChannelQueryFilterChain)1 DataChannelSyncFilter (org.apache.cayenne.DataChannelSyncFilter)1 DataChannelSyncFilterChain (org.apache.cayenne.DataChannelSyncFilterChain)1 DataRow (org.apache.cayenne.DataRow)1 ObjectContext (org.apache.cayenne.ObjectContext)1 ObjectId (org.apache.cayenne.ObjectId)1 QueryResponse (org.apache.cayenne.QueryResponse)1 PostPersist (org.apache.cayenne.annotation.PostPersist)1 QueryCache (org.apache.cayenne.cache.QueryCache)1 QueryCacheEntryFactory (org.apache.cayenne.cache.QueryCacheEntryFactory)1 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)1 Inject (org.apache.cayenne.di.Inject)1 GraphDiff (org.apache.cayenne.graph.GraphDiff)1 DbEntity (org.apache.cayenne.map.DbEntity)1