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=bca7ba2481ff641b5a7d4c300ed80642cb751ac2;hp=09022d543c1aba3e9101028c88ed939b72759963;hb=b986319b03afb66cd4206338e0a424e937fd6fcf;hpb=599e0a37bfc3159ed450154c2a613a17def12fcb 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 09022d543..bca7ba248 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 @@ -177,7 +177,7 @@ public class SCLFunctions { private static Object[] NO_ARGS = new Object[] { Tuple0.INSTANCE }; - public static void asyncRead(final Function f) throws DatabaseException { + public static void asyncRead(final Function f) throws DatabaseException { asyncRead(f, NO_ARGS); } @@ -189,7 +189,7 @@ public class SCLFunctions { SCLContext.push(context); context.put(GRAPH, graph); try { - f.apply(Tuple0.INSTANCE); + f.applyArray(args); } finally { SCLContext.pop(); } @@ -213,7 +213,7 @@ public class SCLFunctions { SCLContext.push(context); ReadGraph oldGraph = (ReadGraph)context.put(GRAPH, graph); try { - return (T)f.apply(Tuple0.INSTANCE); + return (T)f.applyArray(args); } finally { context.put(GRAPH, oldGraph); SCLContext.pop(); @@ -236,7 +236,7 @@ public class SCLFunctions { SCLContext.push(context); context.put(GRAPH, graph); try { - f.apply(args); + f.applyArray(args); } finally { SCLContext.pop(); } @@ -254,9 +254,14 @@ public class SCLFunctions { public static T syncWrite(final Function f, final Object ... args) throws DatabaseException { final SCLContext context = SCLContext.getCurrent(); Object graph = context.get(GRAPH); - if (graph != null) { - return (T)f.apply(Tuple0.INSTANCE); + if (graph != null && graph instanceof WriteGraph) { + return (T)f.applyArray(args); } else { + if (graph != null) { + LOGGER.error( + "SCLContext {} for current thread {} contains an existing graph object but it is not WriteGraph - Somewhere is a function that forgets to remove the graph from the context!!", + context, Thread.currentThread()); + } final SCLReportingHandler printer = (SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); return Simantics.getSession().syncRequest(new WriteResultRequest() { @Override @@ -265,7 +270,7 @@ public class SCLFunctions { SCLReportingHandler oldPrinter = (SCLReportingHandler)context.put(SCLReportingHandler.REPORTING_HANDLER, printer); ReadGraph oldGraph = (ReadGraph)context.put(GRAPH, graph); try { - return (T)f.apply(args); + return (T)f.applyArray(args); } finally { context.put(GRAPH, oldGraph); context.put(SCLReportingHandler.REPORTING_HANDLER, oldPrinter);