From 98215de158f07c580afabbba0a28cb0d03154b12 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Wed, 7 Feb 2018 14:53:32 +0200 Subject: [PATCH] Query control functions into Simantics/DB refs #7752 Change-Id: I6de90fddcf5cb3b1834a096c8238f63ea6a7d33a --- .../scl/Simantics/DBSupport.scl | 9 ++++++++ .../org/simantics/scl/db/SCLFunctions.java | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/bundles/org.simantics.scl.db/scl/Simantics/DBSupport.scl b/bundles/org.simantics.scl.db/scl/Simantics/DBSupport.scl index ae7fe4d8e..ee61b88b1 100644 --- a/bundles/org.simantics.scl.db/scl/Simantics/DBSupport.scl +++ b/bundles/org.simantics.scl.db/scl/Simantics/DBSupport.scl @@ -1,7 +1,16 @@ import "UI/Progress" +import "Simantics/DB" importJava "org.simantics.scl.db.SCLFunctions" where collectClusters :: () + countQueries :: Integer + """ + restrictQueries amount step maxTimeInMs + + Collects some DB queries. Tries to reach at maximum 'amount' queries. + Uses at maximum 'maxTimeInMs' milliseconds in 'step' millisecond stints. + """ + restrictQueries :: Integer -> Integer -> Integer -> () importJava "org.simantics.db.layer0.util.Layer0Utils" where @JavaName emptyTrashBin 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 aae7a89a2..618d6a91f 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 @@ -21,6 +21,7 @@ import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.Variables; import org.simantics.db.request.Read; import org.simantics.db.service.ClusterControl; +import org.simantics.db.service.QueryControl; import org.simantics.db.service.SerialisationSupport; import org.simantics.db.service.VirtualGraphSupport; import org.simantics.layer0.utils.triggers.IActivationManager; @@ -327,4 +328,25 @@ public class SCLFunctions { return value; } + public static void restrictQueries(ReadGraph graph, int amount, int step, int maxTimeInMs) { + + QueryControl qc = graph.getService(QueryControl.class); + long start = System.currentTimeMillis(); + while(true) { + int current = qc.count(); + if(current < amount) return; + qc.gc(graph, step); + long duration = System.currentTimeMillis() - start; + if(duration > maxTimeInMs) return; + } + + } + + public static int countQueries(ReadGraph graph) { + + QueryControl qc = graph.getService(QueryControl.class); + return qc.count(); + + } + } -- 2.47.1