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;fp=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Frequest%2FNodesRequest2.java;h=6251fb6ec8d283ace11c7cd5592e40907efded21;hb=63bb6d595c37b3a2fb55e07fb810779cae3b4d03;hp=0f57a01c03f2cfc87ff34c9f3a1339fa9dbe9d52;hpb=26b755c7e98b7bb3d9038abba139bef0e71f6607;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 0f57a01c0..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 @@ -2,48 +2,91 @@ 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 { - - 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); - } - - return result; - } - - } + } + + @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