]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/TransientUnaryRead.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / TransientUnaryRead.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.common.request;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.exception.DatabaseException;\r
16 import org.simantics.db.service.QueryControl;\r
17 \r
18 abstract public class TransientUnaryRead<P, R> extends BinaryRead<Object,P,R> {\r
19 \r
20         protected static final Object WITH_PARENT = new Object();\r
21         \r
22         public TransientUnaryRead(ReadGraph graph, P parameter) throws DatabaseException {\r
23                 this(graph, graph.getService(QueryControl.class), parameter);\r
24         }\r
25         \r
26         public TransientUnaryRead(ReadGraph graph, QueryControl qc, P parameter) throws DatabaseException {\r
27                 super(resolveFirstParameter(graph, qc), parameter);\r
28         }\r
29 \r
30         final private static Object resolveFirstParameter(ReadGraph graph, QueryControl qc) throws DatabaseException {\r
31                 if(qc.hasParentRequest(graph)) return WITH_PARENT;\r
32                 else return graph.getModificationCounter();\r
33         }\r
34 \r
35         @Override\r
36         final public R perform(ReadGraph _graph) throws DatabaseException {\r
37                 if(parameter == WITH_PARENT) {\r
38                         return perform(_graph, parameter2);\r
39                 } else {\r
40                         QueryControl qc = _graph.getService(QueryControl.class);\r
41                         ReadGraph graph = qc.getIndependentGraph(_graph);\r
42                         return perform(graph, parameter2);\r
43                 }\r
44         }\r
45 \r
46         abstract public R perform(ReadGraph graph, P parameter) throws DatabaseException;\r
47     \r
48 }\r