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.Resource;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.db.request.ReadExt;
18 import org.simantics.db.service.QueryControl;
20 abstract public class TransientResourceRead<R> extends BinaryRead<Object,Resource,R> implements ReadExt {
22 protected static final Object WITH_PARENT = new Object();
24 public TransientResourceRead(ReadGraph graph, Resource parameter) throws DatabaseException {
25 this(graph, graph.getService(QueryControl.class), parameter);
28 public TransientResourceRead(ReadGraph graph, QueryControl qc, Resource parameter) throws DatabaseException {
29 super(resolveFirstParameter(graph, qc), parameter);
32 final private static Object resolveFirstParameter(ReadGraph graph, QueryControl qc) throws DatabaseException {
33 if(qc.hasParentRequest(graph)) return WITH_PARENT;
34 else return graph.getModificationCounter();
38 final public R perform(ReadGraph _graph) throws DatabaseException {
39 if(parameter == WITH_PARENT) {
40 return perform(_graph, parameter2);
42 QueryControl qc = _graph.getService(QueryControl.class);
43 ReadGraph graph = qc.getIndependentGraph(_graph);
44 return perform(graph, parameter2);
48 abstract public R perform(ReadGraph graph, Resource parameter) throws DatabaseException;
51 public boolean isImmutable(ReadGraph graph) throws DatabaseException {
52 return graph.isImmutable(parameter2);