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=aae7a89a26da69df9dc3e40360729ec673b754ed;hp=59923933f6107f3e8f0d25e928c9b2fdc7229f1e;hb=ab9d7c411f5de4e4453e9bfb893c5a7559202fdb;hpb=92faf11646c0b547de0b609adde82aa11d1282ca 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 59923933f..aae7a89a2 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 @@ -13,6 +13,7 @@ import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.request.BinaryRead; import org.simantics.db.common.request.DelayedWriteRequest; import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.UnaryRead; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.exception.DatabaseException; @@ -263,43 +264,17 @@ public class SCLFunctions { } - private static class Subquery implements Read { - Function q; + private static class Subquery extends UnaryRead { public Subquery(Function q) { - this.q = q; + super(q); } @Override public Object perform(ReadGraph graph) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.put("graph", graph); - try { - return q.apply(Tuple0.INSTANCE); - } catch (Throwable e) { - if(e instanceof DatabaseException) - throw (DatabaseException)e; - else - throw new DatabaseException(e); - } finally { - sclContext.put("graph", oldGraph); - } + return Simantics.applySCLRead(graph, parameter, Tuple0.INSTANCE); } - @Override - public int hashCode() { - return q.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if(this == obj) - return true; - if(obj == null || obj.getClass() != getClass()) - return false; - Subquery other = (Subquery)obj; - return q.equals(other.q); - } } public static Object subquery(ReadGraph graph, Function q) throws DatabaseException { @@ -312,15 +287,14 @@ public class SCLFunctions { public static void subqueryL(ReadGraph graph, Function query, Function executeCallback, Function1 exceptionCallback, Function1 isDisposedCallback) throws DatabaseException { graph.asyncRequest(new Subquery(query), new SyncListenerAdapter() { - @Override - public void execute(ReadGraph graph, Object result) { - executeCallback.apply(result); + public void execute(ReadGraph graph, Object result) throws DatabaseException { + Simantics.applySCLRead(graph, executeCallback, result); } @Override - public void exception(ReadGraph graph, Throwable t) { - exceptionCallback.apply(t); + public void exception(ReadGraph graph, Throwable t) throws DatabaseException { + Simantics.applySCLRead(graph, exceptionCallback, t); } @Override