X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.db%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fdb%2FSCLFunctions.java;h=d8f83e05f5b2f231bc5dcd14bf27bf93ff85ffdc;hp=e20dfc471ad9ea28831463f00bc9bfc220d8704a;hb=1ae2c52a087a20a7fc9c0288b7e2398b4429e20e;hpb=158d6269660a3b415504f1da5a0b8341e761a5be diff --git a/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java b/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java index e20dfc471..d8f83e05f 100644 --- a/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java +++ b/bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java @@ -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; @@ -152,6 +163,18 @@ public class SCLFunctions { } } + public static void runWithGraph(Object 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 void asyncRead(final Function f) throws DatabaseException {