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