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=59923933f6107f3e8f0d25e928c9b2fdc7229f1e;hp=da88b72c063ab2bb2862156f1f39afe5058839c9;hb=309b4b814a1375c2e2bd67bdee77d62bc9abf073;hpb=3edbf85ff8a7f1bd596857a24b1bdebd66943d6b 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 da88b72c0..59923933f 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 @@ -53,25 +53,19 @@ public class SCLFunctions { } public static void asyncRead(final Function f) throws DatabaseException { - final SCLContext context = SCLContext.getCurrent(); - Object graph = context.get(GRAPH); - if (graph != null) { - f.apply(Tuple0.INSTANCE); - } else { - Simantics.getSession().asyncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - SCLContext.push(context); - ReadGraph oldGraph = (ReadGraph)context.put(GRAPH, graph); - try { - f.apply(Tuple0.INSTANCE); - } finally { - context.put(GRAPH, oldGraph); - SCLContext.pop(); - } + final SCLContext context = SCLContext.createDerivedContext(); + Simantics.getSession().asyncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + SCLContext.push(context); + context.put(GRAPH, graph); + try { + f.apply(Tuple0.INSTANCE); + } finally { + SCLContext.pop(); } - }); - } + } + }); } public static T syncRead(final Function f) throws DatabaseException { @@ -97,25 +91,19 @@ public class SCLFunctions { } public static void asyncWrite(final Function f) throws DatabaseException { - final SCLContext context = SCLContext.getCurrent(); - Object graph = context.get(GRAPH); - if (graph != null) { - f.apply(Tuple0.INSTANCE); - } else { - Simantics.getSession().asyncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException { - SCLContext.push(context); - ReadGraph oldGraph = (ReadGraph)context.put(GRAPH, graph); - try { - f.apply(Tuple0.INSTANCE); - } finally { - context.put(GRAPH, oldGraph); - SCLContext.pop(); - } + SCLContext context = SCLContext.createDerivedContext(); + Simantics.getSession().asyncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + SCLContext.push(context); + context.put(GRAPH, graph); + try { + f.apply(Tuple0.INSTANCE); + } finally { + SCLContext.pop(); } - }); - } + } + }); } public static T syncWrite(final Function f) throws DatabaseException {