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=95923c79946206805ef467211e5523c313c766ee;hp=1d3cf61f54c6c6ad296b06a959f62dac66601537;hb=refs%2Fchanges%2F02%2F1402%2F2;hpb=dbe0a77f0869111219b69d412d0bb90d17c391c1 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 1d3cf61f5..95923c799 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,8 +27,9 @@ 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.layer0.util.ConsistsOfProcess.ConsistsOfProcessEntry; +import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec; +import org.simantics.db.layer0.util.TransferableGraphConfiguration2.SeedSpec.SeedSpecType; import org.simantics.db.service.SerialisationSupport; import org.simantics.graph.db.TransferableGraphSource; import org.simantics.graph.representation.External; @@ -68,34 +69,34 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { SerialisationSupport ss = graph.getService(SerialisationSupport.class); // At this point ids contains all internal resources. Now add roots and externals. - + // Root Library state.ids.put(ss.getTransientId(graph.getRootLibrary()), state.id++); - + // External roots - internal roots were already processed as internal resources by domain processor - for(RootSpec rs : configuration.roots) { - if(!rs.internal) { - int resourceId = ss.getTransientId(rs.resource); + for(SeedSpec spec : configuration.seeds) { + if(SeedSpecType.SPECIAL_ROOT.equals(spec.specType)) { + int resourceId = ss.getTransientId(spec.resource); state.ids.put(resourceId, state.id++); // The fixed roots have been seen as externals by domain processor. Now remove them from external set. state.externals.remove(resourceId); } } - + this.externalBase = state.id; final Collection errors = new HashSet<>(); // All resource considered as not internal by domain processor. Can also contain roots. int[] externals = state.externals.toArray(); - + // Build up the state.externals, externalNames and externalParents for(int i=0;i sorted = new ArrayList<>(errors); Collections.sort(sorted); @@ -120,15 +121,15 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { } throw new DatabaseException(message.toString()); } - + this.resourceCount = state.id; - + state.extensions.put(ExternalDownloadBean.EXTENSION_KEY, new Variant(ExternalDownloadBean.BINDING, new ExternalDownloadBean(downloads))); - + } int indent = 0; - + public boolean validateExternal(Resource ext) { if(configuration.validate) { ExtentStatus status = configuration.preStatus.get(ext); @@ -139,14 +140,14 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { } return true; } - + private Resource getResource(ReadGraph graph, int r) throws DatabaseException { SerialisationSupport ss = graph.getService(SerialisationSupport.class); return ss.getResource(r); } - + final public int getExistingId(ReadGraph graph, int r) throws DatabaseException { - + int ret = state.ids.get(r); if(ret != -1) { return ret; @@ -156,7 +157,7 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { } } - + /* * * @return -2 if r is not really external and the statement should be excluded @@ -166,10 +167,10 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { // // First external is root library // if(r == rootId) return internalCount; - + SerialisationSupport ss = graph.getService(SerialisationSupport.class); Layer0 L0 = Layer0.getInstance(graph); - + if(state.ids.containsKey(r)) { int ret = state.ids.get(r); if(ret == -1) { @@ -185,7 +186,7 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { errors.add("Illegal reference to " + graph.getPossibleURI(getResource(graph, r))); return -2; } - Collection parents = graph.getObjects(res, L0.PartOf); + Collection parents = graph.getObjects(res, L0.PartOf); if(parents.size() != 1) { throw new ValidationException("Reference to external resource " + NameUtils.getSafeName(graph, getResource(graph, r), true) + " without unique uri (" + parents.size() + " parents)."); @@ -215,27 +216,36 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { return state.id++; } } - + @Override public DataContainer getHeader() throws Exception { return null; } - + @Override public int getResourceCount() { return resourceCount; } - + + private int countRootSeeds() { + int result = 0; + for(SeedSpec spec : configuration.seeds) { + if(SeedSpecType.INTERNAL.equals(spec.specType)) continue; + result++; + } + return result; + } + @Override public int getIdentityCount() { - return configuration.roots.size() + state.externals.size() + state.internalEntries.size() + 1; + return countRootSeeds() + state.externals.size() + state.internalEntries.size() + 1; } - + @Override public int getStatementCount() { return state.statementCount; } - + @Override public int getValueCount() { return state.valueCount; @@ -243,18 +253,18 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { @Override public void forStatements(ReadGraph graph, TransferableGraphSourceProcedure procedure) throws Exception { - + int[] value = new int[4]; long length = state.otherStatementsInput.length(); state.otherStatementsInput.position(0); - + while(state.otherStatementsInput.position() < length && !state.monitor.isCanceled()) { - + int s = state.otherStatementsInput.readInt(); int subjectId = state.ids.get(s); - + boolean exclude = subjectId == -1; - + int size = state.otherStatementsInput.readInt(); for(int i=0;i procedure) throws Exception { - + SerialisationSupport support = graph.getService(SerialisationSupport.class); Layer0 L0 = Layer0.getInstance(graph); @@ -395,7 +405,8 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { TIntObjectMap internalMap = new TIntObjectHashMap<>(100, 0.5f, Integer.MIN_VALUE); // Declare internal and external roots - for(RootSpec r : configuration.roots) { + for(SeedSpec r : configuration.seeds) { + if(SeedSpecType.INTERNAL.equals(r.specType)) continue; String typeId = r.type; if (typeId == null) { Resource type = graph.getPossibleType(r.resource, L0.Entity); @@ -413,32 +424,44 @@ 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) { - if(ie.name != null) { - procedure.execute(resolveInternal(graph, support, ie, internalMap)); - } else { - // In this case there is a child that has no HasName => this should be treated as a blank - } + for(ConsistsOfProcessEntry ie : state.internalEntries) { + if(ie.parent != null) { + if(ie.name != null) { + procedure.execute(resolveInternal(graph, support, ie, internalMap)); + } else { + // In this case there is a child that has no HasName => this should be treated as a blank + } } else { - throw new DatabaseException("Invalid internal entry " + ie); + procedure.execute(resolveInternal(graph, support, ie, internalMap)); } } } - + } - - private Identity resolveInternal(ReadGraph graph, SerialisationSupport ss, InternalEntry entry, TIntObjectMap internalMap) throws DatabaseException { + + private Identity resolveInternal(ReadGraph graph, SerialisationSupport ss, ConsistsOfProcessEntry 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; + + if(entry.parent == null) { + Layer0 L0 = Layer0.getInstance(graph); + Resource possibleParent = graph.getPossibleObject(entry.resource, L0.PartOf); + if(possibleParent == null) throw new DatabaseException("Invalid root or internal parent path: " + entry.resource); + int externalId = state.ids.get(ss.getTransientId(possibleParent)); + Identity result = new Identity(id, + new Internal(externalId, entry.name)); + internalMap.put(id, result); + return result; + } else { + 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 @@ -467,7 +490,7 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { public void reset() throws Exception { throw new UnsupportedOperationException(); } - + public long[] getResourceArray(ReadGraph graph) throws DatabaseException { final SerialisationSupport ss = graph.getService(SerialisationSupport.class); final long[] result = new long[state.ids.size()]; @@ -475,38 +498,38 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { @Override public boolean execute(int a, int b) { - + try { Resource r = ss.getResource(a); result[b] = r.getResourceId(); } catch (DatabaseException e) { e.printStackTrace(); } - + return true; - + } }); return result; } - + public DomainProcessorState getState() { return state; } - + public void forResourceStatements(ReadGraph graph, TransferableGraphSourceProcedure procedure) throws Exception { - + int[] value = new int[4]; long length = state.otherStatementsInput.length(); state.otherStatementsInput.position(0); - + while(state.otherStatementsInput.position() < length) { - + int s = state.otherStatementsInput.readInt(); int subjectId = state.ids.get(s); - + boolean exclude = subjectId == -1; - + int size = state.otherStatementsInput.readInt(); for(int i=0;i