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 org.simantics.databoard.Databoard;
15 import org.simantics.databoard.binding.Binding;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.common.request.UniqueRead;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.layer0.variable.RVI;
21 import org.simantics.layer0.Layer0;
22 import org.simantics.modeling.ModelingResources;
25 * This query finds subscription items by variable reference
27 * @author toni.kalajainen
29 public class FindSubscriptionItem extends UniqueRead<Resource> {
31 Resource subscription;
34 public FindSubscriptionItem(Resource subscription, RVI rvi) {
36 this.subscription = subscription;
41 public Resource perform(ReadGraph graph) throws DatabaseException {
42 Layer0 L0 = Layer0.getInstance(graph);
43 ModelingResources MOD = ModelingResources.getInstance(graph);
45 Binding rviBinding = graph.getService(Databoard.class).getBindingUnchecked( RVI.class );
46 for (Resource r : graph.getObjects(subscription, L0.ConsistsOf))
48 if ( !graph.isInstanceOf(r, MOD.Subscription_Item) ) continue;
50 RVI _rvi = (RVI) graph.getPossibleRelatedValue(r, MOD.Subscription_Item_VariableId, rviBinding);
51 if (_rvi.equals(rvi)) return r;
58 public int hashCode() {
59 return rvi.hashCode() + subscription.hashCode();
63 public boolean equals(Object object) {
64 if (this == object) return true;
65 if (object == null) return false;
66 if (getClass() != object.getClass()) return false;
67 FindSubscriptionItem r = (FindSubscriptionItem) object;
69 return subscription.equals(r.subscription) && rvi.equals(r.rvi);