package org.simantics.document.server.request; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.simantics.db.ReadGraph; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.VariableChildren; import org.simantics.db.layer0.request.VariableRead; import org.simantics.db.layer0.variable.Variable; import org.simantics.structural.stubs.StructuralResource2; public class NodesRequest extends VariableRead> { public NodesRequest(Variable var) { super(var); } static class CollectNodesRequest2 extends UnaryRead, Set> { public CollectNodesRequest2(Collection nodes) { super(nodes); } @Override public Set perform(ReadGraph graph) throws DatabaseException { HashSet rs = new HashSet<>(); // result for(Variable child : parameter) { Set childNodes = graph.syncRequest(new NodesRequest2(child)); rs.addAll(childNodes); } return rs; } } @Override public Set perform(ReadGraph graph) throws DatabaseException { long s = System.nanoTime(); StructuralResource2.getInstance(graph); if(variable == null) return Collections.emptySet(); Collection children = graph.syncRequest(new VariableChildren(variable)); Set nodes = graph.syncRequest(new CollectNodesRequest2(children)); if(DocumentRequest.PROFILE) { long dura = System.nanoTime()-s; System.err.println("NodesRequest " + System.identityHashCode(this) + " in " + 1e-6*dura + "ms. " + variable.getURI(graph)); } return nodes; } }