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.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.request.UniqueRead;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.layer0.Layer0;
19 import org.simantics.modeling.ModelingResources;
20 import org.simantics.utils.ObjectUtils;
23 * This query finds subscription using label as keyword.
24 * If multiple subscriptions have the
26 * @author toni.kalajainen
28 public class FindSubscription extends UniqueRead<Resource> {
33 public FindSubscription( Resource model, String id, String label )
41 public Resource perform(ReadGraph graph) throws DatabaseException {
42 Layer0 L0 = Layer0.getInstance(graph);
43 ModelingResources MOD = ModelingResources.getInstance(graph);
45 for (Resource r : graph.getObjects(model, L0.ConsistsOf))
47 if ( !graph.isInstanceOf(r, MOD.Subscription) ) continue;
49 if ( this.id!=null ) {
50 String name = graph.getPossibleRelatedValue(r, L0.HasName);
51 if ( !name.equals(this.id)) continue;
54 if ( this.label!=null ) {
55 String label = graph.getPossibleRelatedValue(r, L0.HasLabel);
56 if ( !label.equals(this.label)) continue;
66 public int hashCode() {
67 return model.hashCode() + (id!=null?id.hashCode():0) + (label!=null?label.hashCode():0);
71 public boolean equals(Object object) {
72 if (this == object) return true;
73 if (object == null) return false;
74 if (getClass() != object.getClass()) return false;
75 FindSubscription r = (FindSubscription) object;
77 if ( !ObjectUtils.objectEquals(id, r.id) ) return false;
78 if ( !ObjectUtils.objectEquals(label, r.label)) return false;