]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/BinaryQuery.java
Multiple reader thread support for db client
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / BinaryQuery.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2018 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.request.RequestFlags;
15
16 public abstract class BinaryQuery<Procedure> extends CacheEntryBase<Procedure> implements Query {
17
18         final public long id;
19
20         public BinaryQuery(final long r1, final long r2) {
21         assert(r1 != 0);
22         assert(r2 != 0);
23         id = id(r1,r2);
24         assert(id != 0);
25     }
26         
27         @Override
28         int makeHash() {
29                 return r1() ^ r2();
30         }
31         
32     final public int r1() {
33         return (int)(id>>>32);
34     }
35     
36     final public int r2() {
37         return (int)id;
38     }
39     
40     final protected static long id(long r1, long r2) {
41         long result = (r1<<32) | (r2 & 0xffffffffL); 
42         return result;
43     }
44     
45     @Override
46     public int type() {
47         return RequestFlags.INVALIDATE;
48     }
49     
50         @Override
51     final public boolean equals(Object object) {
52         if (this == object)
53             return true;
54         else if (object == null)
55             return false;
56         else if (getClass() != object.getClass())
57             return false;
58         BinaryQuery<?> other = (BinaryQuery<?>)object;
59         return id == other.id;
60     }
61         
62     @Override
63     final public Query getQuery() {
64         return this;
65     }
66
67     abstract public void removeEntry(QueryProcessor provider);
68
69 }