From: Antti Villberg Date: Fri, 17 Nov 2017 12:23:30 +0000 (+0200) Subject: Graph bookkeeping gets broken in SCL request API X-Git-Tag: v1.31.0~28 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ab9d7c411f5de4e4453e9bfb893c5a7559202fdb;p=simantics%2Fplatform.git Graph bookkeeping gets broken in SCL request API Also re-throw DatabaseExceptions directly instead of wrapping them in yet another DatabaseException in Simantics.apply* methods. refs #7624 Change-Id: I2e33164dc8f4782f97e796a3f7bd14f0da0a37c3 --- diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/SyncListenerAdapter.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/SyncListenerAdapter.java index 83d0d33f9..ba2e823da 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/SyncListenerAdapter.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/adapter/SyncListenerAdapter.java @@ -12,18 +12,19 @@ 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 implements SyncListener { @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 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 diff --git a/bundles/org.simantics/src/org/simantics/Simantics.java b/bundles/org.simantics/src/org/simantics/Simantics.java index c19efde85..cbe17e940 100644 --- a/bundles/org.simantics/src/org/simantics/Simantics.java +++ b/bundles/org.simantics/src/org/simantics/Simantics.java @@ -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 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);