]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java
Pass graphs as ReadGraph instead of Object for clarity
[simantics/platform.git] / bundles / org.simantics.scl.db / src / org / simantics / scl / db / SCLFunctions.java
index e20dfc471ad9ea28831463f00bc9bfc220d8704a..2fd74b21e3e1c25e7b7b520ba24f559ff0749a06 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2019 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:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
 package org.simantics.scl.db;
 
 import java.io.IOException;
@@ -140,7 +151,7 @@ public class SCLFunctions {
         }
     }
     
-    public static <T> T evaluateGraph(String module, String function, Object graph, Object ... args) throws DatabaseException {
+    public static <T> T evaluateGraph(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException {
         final SCLContext context = SCLContext.getCurrent();
         SCLContext.push(context);
         Object oldGraph = context.put(GRAPH, graph);
@@ -152,6 +163,18 @@ public class SCLFunctions {
         }
     }
 
+    public static void runWithGraph(ReadGraph graph, Runnable r) {
+        final SCLContext context = SCLContext.getCurrent();
+        SCLContext.push(context);
+        Object oldGraph = context.put(GRAPH, graph);
+        try {
+            r.run();
+        } finally {
+            context.put(GRAPH, oldGraph);
+            SCLContext.pop();
+        }
+    }
+
     private static Object[] NO_ARGS = new Object[] { Tuple0.INSTANCE };
 
     public static <T> void asyncRead(final Function f) throws DatabaseException {