use of org.apache.cayenne.DataChannelSyncFilter in project cayenne by apache.
the class DataDomainFiltersIT method testOnSync_FilterOrdering.
@Test
public void testOnSync_FilterOrdering() {
DataDomain domain = runtime.getDataDomain();
List<String> results = new ArrayList<>();
DataChannelSyncFilter f1 = (originatingContext, changes, syncType, filterChain) -> {
results.add("f1start");
GraphDiff response = filterChain.onSync(originatingContext, changes, syncType);
results.add("f1end");
return response;
};
DataChannelSyncFilter f2 = (originatingContext, changes, syncType, filterChain) -> {
results.add("f2start");
GraphDiff response = filterChain.onSync(originatingContext, changes, syncType);
results.add("f2end");
return response;
};
domain.syncFilters.add(f1);
domain.syncFilters.add(f2);
Artist a = context.newObject(Artist.class);
a.setArtistName("AAA");
// testing domain.onSync indirectly
context.commitChanges();
assertEquals(4, results.size());
assertEquals("f2start", results.get(0));
assertEquals("f1start", results.get(1));
assertEquals("f1end", results.get(2));
assertEquals("f2end", results.get(3));
}
use of org.apache.cayenne.DataChannelSyncFilter 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;
}
Aggregations