]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/UnaryAsyncRead.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / UnaryAsyncRead.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.AsyncRequestProcessor;\r
15 import org.simantics.db.RequestProcessor;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 import org.simantics.db.procedure.AsyncListener;\r
18 import org.simantics.db.procedure.AsyncProcedure;\r
19 import org.simantics.db.procedure.Listener;\r
20 import org.simantics.db.procedure.Procedure;\r
21 import org.simantics.db.procedure.SyncListener;\r
22 import org.simantics.db.procedure.SyncProcedure;\r
23 import org.simantics.db.request.AsyncRead;\r
24 import org.simantics.db.request.ReadInterface;\r
25 \r
26 public abstract class UnaryAsyncRead<P, R> implements AsyncRead<R>, ReadInterface<R> {\r
27 \r
28     final protected P parameter;\r
29 \r
30     @Override\r
31     public int hashCode() {\r
32         return parameter != null ? parameter.hashCode() : 0;\r
33     }\r
34 \r
35     @Override\r
36     final public int threadHash() {\r
37         return parameter.hashCode();\r
38     }\r
39     \r
40     @Override\r
41     public boolean equals(Object object) {\r
42         if (this == object)\r
43             return true;\r
44         else if (object == null)\r
45             return false;\r
46         else if (getClass() != object.getClass())\r
47             return false;\r
48         UnaryAsyncRead<?, ?> r = (UnaryAsyncRead<?, ?>) object;\r
49         if(parameter != null) {\r
50             if(!parameter.equals(r.parameter)) return false;\r
51         } else if(r.parameter != null) return false;\r
52         return true;\r
53     }\r
54 \r
55     @Override\r
56     public int getFlags() {\r
57         return 0;\r
58     }\r
59     \r
60     public UnaryAsyncRead(P parameter) {\r
61         this.parameter = parameter;\r
62     }\r
63 \r
64     @Override\r
65     public void request(AsyncRequestProcessor processor, AsyncProcedure<R> procedure) {\r
66         processor.asyncRequest(this, procedure);\r
67     }\r
68     \r
69     @Override\r
70     public void request(AsyncRequestProcessor processor, Procedure<R> procedure) {\r
71         processor.asyncRequest(this, procedure);\r
72     }\r
73     \r
74     @Override\r
75     public void request(AsyncRequestProcessor processor, SyncProcedure<R> procedure) {\r
76         processor.asyncRequest(this, procedure);\r
77     }\r
78 \r
79     @Override\r
80     public void request(AsyncRequestProcessor processor, AsyncListener<R> procedure) {\r
81         processor.asyncRequest(this, procedure);\r
82     }\r
83     \r
84     @Override\r
85     public void request(AsyncRequestProcessor processor, Listener<R> procedure) {\r
86         processor.asyncRequest(this, procedure);\r
87     }\r
88     \r
89     @Override\r
90     public void request(AsyncRequestProcessor processor, SyncListener<R> procedure) {\r
91         processor.asyncRequest(this, procedure);\r
92     }\r
93     \r
94     @Override\r
95     public R request(RequestProcessor processor) throws DatabaseException {\r
96         return processor.syncRequest(this);\r
97     }\r
98     \r
99 }\r