-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.common.request;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.ReadExt;\r
-import org.simantics.db.service.QueryControl;\r
-\r
-abstract public class TransientResourceRead<R> extends BinaryRead<Object,Resource,R> implements ReadExt {\r
-\r
- protected static final Object WITH_PARENT = new Object();\r
- \r
- public TransientResourceRead(ReadGraph graph, Resource parameter) throws DatabaseException {\r
- this(graph, graph.getService(QueryControl.class), parameter);\r
- }\r
- \r
- public TransientResourceRead(ReadGraph graph, QueryControl qc, Resource parameter) throws DatabaseException {\r
- super(resolveFirstParameter(graph, qc), parameter);\r
- }\r
-\r
- final private static Object resolveFirstParameter(ReadGraph graph, QueryControl qc) throws DatabaseException {\r
- if(qc.hasParentRequest(graph)) return WITH_PARENT;\r
- else return graph.getModificationCounter();\r
- }\r
-\r
- @Override\r
- final public R perform(ReadGraph _graph) throws DatabaseException {\r
- if(parameter == WITH_PARENT) {\r
- return perform(_graph, parameter2);\r
- } else {\r
- QueryControl qc = _graph.getService(QueryControl.class);\r
- ReadGraph graph = qc.getIndependentGraph(_graph);\r
- return perform(graph, parameter2);\r
- }\r
- }\r
-\r
- abstract public R perform(ReadGraph graph, Resource parameter) throws DatabaseException;\r
- \r
- @Override\r
- public boolean isImmutable(ReadGraph graph) throws DatabaseException {\r
- return graph.isImmutable(parameter2);\r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.common.request;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.ReadExt;
+import org.simantics.db.service.QueryControl;
+
+abstract public class TransientResourceRead<R> extends BinaryRead<Object,Resource,R> implements ReadExt {
+
+ protected static final Object WITH_PARENT = new Object();
+
+ public TransientResourceRead(ReadGraph graph, Resource parameter) throws DatabaseException {
+ this(graph, graph.getService(QueryControl.class), parameter);
+ }
+
+ public TransientResourceRead(ReadGraph graph, QueryControl qc, Resource parameter) throws DatabaseException {
+ super(resolveFirstParameter(graph, qc), parameter);
+ }
+
+ final private static Object resolveFirstParameter(ReadGraph graph, QueryControl qc) throws DatabaseException {
+ if(qc.hasParentRequest(graph)) return WITH_PARENT;
+ else return graph.getModificationCounter();
+ }
+
+ @Override
+ final public R perform(ReadGraph _graph) throws DatabaseException {
+ if(parameter == WITH_PARENT) {
+ return perform(_graph, parameter2);
+ } else {
+ QueryControl qc = _graph.getService(QueryControl.class);
+ return qc.syncRequestIndependent(_graph, new UniqueRead<R>() {
+ @Override
+ public R perform(ReadGraph graph) throws DatabaseException {
+ return TransientResourceRead.this.perform(graph, parameter2);
+ }
+ });
+ }
+ }
+
+ abstract public R perform(ReadGraph graph, Resource parameter) throws DatabaseException;
+
+ @Override
+ public boolean isImmutable(ReadGraph graph) throws DatabaseException {
+ return graph.isImmutable(parameter2);
+ }
+
+}