X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Futil%2FModelTransferableGraphSource.java;h=f0a0893eb447d40455835d39fdd41cc40d6e3c5f;hp=cbd3130eea6d737f2c431b685e47f6c306576399;hb=22703b9675e377d3620fb5b9fe1e4c3adc18edc4;hpb=32c804755176db2bb20f46f6a69a418c46d458f5 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..f0a0893eb 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"); @@ -224,7 +228,7 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { @Override public int getIdentityCount() { - return configuration.roots.size() + state.externals.size() + 1; + return configuration.roots.size() + state.externals.size() + state.internalEntries.size() + 1; } @Override @@ -388,13 +392,20 @@ 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)))); + String typeId = r.type; + if (typeId == null) { + Resource type = graph.getPossibleType(r.resource, L0.Entity); + typeId = type != null ? graph.getURI(type) : Layer0.URIs.Entity; + } + int id = state.ids.get(support.getTransientId(r.resource)); + Root root = new Root(r.name, typeId); + Identity rootId = new Identity(id,root); + internalMap.put(id, rootId); + procedure.execute(rootId); } for(int i = 0; i < state.externals.size() ; i++) { @@ -402,8 +413,29 @@ 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)); + } else { + throw new DatabaseException("Invalid internal entry " + ie); + } + } + } } + + 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() {