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