]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/BinaryQuery.java
e7af8d04d683f15fd9677ad6573596cd40851ab5
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / BinaryQuery.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.impl.query;
13
14 import org.simantics.db.impl.graph.ReadGraphImpl;
15 import org.simantics.db.request.RequestFlags;
16
17
18 abstract public class BinaryQuery<Procedure> extends CacheEntryBase implements Query {
19
20         final public long id;
21
22         public BinaryQuery(final long r1, final long r2) {
23         assert(r1 != 0);
24         assert(r2 != 0);
25         id = id(r1,r2);
26         assert(id != 0);
27     }
28         
29         @Override
30         int makeHash() {
31                 return r1() ^ r2();
32         }
33         
34     final public int r1() {
35         return (int)(id>>>32);
36     }
37     
38     final public int r2() {
39         return (int)id;
40     }
41     
42     final protected static long id(long r1, long r2) {
43         long result = (r1<<32) | (r2 & 0xffffffffL); 
44         return result;
45     }
46     
47     @Override
48     public int type() {
49         return RequestFlags.INVALIDATE;
50     }
51     
52         @Override
53     final public boolean equals(Object object) {
54         if (this == object)
55             return true;
56         else if (object == null)
57             return false;
58         else if (getClass() != object.getClass())
59             return false;
60         BinaryQuery<?> other = (BinaryQuery<?>)object;
61         return id == other.id;
62     }
63         
64     @Override
65     final public Query getQuery() {
66         return this;
67     }
68     
69     @Override
70     public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) {
71         recompute(graph, (QueryProcessor)provider);
72     }
73     
74     @Override
75     public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
76         performFromCache(graph, (QueryProcessor)provider, (Procedure)procedure);
77     }
78
79     abstract public void recompute(ReadGraphImpl graph, QueryProcessor provider);
80     abstract public void computeForEach(ReadGraphImpl graph, QueryProcessor provider, Procedure procedure, boolean store);
81     abstract public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, Procedure procedure);
82     abstract public void putEntry(QueryProcessor provider);
83     abstract public void removeEntry(QueryProcessor provider);
84     abstract public BinaryQuery<Procedure> getEntry(QueryProcessor provider);
85
86 }