]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/StringQuery.java
36d6acc5ae377e5c55e7f5019af705c48085cfe9
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / StringQuery.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 abstract public class StringQuery<Procedure> extends CacheEntryBase implements Query {
18
19     final public String id;
20     final public int hash;
21
22     public StringQuery(String id) {
23         assert(id != null);
24         this.id = id;
25         hash = id.hashCode();
26     }
27     
28     @Override
29     int makeHash() {
30         return id.hashCode();
31     }
32     
33     final protected static int hash(String id) {
34         return id.hashCode();
35     }
36     
37     @Override
38     public int type() {
39         return RequestFlags.INVALIDATE;
40     }
41     
42     @Override
43     final public boolean equals(Object object) {
44         if (this == object)
45             return true;
46         else if (object == null)
47             return false;
48         else if (getClass() != object.getClass())
49             return false;
50         StringQuery other = (StringQuery)object;
51         return id == other.id;
52     }
53     
54     @Override
55     final public Query getQuery() {
56         return this;
57     }
58     
59     @Override
60     public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) {
61         throw new Error("Recompute of primitive queries is not supported.");
62     }
63     
64     @Override
65     public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
66         throw new Error("Not possible.");
67     }
68     
69     abstract public void recompute(ReadGraphImpl graph, QueryProcessor provider);
70     abstract public void computeForEach(ReadGraphImpl graph, QueryProcessor provider, Procedure procedure);
71     abstract public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, Procedure procedure);
72     abstract public void putEntry(QueryProcessor provider);
73     abstract public void removeEntry(QueryProcessor provider);
74     abstract public StringQuery<Procedure> getEntry(QueryProcessor provider);
75         
76 }