]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Predicates.java
Multiple readers and variable optimization
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / Predicates.java
index 3841e1d14640777706ce30421c00d2bcce2d43ea..e5cb6dfa146e10f6cf5b6b909554e56abe532cc0 100644 (file)
@@ -85,45 +85,39 @@ final public class Predicates extends UnaryQuery<InternalProcedure<IntSet>> {
 
        public static void computeForEach(ReadGraphImpl graph, final int r, final Predicates entry, final InternalProcedure<IntSet> procedure) throws DatabaseException {
        
-       
-       IntSet direct = QueryCache.resultDirectPredicates(graph, r, entry, null, procedure);
-               IntSet result = new IntSet();
-               direct.forEach(new TIntProcedure() {
-                       @Override
-                       public boolean execute(int value) {
-                               result.add(value);
-                               return true;
-                       }
-               });
+       IntSet direct = QueryCache.resultDirectPredicates(graph, r, entry, null);
                
+               IntSet result = new IntSet(graph.processor.querySupport);
        forAssertions(graph, r, entry, result);
        
-//             DirectPredicates.queryEach(graph, r, processor, entry, null, new IntProcedure() {
-//
-//                     @Override
-//                     public void execute(ReadGraphImpl graph, final int pred) throws DatabaseException {
-//                             result.add(pred);
-//                     }
-//
-//                     @Override
-//                     public void finished(ReadGraphImpl graph) throws DatabaseException {
-//                             
-//
-//                     }
-//
-//                     @Override
-//                     public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
-//                             procedure.exception(graph, t);
-//                     }
-//
-//             });
-               
-               if(entry != null) {
-                       entry.setResult(result);
-                       entry.setReady();
-               }
+       if(result.isEmpty()) {
+               
+               if(entry != null) {
+                       entry.setResult(direct);
+                       entry.setReady();
+               }
+               
+               procedure.execute(graph, direct);
+               
+       } else {
+               
+               direct.forEach(new TIntProcedure() {
+                       @Override
+                       public boolean execute(int value) {
+                               result.add(value);
+                               return true;
+                       }
+               });
+
+               if(entry != null) {
+                       entry.setResult(result);
+                       entry.setReady();
+               }
+               
+               procedure.execute(graph, result);
+               
+       }
                
-               procedure.execute(graph, result);
         
     }