From: Antti Villberg Date: Mon, 8 Jan 2018 06:23:52 +0000 (+0200) Subject: Switch to delayed write for more performance. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fheads%2Frelease%2F1.32.1;p=simantics%2Finterop.git Switch to delayed write for more performance. refs #7656 Change-Id: Iaf7e364bdbb286ca4761f6dc7b78efcb54560e33 --- diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java index 1779b8f..919fe4b 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/editor/ModelUpdateEditor.java @@ -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() { - @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()) diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java index f47dd93..3493631 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java @@ -9,6 +9,7 @@ import org.simantics.db.common.request.DelayedWriteRequest; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.util.Layer0Utils; +import org.simantics.db.service.XSupport; import org.simantics.message.ILogger; import org.simantics.message.MessageService; @@ -21,7 +22,7 @@ public abstract class AbstractImporter { private ILogger logger; private XMLParser parser; - private static final boolean USE_DELAYED = false; + private static final boolean USE_DELAYED = true; public AbstractImporter(Session session, File file) { this.session = session; @@ -42,7 +43,10 @@ public abstract class AbstractImporter { if (USE_DELAYED) { ImportDelayedRequest req = new ImportDelayedRequest(); session.syncRequest(req); - return req.getResult(); + Resource dr = req.getResult(); + XSupport xs = session.getService(XSupport.class); + Resource result = xs.convertDelayedResourceToResource(dr); + return result; } else { ImportRequest req = new ImportRequest(); session.syncRequest(req); diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java index e3298e3..2ab58f7 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java @@ -1,11 +1,18 @@ package org.simantics.xml.sax.base; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.MapList; import org.xml.sax.Attributes; public class ParserElement implements Serializable { @@ -13,16 +20,19 @@ public class ParserElement implements Serializable { String uri; String localName; String qName; - Map attributes = new HashMap(); - + Map attributes; + MapList lists; + XMLElementParser elementParser; XMLParser xmlParser; - + public ParserElement(String uri, String localName, String qName, Attributes attributes) { this.uri = uri; this.localName = localName; this.qName = qName; - for (int i = 0; i < attributes.getLength(); i++) { + int attrCount = attributes.getLength(); + this.attributes = new HashMap<>(attrCount); + for (int i = 0; i < attrCount; i++) { this.attributes.put(attributes.getLocalName(i),new Attribute(attributes.getLocalName(i),attributes.getQName(i),attributes.getURI(i),attributes.getValue(i))); } } @@ -31,6 +41,7 @@ public class ParserElement implements Serializable { this.uri = uri; this.localName = localName; this.qName = qName; + this.attributes = new HashMap<>(attributes.size()); for (Attribute a : attributes) { this.attributes.put(a.localName,new Attribute(a.localName,a.qName,a.uri,a.value)); } @@ -82,4 +93,23 @@ public class ParserElement implements Serializable { return xmlParser; } + public void registerListChild(Resource predicate, ParserElement child) { + if (lists == null) + lists = new MapList<>(); + lists.add(predicate, child); + } + + public void createLists(WriteGraph graph) throws DatabaseException { + if (lists == null) + return; + Layer0 L0 = Layer0.getInstance(graph); + for (Resource predicate : lists.getKeys()) { + List children = new ArrayList<>(); + for (ParserElement child : lists.getValues(predicate)) + children.add(child.getData()); + Resource list = ListUtils.create(graph, L0.List, L0.List_Element, null, children); + graph.claim(getData(), predicate, list); + } + } + } \ No newline at end of file diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java index 9689eda..87bb477 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java @@ -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{ diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java index 206acc0..3e02434 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java @@ -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(" }"); }