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