From: jsimomaa Date: Mon, 17 Jul 2017 07:02:14 +0000 (+0300) Subject: Fail safe import fixes made by Antti X-Git-Tag: v1.31.0~264^2~18 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F17%2F717%2F3;p=simantics%2Fplatform.git Fail safe import fixes made by Antti Fail safe import & pretty print fixes made by Antti and patch received from Jussi refs #7350 refs #7308 refs #7309 Change-Id: I63497ae3ac23f6cff579268e17e501b1647a74f3 --- diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java index 07d385235..188917994 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java @@ -32,8 +32,8 @@ public final class ForEachObjectContextProcedure implements AsyncContextMulti } @Override - public void finished(AsyncReadGraph graph) { - user.finished(graph); + public void finished(AsyncReadGraph graph, C context) { + user.finished(graph, context); } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java index 9ec12047c..4162f9163 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java @@ -145,7 +145,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic } @Override - public void finished(AsyncReadGraph graph) { + public void finished(AsyncReadGraph graph, Resource parent) { } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java index d910f13ff..a2e64868f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java @@ -2,6 +2,7 @@ package org.simantics.db.layer0.util; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -17,22 +18,25 @@ import org.simantics.db.procedure.AsyncContextMultiProcedure; import org.simantics.db.procedure.Procedure; import org.simantics.db.service.DirectQuerySupport; import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.Pair; class ConsistsOfProcess { final List result; + final Set childrenWithNoName; final AsyncContextMultiProcedure structure; final AsyncContextMultiProcedure names; - public static List walk(ReadGraph graph, ResourceMap status, Collection resources, Set exclusions, boolean ignoreVirtual) throws DatabaseException { + public static Pair,Set> walk(ReadGraph graph, ResourceMap status, Collection resources, Set exclusions, boolean ignoreVirtual) throws DatabaseException { ConsistsOfProcess process = new ConsistsOfProcess(graph, status, resources, exclusions, ignoreVirtual); - return process.result; + return Pair.make(process.result, process.childrenWithNoName); } static class InternalEntry { public InternalEntry parent; public Resource resource; public String name; + public boolean valid = true; InternalEntry(InternalEntry parent, Resource resource, String name) { this.parent = parent; this.resource = resource; @@ -46,7 +50,7 @@ class ConsistsOfProcess { final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); result = new ArrayList(); - + childrenWithNoName = new HashSet<>(); names = dqs.compileForEachObject(graph, L0.HasName, new AsyncContextMultiProcedure() { @Override @@ -58,8 +62,16 @@ class ConsistsOfProcess { graph.forPossibleValue(nameResource, new Procedure() { @Override - public void execute(String result) { - entry.name = result; + public void execute(String name) { + if(!entry.valid) return; + + if(name == null) { + entry.valid = false; + } else if (entry.name != null) { + entry.valid = false; + } else { + entry.name = name; + } } @Override @@ -76,9 +88,19 @@ class ConsistsOfProcess { } @Override - public void finished(AsyncReadGraph graph) { + public void finished(AsyncReadGraph graph, InternalEntry entry) { + if(entry.valid) { + if(entry.name != null) { + result.add(entry); + } else { + // This one did not have a name - not a valid internal + childrenWithNoName.add(entry.resource); + } + } else { + // Something wrong has happened. Do not treat as valid internal + childrenWithNoName.add(entry.resource); + } } - }); structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure() { @@ -90,16 +112,14 @@ class ConsistsOfProcess { if(!ignoreVirtual || child.isPersistent()) { InternalEntry entry = new InternalEntry(parent, child, null); - if(result.add(entry)) { - dqs.forEachObjectCompiled(graph, child, entry, structure); - dqs.forEachObjectCompiled(graph, child, entry, names); - } + dqs.forEachObjectCompiled(graph, child, entry, structure); + dqs.forEachObjectCompiled(graph, child, entry, names); } } @Override - public void finished(AsyncReadGraph graph) { + public void finished(AsyncReadGraph graph, InternalEntry parent) { } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java index bd67680db..7a0a5f06b 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java @@ -34,6 +34,7 @@ import org.simantics.db.service.TransferableGraphSupport; import org.simantics.graph.db.TransferableGraphSource; import org.simantics.layer0.Layer0; import org.simantics.scl.runtime.function.Function1; +import org.simantics.utils.datastructures.Pair; import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TIntIntHashMap; @@ -504,7 +505,8 @@ public class DomainProcessor3 { this.datatypeBinding = Bindings.getBindingUnchecked(Datatype.class); this.datatypeSerializer = graph.getService(Databoard.class).getSerializerUnchecked(this.datatypeBinding); - state.internalEntries = ConsistsOfProcess.walk(graph, status, fringe, exclusions, ignoreVirtual); + Pair,Set> pair = ConsistsOfProcess.walk(graph, status, fringe, exclusions, ignoreVirtual); + state.internalEntries = pair.first; for(InternalEntry entry : state.internalEntries) { Resource r = entry.resource; @@ -518,6 +520,12 @@ public class DomainProcessor3 { } } + for(Resource unnamedChild : pair.second) { + if (status.put(unnamedChild, ExtentStatus.INTERNAL) == null) { + fringe.add(unnamedChild); + } + } + if (state.monitor.isCanceled()) throw new CancelTransactionException(); 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 f0a0893eb..1d3cf61f5 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 @@ -416,8 +416,12 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { if(state.internalEntries != null) { for(InternalEntry ie : state.internalEntries) { - if(ie.parent != null && ie.name != null) { - procedure.execute(resolveInternal(graph, support, ie, internalMap)); + 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); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java index c7e697e62..518efc882 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java @@ -991,7 +991,8 @@ public class Subgraphs { * � All o are internal * � All stm are included */ - List entries = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true); + Pair,Set> pair = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true); + List entries = pair.first; for(InternalEntry entry : entries) { Resource r = entry.resource; if (status.put(r, ExtentStatus.INTERNAL) == null) { @@ -1003,6 +1004,12 @@ public class Subgraphs { } } + for(Resource unnamedChild : pair.second) { + if (status.put(unnamedChild, ExtentStatus.INTERNAL) == null) { + fringe.add(unnamedChild); + } + } + /* * This loop resolves the transitive closure of all p < IsRelatedTo such that p does not contain the SharedRange tag. * Such resources are guaranteed to be internal. diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java index ffa399743..0bd71af86 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java @@ -14,6 +14,7 @@ package org.simantics.db.layer0.util; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import org.simantics.datatypes.literal.GUID; import org.simantics.db.ReadGraph; @@ -26,6 +27,7 @@ import org.simantics.db.layer0.util.ConsistsOfProcess.InternalEntry; import org.simantics.db.layer0.util.DomainProcessor3.ExclusionDecision; import org.simantics.layer0.Layer0; import org.simantics.scl.runtime.function.Function1; +import org.simantics.utils.datastructures.Pair; /** * @author Antti Villberg @@ -63,7 +65,8 @@ public class TGRepresentationUtils { return new GUIDExclusionFunction(graph); // The root is OK - check everything beneath - List entries = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true); + Pair,Set> pair = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true); + List entries = pair.first; for(InternalEntry entry : entries) { if(findByIdentifier(graph, targetRoot, entry.resource)) return new GUIDExclusionFunction(graph); diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java index ea1c779fa..1d3563fc1 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java @@ -306,7 +306,7 @@ public class QuerySupportImpl implements QuerySupport { } } - procedure.finished(graph); + procedure.finished(graph, context); // graph.dec(); return; diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java index 69450de7c..c0ead5d07 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java @@ -304,7 +304,7 @@ public class IntHash extends IntHashTrait { } - procedure.finished(graph); + procedure.finished(graph, context); // graph.dec(); assert(size == count); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java index 42ca6b018..da3b7903e 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java @@ -167,7 +167,7 @@ public final class ObjectTable extends Table { if (ClusterTraits.statementIndexIsDirect(objectIndex)) { int key = modifier.execute(objectIndex); procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), key)); - procedure.finished(graph); + procedure.finished(graph, context); // graph.dec(); return; } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java index 23d15dcfd..90519a36c 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java @@ -477,7 +477,7 @@ public final class ResourceElementSmall { if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) { int completeRef = getCompleteObjectRef(table, index); if (0 == completeRef) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // no objects for given complete type } @@ -496,19 +496,19 @@ public final class ResourceElementSmall { } else { // One complete type element. CompleteRef is resource reference. ClusterI.CompleteTypeEnum rCompleteType = ResourceElementSmall.getCompleteType(table, index); if (pCompleteType != rCompleteType) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // Complete predicate does not match. } procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(completeRef))); } - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished } short p1 = getStm1Predicate(table, index); if (0 == p1) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, no statements } @@ -525,7 +525,7 @@ public final class ResourceElementSmall { } short p2 = getStm2Predicate(table, index); if (0 == p2 || pRef != p2) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, one statements } @@ -539,7 +539,7 @@ public final class ResourceElementSmall { // return true; // loop broken by procedure // return false; // loop finished procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(o2))); - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java index 84090af41..e997b7318 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java @@ -514,7 +514,7 @@ final class ResourceElement { if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) { int completeRef = getCompleteObjectRef(table, index); if (0 == completeRef) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // no objects for given complete type } @@ -543,14 +543,14 @@ final class ResourceElement { ForeachObject t = new ForeachObject(); // CompleteRef is complete object set index. ct.foreachComplete(completeRef, t, null, support, modifier); - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished } // one complete type element ClusterI.CompleteTypeEnum completeType = ClusterTraits.completeReferenceGetType(completeRef); if (pCompleteType != completeType) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; } @@ -562,7 +562,7 @@ final class ResourceElement { int externalRef = ClusterTraits.createForeignReference(clusterIndex, resourceIndex); procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(externalRef))); } - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished } @@ -570,7 +570,7 @@ final class ResourceElement { long l = table[i]; int p1 = (int) (l >>> 32); if (0 == p1) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, no statements } @@ -588,13 +588,13 @@ final class ResourceElement { long l2 = table[++i]; int p2 = (int) (l2 >>> 32); if (pRef != p2) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, one statements } int o2 = (int)l2; procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(o2))); - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java index df5920c47..2c57f3627 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java @@ -184,7 +184,7 @@ final class TableIntArraySet { } - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); } diff --git a/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java b/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java index 875ee37ab..c393d32da 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java +++ b/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java @@ -43,7 +43,7 @@ public interface AsyncContextMultiProcedure { * * @param graph asynchronous graph access */ - void finished(AsyncReadGraph graph); + void finished(AsyncReadGraph graph, Context context); /** * If an error occurs in the processing of the database request that