]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Graph bookkeeping gets broken in SCL request API 35/1235/4
authorAntti Villberg <antti.villberg@semantum.fi>
Fri, 17 Nov 2017 12:23:30 +0000 (14:23 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 20 Nov 2017 09:52:52 +0000 (11:52 +0200)
Also re-throw DatabaseExceptions directly instead of wrapping them in
yet another DatabaseException in Simantics.apply* methods.

refs #7624

Change-Id: I2e33164dc8f4782f97e796a3f7bd14f0da0a37c3

bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/SyncListenerAdapter.java
bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java
bundles/org.simantics/src/org/simantics/Simantics.java

index 83d0d33f9c8da9dc0ddc6353aa1ba56925b16505..ba2e823da511bb95bfb317edb5a0ebd63a62d528 100644 (file)
 package org.simantics.db.common.procedure.adapter;
 
 import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.procedure.SyncListener;
 import org.slf4j.LoggerFactory;
 
 public abstract class SyncListenerAdapter<T> implements SyncListener<T> {
 
     @Override
-    public void exception(ReadGraph graph, Throwable t) {
+    public void exception(ReadGraph graph, Throwable t) throws DatabaseException {
         LoggerFactory.getLogger(getClass()).error("Failed to listen", t);
     }
 
     @Override
-    public void execute(ReadGraph graph, T result) {
+    public void execute(ReadGraph graph, T result) throws DatabaseException {
     }
 
     @Override
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
index c19efde85913a10c0ed6befba804d01f90b1fab7..cbe17e940d9436223aa6c2b62127872963a7b769 100644 (file)
@@ -25,7 +25,6 @@ import org.simantics.application.arguments.IArguments;
 import org.simantics.application.arguments.SimanticsArguments;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RequestProcessor;
-import org.simantics.db.RequestProcessorSpecific;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
@@ -477,11 +476,12 @@ public class Simantics {
         } catch (ValueNotFound e) {
             throw new DatabaseException("SCL Value not found: " + e.name);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         }
     }
 
-    @SuppressWarnings({ "unchecked", "rawtypes" })
     public static <T> T applySCL(String module, String function, ReadGraph graph, Object ... args) throws DatabaseException {
         SCLContext sclContext = SCLContext.getCurrent();
         Object oldGraph = sclContext.put("graph", graph);
@@ -503,6 +503,8 @@ public class Simantics {
         try {
             return (T)f.applyArray(args);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -516,6 +518,8 @@ public class Simantics {
         try {
             return (T)f.applyArray(args);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -528,6 +532,8 @@ public class Simantics {
         try {
             return function.apply(p0);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -540,6 +546,8 @@ public class Simantics {
         try {
             return function.apply(p0);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);
@@ -552,6 +560,8 @@ public class Simantics {
         try {
             return function.apply(p0, p1);
         } catch (Throwable t) {
+            if (t instanceof DatabaseException)
+                throw (DatabaseException) t;
             throw new DatabaseException(t);
         } finally {
             sclContext.put("graph", oldGraph);