]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java
Document performance optimizations
[simantics/platform.git] / bundles / org.simantics.document.server / src / org / simantics / document / server / Functions.java
index 6ec2e6734a5a70808dcb02d6ef9e05c43a3a97ef..4915fc002ecdbc91b0a54806f796daa8f730b85e 100644 (file)
@@ -23,8 +23,10 @@ import org.simantics.db.Session;
 import org.simantics.db.Statement;
 import org.simantics.db.WriteGraph;
 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.UniqueRead;
 import org.simantics.db.common.request.WriteResultRequest;
 import org.simantics.db.common.utils.Logger;
@@ -212,28 +214,91 @@ public class Functions {
 
     };
 
-    static class StandardDocumentProperties implements DocumentProperties {
+    static class DocumentPropertyKeys extends ResourceRead<List<String>> {
+
+        protected DocumentPropertyKeys(Resource resource) {
+            super(resource);
+        }
 
         @Override
-        public Collection<String> getKeys(ReadGraph graph, Variable context) throws DatabaseException {
-            
+        public List<String> perform(ReadGraph graph) throws DatabaseException {
+
+            List<String> result = new ArrayList<>();
+
             DocumentationResource DOC = DocumentationResource.getInstance(graph);
-            StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties);
-            Map<String, Variable> ps = primitiveProperties.getVariables(graph, asd, null);
-            return ps.keySet();
-            
+
+            if(graph.hasStatement(resource, DOC.Properties_commands))
+                result.add("commands");
+            if(graph.hasStatement(resource, DOC.Properties_dataDefinitions))
+                result.add("dataDefinitions");
+
+            DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
+            DirectStatements ds = dqs.getDirectPersistentStatements(graph, resource);
+
+            for(Statement stm : ds) {
+
+                Resource predicate = stm.getPredicate();
+                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);
+                    }
+                }
+            }
+
+            return result;
+
+        }
+
+    }
+
+    static class StandardDocumentProperties implements DocumentProperties {
+
+        @Override
+        public Collection<String> getKeys(ReadGraph graph, Variable parent) throws DatabaseException {
+
+            if(parent instanceof StandardProceduralChildVariable) {
+
+                StandardProceduralChildVariable procedural = (StandardProceduralChildVariable)parent;
+                List<String> result = new ArrayList<>();
+                for(Variable property : procedural.getProperties(graph)) {
+                    if(property instanceof StandardAssertedGraphPropertyVariable) {
+                        StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property;
+                        if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name)  || "pollingFunction".equals(ass.property.name)) {
+                            result.add(ass.property.name);
+                        }
+                        continue;
+                    }
+                    Resource predicate = property.getPossiblePredicateResource(graph);
+                    if(predicate != null) {
+                        PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate));
+                        if(info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) {
+                            result.add(info.name);
+                        }
+                    }
+                }
+
+                return result;
+
+            } else {
+
+                Resource parentRes = parent.getRepresents(graph);
+                return graph.syncRequest(new DocumentPropertyKeys(parentRes), TransientCacheAsyncListener.instance());
+
+            }
+
         }
 
         @Override
         public Object getValue(ReadGraph graph, Variable context, String key) throws DatabaseException {
-            
-            DocumentationResource DOC = DocumentationResource.getInstance(graph);
-            StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties);
-            Map<String, Variable> ps = primitiveProperties.getVariables(graph, asd, null);
-            return ps.get(key).getValue(graph);
-            
+            return context.getPropertyValue(graph, key);
         }
-        
+
     }
     
     public static DocumentProperties primitiveProperties() throws DatabaseException {