]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/SyncSetResourceRead.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / SyncSetResourceRead.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.common.request;\r
13 \r
14 import org.simantics.db.AsyncReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.procedure.AsyncProcedure;\r
17 import org.simantics.db.procedure.SyncSetListener;\r
18 import org.simantics.db.request.AsyncRead;\r
19 \r
20 public abstract class SyncSetResourceRead<T> implements AsyncRead<Object>, SetListenerRead<T> {\r
21 \r
22     final protected SyncSetListener<T> procedure;\r
23     final protected Resource resource;\r
24 \r
25     @Override\r
26     public int hashCode() {\r
27         return resource.hashCode() + 31 * procedure.hashCode();\r
28     }\r
29     \r
30     @Override\r
31     public int threadHash() {\r
32         return resource.getThreadHash();\r
33     }\r
34     \r
35     @Override\r
36     public boolean equals(Object object) {\r
37         if (this == object)\r
38             return true;\r
39         else if (object == null)\r
40             return false;\r
41         else if (getClass() != object.getClass())\r
42             return false;\r
43         SyncSetResourceRead<?> r = (SyncSetResourceRead<?>) object;\r
44         return resource.equals(r.resource) && procedure.equals(r.procedure);\r
45     }\r
46 \r
47     public SyncSetResourceRead(Resource resource, SyncSetListener<T> procedure) {\r
48         this.resource = resource;\r
49         this.procedure = procedure;\r
50     }\r
51 \r
52     @Override\r
53     public void perform(AsyncReadGraph graph, AsyncProcedure<Object> dummy) {\r
54         execute(graph, procedure);\r
55         dummy.execute(graph, null);\r
56     }\r
57     \r
58 }\r