1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.subscription;
14 import java.util.Collection;
15 import java.util.HashSet;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.UniqueRead;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.layer0.Layer0;
23 import org.simantics.modeling.ModelingResources;
27 * This query returns all subscription items for a collection of subscriptions.
29 public class SubscriptionItemsQuery extends UniqueRead<Set<Resource>> {
31 Collection<Resource> resources;
33 public SubscriptionItemsQuery(Collection<Resource> resources) {
35 this.resources = resources;
39 public Set<Resource> perform(ReadGraph graph) throws DatabaseException {
41 Set<Resource> result = new HashSet<Resource>();
42 ModelingResources MOD = ModelingResources.getInstance(graph);
43 Layer0 L0 = Layer0.getInstance(graph);
45 for (Resource r : resources) {
46 if ( graph.isInstanceOf(r, MOD.Subscription_Item)) result.add(r);
47 else if ( graph.isInstanceOf(r, MOD.Subscription)) {
48 for (Resource rr : graph.getObjects(r, L0.ConsistsOf)) {
49 if ( graph.isInstanceOf(rr, MOD.Subscription_Item)) result.add(rr);