]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Query control functions into Simantics/DB 32/1432/3
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 7 Feb 2018 12:53:32 +0000 (14:53 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Thu, 8 Feb 2018 06:23:33 +0000 (08:23 +0200)
refs #7752

Change-Id: I6de90fddcf5cb3b1834a096c8238f63ea6a7d33a

bundles/org.simantics.scl.db/scl/Simantics/DBSupport.scl
bundles/org.simantics.scl.db/src/org/simantics/scl/db/SCLFunctions.java

index ae7fe4d8eaf236f5a164f2c49e6243eec362147c..ee61b88b1e39a9be685b19731a12141161b9f47a 100644 (file)
@@ -1,7 +1,16 @@
 import "UI/Progress"
+import "Simantics/DB"
 
 importJava "org.simantics.scl.db.SCLFunctions" where
     collectClusters :: <Proc> ()
+    countQueries :: <ReadGraph> 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 -> <ReadGraph> ()
 
 importJava "org.simantics.db.layer0.util.Layer0Utils" where
     @JavaName emptyTrashBin
index aae7a89a26da69df9dc3e40360729ec673b754ed..618d6a91fbe793e5d982656f19a063f49e297627 100644 (file)
@@ -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();
+
+    }
+    
 }