]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Switch to delayed write for more performance. 57/1357/3 release/1.32.0 release/1.32.0.1 release/1.32.0.2 release/1.32.1
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 8 Jan 2018 06:23:52 +0000 (08:23 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 8 Jan 2018 08:57:08 +0000 (10:57 +0200)
refs #7656

Change-Id: Iaf7e364bdbb286ca4761f6dc7b78efcb54560e33

org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java
org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java

index 1779b8f6bbdaf188b1556a2c61d69669a3035374..919fe4b68238d05311533d363553bdad6de0bc17 100644 (file)
@@ -51,8 +51,8 @@ import org.simantics.db.request.Read;
 import org.simantics.interop.test.GraphChanges;
 import org.simantics.interop.update.Activator;
 import org.simantics.interop.update.model.ModelUpdate;
-import org.simantics.interop.update.model.PropertyChange;
 import org.simantics.interop.update.model.ModelUpdate.WarningListener;
+import org.simantics.interop.update.model.PropertyChange;
 import org.simantics.interop.update.model.UpdateList;
 import org.simantics.interop.update.model.UpdateNode;
 import org.simantics.interop.update.model.UpdateOp;
@@ -60,7 +60,6 @@ import org.simantics.interop.update.model.UpdateStatus;
 import org.simantics.interop.update.model.UpdateTree;
 import org.simantics.interop.utils.TableUtils;
 import org.simantics.ui.SimanticsUI;
-import org.simantics.utils.datastructures.Callback;
 import org.simantics.utils.datastructures.Pair;
 import org.simantics.utils.ui.ExceptionUtils;
 
@@ -433,12 +432,9 @@ public abstract class ModelUpdateEditor extends Composite implements WarningList
                        }
                        
                        
-               }, new Callback<DatabaseException>() {
-                       @Override
-                       public void run(DatabaseException parameter) {
-                               if (parameter != null)
-                                       ExceptionUtils.logAndShowError("Cannot update model", parameter);
-                       }
+               }, e -> {
+                       if (e != null)
+                               ExceptionUtils.logAndShowError("Cannot update model", e);
                });
        }
        
@@ -609,10 +605,8 @@ public abstract class ModelUpdateEditor extends Composite implements WarningList
        private class SelectionEditingSupport extends EditingSupport {
                
                
-               @SuppressWarnings("rawtypes")
                public SelectionEditingSupport(ColumnViewer viewer) {
                        super(viewer);
-                       
                }
 
                @Override
@@ -633,7 +627,6 @@ public abstract class ModelUpdateEditor extends Composite implements WarningList
                        return pc.selected();
                }
                
-               @SuppressWarnings("unchecked")
                @Override
                protected void setValue(Object element, Object value) {
                        if (update == null || !update.isInit())
index f47dd9395c90e2338236fb0508ac9572a856327c..34936318f3cec738e3fe8b58a7efac3bd3de8065 100644 (file)
@@ -9,6 +9,7 @@ import org.simantics.db.common.request.DelayedWriteRequest;
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.layer0.util.Layer0Utils;\r
+import org.simantics.db.service.XSupport;\r
 import org.simantics.message.ILogger;\r
 import org.simantics.message.MessageService;\r
 \r
@@ -21,7 +22,7 @@ public abstract class AbstractImporter {
        private ILogger logger;\r
        private XMLParser parser;\r
        \r
-       private static final boolean USE_DELAYED = false;\r
+       private static final boolean USE_DELAYED = true;\r
        \r
        public AbstractImporter(Session session, File file)  {\r
                this.session = session;\r
@@ -42,7 +43,10 @@ public abstract class AbstractImporter {
                if (USE_DELAYED) {\r
                        ImportDelayedRequest req = new ImportDelayedRequest();\r
                        session.syncRequest(req);\r
-                       return req.getResult();\r
+                       Resource dr = req.getResult();\r
+                       XSupport xs = session.getService(XSupport.class);\r
+                       Resource result = xs.convertDelayedResourceToResource(dr);\r
+                       return result;\r
                } else {\r
                        ImportRequest req = new ImportRequest();\r
                        session.syncRequest(req);\r
index e3298e3677c8c54916bf4d80cb030f447ea29cac..2ab58f773ae54d2d154b944bc3d0f89e8926ff17 100644 (file)
@@ -1,11 +1,18 @@
 package org.simantics.xml.sax.base;\r
 \r
 import java.io.Serializable;\r
+import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.HashMap;\r
+import java.util.List;\r
 import java.util.Map;\r
 \r
 import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.utils.datastructures.MapList;\r
 import org.xml.sax.Attributes;\r
 \r
 public class ParserElement implements Serializable {\r
@@ -13,16 +20,19 @@ public class ParserElement implements Serializable {
        String uri;\r
        String localName;\r
        String qName;\r
-       Map<String,Attribute> attributes = new HashMap<String, Attribute>();\r
-       \r
+       Map<String, Attribute> attributes;\r
+       MapList<Resource, ParserElement> lists;\r
+\r
        XMLElementParser elementParser;\r
        XMLParser xmlParser;\r
-       \r
+\r
        public ParserElement(String uri, String localName, String qName, Attributes attributes) {\r
                this.uri = uri;\r
                this.localName = localName;\r
                this.qName = qName;\r
-               for (int i = 0; i < attributes.getLength(); i++) {\r
+               int attrCount = attributes.getLength();\r
+               this.attributes = new HashMap<>(attrCount);\r
+               for (int i = 0; i < attrCount; i++) {\r
                        this.attributes.put(attributes.getLocalName(i),new Attribute(attributes.getLocalName(i),attributes.getQName(i),attributes.getURI(i),attributes.getValue(i)));\r
                }\r
        }\r
@@ -31,6 +41,7 @@ public class ParserElement implements Serializable {
                this.uri = uri;\r
                this.localName = localName;\r
                this.qName = qName;\r
+               this.attributes = new HashMap<>(attributes.size());\r
                for (Attribute a : attributes) {\r
                        this.attributes.put(a.localName,new Attribute(a.localName,a.qName,a.uri,a.value));\r
                }\r
@@ -82,4 +93,23 @@ public class ParserElement implements Serializable {
                return xmlParser;\r
        }\r
 \r
+       public void registerListChild(Resource predicate, ParserElement child) {\r
+               if (lists == null)\r
+                       lists = new MapList<>();\r
+               lists.add(predicate, child);\r
+       }\r
+\r
+       public void createLists(WriteGraph graph) throws DatabaseException {\r
+               if (lists == null)\r
+                       return;\r
+               Layer0 L0 = Layer0.getInstance(graph);\r
+               for (Resource predicate : lists.getKeys()) {\r
+                       List<Resource> children = new ArrayList<>();\r
+                       for (ParserElement child : lists.getValues(predicate))\r
+                               children.add(child.getData());\r
+                       Resource list = ListUtils.create(graph, L0.List, L0.List_Element, null, children);\r
+                       graph.claim(getData(), predicate, list);\r
+               }\r
+       }\r
+\r
 }
\ No newline at end of file
index 9689eda1f8c56b396f50ad383e60d6eccd19bab6..87bb477b788902adc54ffd5f7d38fd21861d726b 100644 (file)
@@ -199,6 +199,11 @@ public class XMLParser extends DefaultHandler implements Serializable {
                                }
                        }
                }
+               try {
+                       element.createLists(graph);
+               } catch (DatabaseException e) {
+                       throw new SAXException(e);
+               }
        }
        
        private void handleCharacters(ParserElement element, String string) throws SAXException{
index 206acc0eca84f78d30a1aac4778f070bda1a33c2..3e02434e797481d721e9e1f5ac0a0290f5a8e322 100644 (file)
@@ -252,26 +252,28 @@ public class ImporterGenerator extends JavaGenerator{
 
                // element type specific list
                fw.delayedWriter.println("            {");
-               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
-               fw.delayedWriter.println("               if (list == null) {");
-               fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
-               fw.delayedWriter.println("               } else {");
-               fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("               }");
+               fw.delayedWriter.println("               element.registerListChild("+ontShort+getName(parent)+"_has"+refName + "_List, child);");
+//             fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
+//             fw.delayedWriter.println("               if (list == null) {");
+//             fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
+//             fw.delayedWriter.println("               } else {");
+//             fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("               }");
                fw.delayedWriter.println("            }");
                }
                if (useOriginalList) {
                // generic list
                fw.delayedWriter.println("            {");
                fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");
-               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
-               fw.delayedWriter.println("               if (list == null) {");
-               fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");
-               fw.delayedWriter.println("               } else {");
-               fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("               }");
+               fw.delayedWriter.println("               element.registerListChild(XML.hasOriginalElementList, child);");
+//             fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
+//             fw.delayedWriter.println("               if (list == null) {");
+//             fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");
+//             fw.delayedWriter.println("               } else {");
+//             fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("               }");
                fw.delayedWriter.println("            }");
                }
                
@@ -321,26 +323,28 @@ public class ImporterGenerator extends JavaGenerator{
 
                // element type specific list
                fw.delayedWriter.println("            {");
-               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
-               fw.delayedWriter.println("               if (list == null) {");
-               fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
-               fw.delayedWriter.println("               } else {");
-               fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("               }");
+               fw.delayedWriter.println("               element.registerListChild(" + ontShort+getName(parent)+"_has"+refName + "_List, child);");
+//             fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List);");
+//             fw.delayedWriter.println("               if (list == null) {");
+//             fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("                  graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+refName + "_List,list);");
+//             fw.delayedWriter.println("               } else {");
+//             fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("               }");
                fw.delayedWriter.println("            }");
                }
                if (useOriginalList) {
                // generic list
                fw.delayedWriter.println("            {");
                fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");
-               fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
-               fw.delayedWriter.println("               if (list == null) {");
-               fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");
-               fw.delayedWriter.println("               } else {");
-               fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
-               fw.delayedWriter.println("               }");
+               fw.delayedWriter.println("               element.registerListChild(XML.hasOriginalElementList, child);");
+//             fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");
+//             fw.delayedWriter.println("               if (list == null) {");
+//             fw.delayedWriter.println("                  list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,list);");
+//             fw.delayedWriter.println("               } else {");
+//             fw.delayedWriter.println("                  org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");
+//             fw.delayedWriter.println("               }");
                fw.delayedWriter.println("            }");
                }