]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java
Graph bookkeeping gets broken in SCL request API
[simantics/platform.git] / bundles / org.simantics.scl.db / src / org / simantics / scl / db / SCLFunctions.java
index 59923933f6107f3e8f0d25e928c9b2fdc7229f1e..aae7a89a26da69df9dc3e40360729ec673b754ed 100644 (file)
@@ -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<Object> {
-        Function q;
+    private static class Subquery extends UnaryRead<Function, Object> {
 
         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<Throwable, Tuple> exceptionCallback, Function1<Tuple0, Boolean> isDisposedCallback) throws DatabaseException {
         graph.asyncRequest(new Subquery(query), new SyncListenerAdapter<Object>() {
-            
             @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