From: jsimomaa Date: Tue, 10 Oct 2017 04:44:30 +0000 (+0300) Subject: Listenable queries in SCL X-Git-Tag: v1.31.0~131^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F92%2F1092%2F2;p=simantics%2Fplatform.git Listenable queries in SCL refs #7540 Change-Id: Ibd25a6ac59316ad5a4876881a3af43551e740223 --- diff --git a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl index cd0242be7..ec9cc2671 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/DB.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/DB.scl @@ -344,6 +344,8 @@ importJava "org.simantics.scl.db.SCLFunctions" where subquery :: ( a) -> a "Makes a new read request with given procedure for calculating the result. The request is always cached." subqueryC :: ( a) -> a + "Makes a new read asynchronous request with function to handle the request result. The last `isDisposed` function parameter is used to determine if the listener is still alive or not." + subqueryL :: ( a) -> (a -> ()) -> (Throwable -> ()) -> ( Boolean) -> () "Tries to convert the given Dynamic value to a value with the inferred type" possibleFromDynamic :: Typeable a => String -> Dynamic -> Maybe a 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 00df313ad..da88b72c0 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 @@ -8,6 +8,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; +import org.simantics.db.common.procedure.adapter.SyncListenerAdapter; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.request.BinaryRead; import org.simantics.db.common.request.DelayedWriteRequest; @@ -33,6 +34,7 @@ import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function; import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.tuple.Tuple; import org.simantics.scl.runtime.tuple.Tuple0; import org.simantics.utils.DataContainer; @@ -319,6 +321,26 @@ public class SCLFunctions { public static Object subqueryC(ReadGraph graph, Function q) throws DatabaseException { return graph.syncRequest(new Subquery(q), TransientCacheAsyncListener.instance()); } + + 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); + } + + @Override + public void exception(ReadGraph graph, Throwable t) { + exceptionCallback.apply(t); + } + + @Override + public boolean isDisposed() { + return isDisposedCallback.apply(Tuple0.INSTANCE); + } + }); + } public static Object possibleFromDynamic(Type expectedType, String moduleName, Object value) {