From: Antti Villberg Date: Fri, 25 Jan 2019 10:26:23 +0000 (+0200) Subject: Fix document update / even better optimization of document requests X-Git-Tag: v1.43.0~136^2~204 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=086798a5c44ff57e4833e40124fa2c025253fdd2;p=simantics%2Fplatform.git Fix document update / even better optimization of document requests gitlab #249 Change-Id: I3b76b4ec8e767e974de83f4e52deba7c940b7174 --- diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index 4915fc002..186edd252 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import org.simantics.Simantics; @@ -15,6 +16,7 @@ import org.simantics.databoard.Bindings; import org.simantics.databoard.Datatypes; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.type.Datatype; +import org.simantics.db.AsyncReadGraph; import org.simantics.db.DirectStatements; import org.simantics.db.ReadGraph; import org.simantics.db.RequestProcessor; @@ -26,12 +28,13 @@ import org.simantics.db.common.primitiverequest.Adapter; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.BinaryRead; -import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.request.ResourceAsyncRead; import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ServiceException; import org.simantics.db.layer0.function.All; import org.simantics.db.layer0.request.ProjectModels; import org.simantics.db.layer0.request.PropertyInfo; @@ -51,6 +54,7 @@ import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.VariableMap; import org.simantics.db.layer0.variable.VariableMapImpl; import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.service.DirectQuerySupport; import org.simantics.document.base.ontology.DocumentationResource; import org.simantics.document.server.bean.Command; @@ -214,44 +218,66 @@ public class Functions { }; - static class DocumentPropertyKeys extends ResourceRead> { + static class DocumentPropertyKeys extends ResourceAsyncRead> { protected DocumentPropertyKeys(Resource resource) { super(resource); } @Override - public List perform(ReadGraph graph) throws DatabaseException { + public void perform(AsyncReadGraph graph, final AsyncProcedure> procedure) { - List result = new ArrayList<>(); + final List result = new ArrayList<>(); DocumentationResource DOC = DocumentationResource.getInstance(graph); - if(graph.hasStatement(resource, DOC.Properties_commands)) - result.add("commands"); - if(graph.hasStatement(resource, DOC.Properties_dataDefinitions)) - result.add("dataDefinitions"); + try { + if(graph.hasStatement(resource, DOC.Properties_commands)) + result.add("commands"); + if(graph.hasStatement(resource, DOC.Properties_dataDefinitions)) + result.add("dataDefinitions"); + } catch(ServiceException e) { + LOGGER.info(e.getMessage(), e); + } + + graph.forEachDirectPredicate(resource, new AsyncProcedure>() { - DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); - DirectStatements ds = dqs.getDirectPersistentStatements(graph, resource); + @Override + public void execute(AsyncReadGraph graph, Set predicates) { + + for(Resource predicate : predicates) { - for(Statement stm : ds) { + try { - Resource predicate = stm.getPredicate(); - PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); + PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); + + if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { + result.add(info.name); + } else { + Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation); + if(definition != null) { + PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition)); + result.add(info2.name); + } + } + + } catch (DatabaseException e) { + LOGGER.info(e.getMessage(), e); + } - if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { - result.add(info.name); - } else { - Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation); - if(definition != null) { - PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition)); - result.add(info2.name); } + + procedure.execute(graph, result); + } - } - return result; + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + LOGGER.info(throwable.getMessage(), throwable); + procedure.exception(graph, throwable); + } + + }); }