]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodesRequest.java
Fix document update / even better optimization of document requests
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / request / NodesRequest.java
1 package org.simantics.document.server.request;
2
3 import gnu.trove.set.hash.THashSet;
4
5 import java.util.Collection;
6 import java.util.Collections;
7 import java.util.Set;
8
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.request.VariableChildren;
12 import org.simantics.db.layer0.request.VariableRead;
13 import org.simantics.db.layer0.variable.Variable;
14 import org.simantics.structural.stubs.StructuralResource2;
15
16 public class NodesRequest extends VariableRead<Set<Variable>> {
17
18     public NodesRequest(Variable var) {
19         super(var);
20         }
21
22         @Override
23         public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
24
25                 long s = System.nanoTime();
26                 
27                 StructuralResource2.getInstance(graph);
28                 if(variable == null)
29                         return Collections.emptySet();
30                 
31                 Set<Variable> nodes = new THashSet<Variable>();
32                 Collection<Variable> children = graph.syncRequest(new VariableChildren(variable));
33                 for(Variable child : children) {
34                         Set<Variable> childNodes = graph.syncRequest(new NodesRequest2(child));
35                         nodes.addAll(childNodes);
36                 }
37                 
38         if(DocumentRequest.PROFILE) {
39                 long dura = System.nanoTime()-s;
40                 System.err.println("NodesRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph));
41         }
42                 
43                 return nodes;
44
45         }
46
47 }