Search in sources :

Example 1 with DataChannelQueryFilter

use of org.apache.cayenne.DataChannelQueryFilter 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 2 with DataChannelQueryFilter

use of org.apache.cayenne.DataChannelQueryFilter in project cayenne by apache.

the class DataDomainFiltersIT method testOnQuery_FilterOrdering.

@Test
public void testOnQuery_FilterOrdering() {
    DataDomain domain = runtime.getDataDomain();
    List<String> results = new ArrayList<>();
    DataChannelQueryFilter f1 = (originatingContext, query, filterChain) -> {
        results.add("f1start");
        QueryResponse response = filterChain.onQuery(originatingContext, query);
        results.add("f1end");
        return response;
    };
    DataChannelQueryFilter f2 = (originatingContext, query, filterChain) -> {
        results.add("f2start");
        QueryResponse response = filterChain.onQuery(originatingContext, query);
        results.add("f2end");
        return response;
    };
    domain.queryFilters.add(f1);
    domain.queryFilters.add(f2);
    ObjectSelect<Artist> query = ObjectSelect.query(Artist.class);
    QueryResponse response = domain.onQuery(context, query);
    assertNotNull(response);
    assertEquals(4, results.size());
    assertEquals("f2start", results.get(0));
    assertEquals("f1start", results.get(1));
    assertEquals("f1end", results.get(2));
    assertEquals("f2end", results.get(3));
}
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) QueryResponse(org.apache.cayenne.QueryResponse) ArrayList(java.util.ArrayList) DataChannelQueryFilter(org.apache.cayenne.DataChannelQueryFilter) Test(org.junit.Test)

Example 3 with DataChannelQueryFilter

use of org.apache.cayenne.DataChannelQueryFilter in project cayenne by apache.

the class DataDomainProvider method createAndInitDataDomain.

@SuppressWarnings("deprecation")
protected DataDomain createAndInitDataDomain() throws Exception {
    DataChannelDescriptor descriptor = loadDescriptor();
    DataDomain dataDomain = createDataDomain(descriptor.getName());
    dataDomain.setMaxIdQualifierSize(runtimeProperties.getInt(Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY, -1));
    dataDomain.setQueryCache(new NestedQueryCache(queryCache));
    dataDomain.setEntitySorter(injector.getInstance(EntitySorter.class));
    dataDomain.setEventManager(injector.getInstance(EventManager.class));
    dataDomain.setDataRowStoreFactory(injector.getInstance(DataRowStoreFactory.class));
    dataDomain.initWithProperties(descriptor.getProperties());
    for (DataMap dataMap : descriptor.getDataMaps()) {
        dataDomain.addDataMap(dataMap);
    }
    dataDomain.getEntityResolver().applyDBLayerDefaults();
    dataDomain.getEntityResolver().setValueObjectTypeRegistry(valueObjectTypeRegistry);
    dataDomain.getEntityResolver().setValueComparisionStrategyFactory(valueComparisonStrategyFactory);
    for (DataNodeDescriptor nodeDescriptor : descriptor.getNodeDescriptors()) {
        addDataNode(dataDomain, nodeDescriptor);
    }
    // init default node
    DataNode defaultNode = null;
    if (descriptor.getDefaultNodeName() != null) {
        defaultNode = dataDomain.getDataNode(descriptor.getDefaultNodeName());
    }
    if (defaultNode == null) {
        Collection<DataNode> allNodes = dataDomain.getDataNodes();
        if (allNodes.size() == 1) {
            defaultNode = allNodes.iterator().next();
        }
    }
    if (defaultNode != null) {
        logger.info("setting DataNode '" + defaultNode.getName() + "' as default, used by all unlinked DataMaps");
        dataDomain.setDefaultNode(defaultNode);
    }
    // filters are deprecated, used here for backward compatibility
    for (DataChannelFilter filter : filters) {
        dataDomain.addFilter(filter);
    }
    for (DataChannelQueryFilter filter : queryFilters) {
        dataDomain.addQueryFilter(filter);
    }
    for (DataChannelSyncFilter filter : syncFilters) {
        dataDomain.addSyncFilter(filter);
    }
    for (Object listener : listeners) {
        dataDomain.addListener(listener);
    }
    return dataDomain;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataDomain(org.apache.cayenne.access.DataDomain) EntitySorter(org.apache.cayenne.map.EntitySorter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) EventManager(org.apache.cayenne.event.EventManager) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap) NestedQueryCache(org.apache.cayenne.cache.NestedQueryCache) DataNode(org.apache.cayenne.access.DataNode) DataChannelSyncFilter(org.apache.cayenne.DataChannelSyncFilter) DataChannelQueryFilter(org.apache.cayenne.DataChannelQueryFilter) DataRowStoreFactory(org.apache.cayenne.access.DataRowStoreFactory)

Aggregations

DataChannelQueryFilter (org.apache.cayenne.DataChannelQueryFilter)3 DataChannelSyncFilter (org.apache.cayenne.DataChannelSyncFilter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DataChannelQueryFilterChain (org.apache.cayenne.DataChannelQueryFilterChain)2 DataChannelSyncFilterChain (org.apache.cayenne.DataChannelSyncFilterChain)2 ObjectContext (org.apache.cayenne.ObjectContext)2 QueryResponse (org.apache.cayenne.QueryResponse)2 PostPersist (org.apache.cayenne.annotation.PostPersist)2 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)2 Inject (org.apache.cayenne.di.Inject)2 GraphDiff (org.apache.cayenne.graph.GraphDiff)2 ObjectSelect (org.apache.cayenne.query.ObjectSelect)2 Query (org.apache.cayenne.query.Query)2 Artist (org.apache.cayenne.testdo.testmap.Artist)2 CayenneProjects (org.apache.cayenne.unit.di.server.CayenneProjects)2 ServerCase (org.apache.cayenne.unit.di.server.ServerCase)2 UseServerRuntime (org.apache.cayenne.unit.di.server.UseServerRuntime)2 ListResponse (org.apache.cayenne.util.ListResponse)2 Assert.assertEquals (org.junit.Assert.assertEquals)2