X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Futil%2FModelTransferableGraphSource.java;h=e7fa24124a2ca1a72fca4955d320e385b87368de;hb=9acebe9584f8f2a78f0322b6e0e24438e7ceb984;hp=cbd3130eea6d737f2c431b685e47f6c306576399;hpb=081bf7e08a67c0af23c5846e163be39bb19f12cb;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java index cbd3130ee..e7fa24124 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java @@ -27,16 +27,20 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.RuntimeDatabaseException; import org.simantics.db.exception.ValidationException; import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus; +import org.simantics.db.layer0.util.ConsistsOfProcess.InternalEntry; import org.simantics.db.layer0.util.TransferableGraphConfiguration2.RootSpec; import org.simantics.db.service.SerialisationSupport; import org.simantics.graph.db.TransferableGraphSource; import org.simantics.graph.representation.External; import org.simantics.graph.representation.Identity; +import org.simantics.graph.representation.Internal; import org.simantics.graph.representation.Root; import org.simantics.graph.representation.Value; import org.simantics.layer0.Layer0; import gnu.trove.list.array.TIntArrayList; +import gnu.trove.map.TIntObjectMap; +import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.procedure.TIntIntProcedure; public class ModelTransferableGraphSource implements TransferableGraphSource { @@ -51,7 +55,7 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { private volatile boolean closed = false; TIntArrayList externalParents = new TIntArrayList(); - ArrayList externalNames = new ArrayList(); + ArrayList externalNames = new ArrayList<>(); TreeMap downloads = new TreeMap(); public ModelTransferableGraphSource(final ReadGraph graph, TransferableGraphConfiguration2 configuration, final DomainProcessorState state, File ... fs) throws DatabaseException { @@ -80,7 +84,7 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { this.externalBase = state.id; - final Collection errors = new HashSet(); + final Collection errors = new HashSet<>(); // All resource considered as not internal by domain processor. Can also contain roots. int[] externals = state.externals.toArray(); @@ -106,7 +110,7 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { }); if(!errors.isEmpty()) { - ArrayList sorted = new ArrayList(errors); + ArrayList sorted = new ArrayList<>(errors); Collections.sort(sorted); StringBuilder message = new StringBuilder(); message.append("Errors in exported model:\n"); @@ -388,13 +392,17 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { // TODO: this should be Root with name "" procedure.execute(getRootIdentity(state, support, graph.getRootLibrary())); + TIntObjectMap internalMap = new TIntObjectHashMap<>(100, 0.5f, Integer.MIN_VALUE); + // Declare internal and external roots for(RootSpec r : configuration.roots) { Resource type = graph.getPossibleType(r.resource, L0.Entity); if(type == null) type = L0.Entity; - procedure.execute(new Identity( - state.ids.get(support.getTransientId(r.resource)), - new Root(r.name, graph.getURI(type)))); + int id = state.ids.get(support.getTransientId(r.resource)); + Root root = new Root(r.name, graph.getURI(type)); + Identity rootId = new Identity(id,root); + internalMap.put(id, rootId); + procedure.execute(rootId); } for(int i = 0; i < state.externals.size() ; i++) { @@ -402,8 +410,27 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { String name = externalNames.get(i); procedure.execute(new Identity(externalBase + i, new External(parent,name))); } + + if(state.internalEntries != null) { + for(InternalEntry ie : state.internalEntries) { + if(ie.parent != null && ie.name != null) { + procedure.execute(resolveInternal(graph, support, ie, internalMap)); + } + } + } } + + private Identity resolveInternal(ReadGraph graph, SerialisationSupport ss, InternalEntry entry, TIntObjectMap internalMap) throws DatabaseException { + int id = state.ids.get(ss.getTransientId(entry.resource)); + Identity existing = internalMap.get(id); + if(existing != null) return existing; + Identity parent = resolveInternal(graph, ss, entry.parent, internalMap); + Identity result = new Identity(id, + new Internal(parent.resource, entry.name)); + internalMap.put(id, result); + return result; + } @Override public TreeMap getExtensions() {