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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.common.request;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.exception.DatabaseException;
\r
16 import org.simantics.db.service.QueryControl;
\r
18 abstract public class TransientUnaryRead<P, R> extends BinaryRead<Object,P,R> {
\r
20 protected static final Object WITH_PARENT = new Object();
\r
22 public TransientUnaryRead(ReadGraph graph, P parameter) throws DatabaseException {
\r
23 this(graph, graph.getService(QueryControl.class), parameter);
\r
26 public TransientUnaryRead(ReadGraph graph, QueryControl qc, P parameter) throws DatabaseException {
\r
27 super(resolveFirstParameter(graph, qc), parameter);
\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
36 final public R perform(ReadGraph _graph) throws DatabaseException {
\r
37 if(parameter == WITH_PARENT) {
\r
38 return perform(_graph, parameter2);
\r
40 QueryControl qc = _graph.getService(QueryControl.class);
\r
41 ReadGraph graph = qc.getIndependentGraph(_graph);
\r
42 return perform(graph, parameter2);
\r
46 abstract public R perform(ReadGraph graph, P parameter) throws DatabaseException;
\r