X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Frequest%2FNodesRequest2.java;h=6251fb6ec8d283ace11c7cd5592e40907efded21;hb=63bb6d595c37b3a2fb55e07fb810779cae3b4d03;hp=605633012382be41f677f01102b0eb61516d58d0;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodesRequest2.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodesRequest2.java index 605633012..6251fb6ec 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodesRequest2.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodesRequest2.java @@ -1,56 +1,92 @@ -package org.simantics.document.server.request; - -import gnu.trove.set.hash.THashSet; - -import java.util.Collections; -import java.util.Set; - -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.VariableRead; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.document.base.ontology.DocumentationResource; - -public class NodesRequest2 extends VariableRead> { - - public NodesRequest2(Variable var) { - super(var); - } - - @Override - public Set perform(ReadGraph graph) throws DatabaseException { - - long s = System.nanoTime(); - - DocumentationResource DOC = DocumentationResource.getInstance(graph); - - Resource type = variable.getPossibleType(graph); - if(type == null) return Collections.emptySet(); - - if(!graph.isInheritedFrom(type, DOC.Components_Component)) return Collections.emptySet(); - - Boolean pathExists = variable.getPossiblePropertyValue(graph, DOC.Properties_pathExists, Bindings.BOOLEAN); - if(pathExists != null && !pathExists) return Collections.emptySet(); - - if(graph.isInheritedFrom(type, DOC.Components_PrimitiveComponent)) { - return Collections.singleton(variable); - } else { - Set result = new THashSet(); - for(Variable child : variable.getChildren(graph)) { - Set nodes = graph.syncRequest(new NodesRequest2(child)); - result.addAll(nodes); - } - - if(DocumentRequest.PROFILE) { - long dura = System.nanoTime()-s; - System.err.println("NodesRequest2 " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms."); - } - - return result; - } - - } - +package org.simantics.document.server.request; + +import gnu.trove.set.hash.THashSet; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import org.simantics.databoard.Bindings; +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.AsyncReadRequest; +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.db.procedure.AsyncProcedure; +import org.simantics.document.base.ontology.DocumentationResource; +import org.simantics.utils.threads.logger.ITask; +import org.simantics.utils.threads.logger.ThreadLogger; + +public class NodesRequest2 extends VariableRead> { + + public NodesRequest2(Variable var) { + super(var); + } + + @Override + public Set perform(ReadGraph graph) throws DatabaseException { + + ITask task = DocumentRequest.PROFILE ? ThreadLogger.task(this) : null; + + DocumentationResource DOC = DocumentationResource.getInstance(graph); + + Resource type = variable.getPossibleType(graph); + if(type == null) { + if(DocumentRequest.PROFILE) task.finish(); + return Collections.emptySet(); + } + + if(!graph.isInheritedFrom(type, DOC.Components_Component)) { + if(DocumentRequest.PROFILE) task.finish(); + return Collections.emptySet(); + } + + Boolean pathExists = variable.getPossiblePropertyValue(graph, DOC.Properties_pathExists, Bindings.BOOLEAN); + if(pathExists != null && !pathExists) { + if(DocumentRequest.PROFILE) task.finish(); + return Collections.emptySet(); + } + + if(graph.isInheritedFrom(type, DOC.Components_PrimitiveComponent)) { + if(DocumentRequest.PROFILE) task.finish(); + return Collections.singleton(variable); + } else { + Set result = new THashSet(); + Collection children = graph.syncRequest(new VariableChildren(variable)); + graph.syncRequest(new AsyncReadRequest() { + + @Override + public void run(AsyncReadGraph graph) throws DatabaseException { + + for(Variable child : children) { + graph.asyncRequest(new NodesRequest2(child), new AsyncProcedure>() { + + @Override + public void execute(AsyncReadGraph graph, Set vars) { + synchronized(result) { + result.addAll(vars); + } + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + } + + }); + } + + } + + }); + + if(DocumentRequest.PROFILE) task.finish(); + return result; + + } + + } + } \ No newline at end of file