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