]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/subscription/FindSubscriptionItem.java
Removed stderr logging from CompileSCLMonitorRequest.
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / subscription / FindSubscriptionItem.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.subscription;
13
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;
23
24 /**
25  * This query finds subscription items by variable reference
26  * 
27  * @author toni.kalajainen
28  */
29 public class FindSubscriptionItem extends UniqueRead<Resource> {
30
31         Resource subscription;
32         RVI rvi;
33         
34         public FindSubscriptionItem(Resource subscription, RVI rvi) {
35                 super();
36                 this.subscription = subscription;
37                 this.rvi = rvi;
38         }
39
40         @Override
41         public Resource perform(ReadGraph graph) throws DatabaseException {
42         Layer0 L0 = Layer0.getInstance(graph);
43         ModelingResources MOD = ModelingResources.getInstance(graph);
44
45         Binding rviBinding = graph.getService(Databoard.class).getBindingUnchecked( RVI.class );
46         for (Resource r : graph.getObjects(subscription, L0.ConsistsOf))
47         {
48                 if ( !graph.isInstanceOf(r, MOD.Subscription_Item) ) continue;
49                 
50                 RVI _rvi = (RVI) graph.getPossibleRelatedValue(r, MOD.Subscription_Item_VariableId, rviBinding);
51                 if (_rvi.equals(rvi)) return r;
52         }
53
54                 return null;
55         }
56         
57     @Override
58     public int hashCode() {
59         return rvi.hashCode() + subscription.hashCode();
60     }
61
62     @Override
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;
68         
69         return subscription.equals(r.subscription) && rvi.equals(r.rvi);
70     }
71         
72
73
74 }