1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.subscription;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.Resource;
\r
16 import org.simantics.db.common.request.UniqueRead;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.layer0.Layer0;
\r
19 import org.simantics.modeling.ModelingResources;
\r
20 import org.simantics.utils.ObjectUtils;
\r
23 * This query finds subscription using label as keyword.
\r
24 * If multiple subscriptions have the
\r
26 * @author toni.kalajainen
\r
28 public class FindSubscription extends UniqueRead<Resource> {
\r
33 public FindSubscription( Resource model, String id, String label )
\r
41 public Resource perform(ReadGraph graph) throws DatabaseException {
\r
42 Layer0 L0 = Layer0.getInstance(graph);
\r
43 ModelingResources MOD = ModelingResources.getInstance(graph);
\r
45 for (Resource r : graph.getObjects(model, L0.ConsistsOf))
\r
47 if ( !graph.isInstanceOf(r, MOD.Subscription) ) continue;
\r
49 if ( this.id!=null ) {
\r
50 String name = graph.getPossibleRelatedValue(r, L0.HasName);
\r
51 if ( !name.equals(this.id)) continue;
\r
54 if ( this.label!=null ) {
\r
55 String label = graph.getPossibleRelatedValue(r, L0.HasLabel);
\r
56 if ( !label.equals(this.label)) continue;
\r
66 public int hashCode() {
\r
67 return model.hashCode() + (id!=null?id.hashCode():0) + (label!=null?label.hashCode():0);
\r
71 public boolean equals(Object object) {
\r
72 if (this == object) return true;
\r
73 if (object == null) return false;
\r
74 if (getClass() != object.getClass()) return false;
\r
75 FindSubscription r = (FindSubscription) object;
\r
77 if ( !ObjectUtils.objectEquals(id, r.id) ) return false;
\r
78 if ( !ObjectUtils.objectEquals(label, r.label)) return false;
\r