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