]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fail safe import fixes made by Antti 17/717/3
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 17 Jul 2017 07:02:14 +0000 (10:02 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 1 Aug 2017 09:21:45 +0000 (12:21 +0300)
Fail safe import & pretty print fixes made by Antti and patch received
from Jussi

refs #7350 refs #7308 refs #7309

Change-Id: I63497ae3ac23f6cff579268e17e501b1647a74f3

14 files changed:
bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java
bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java
bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java

index 07d385235cfc7d32ccc633e95b66c4f14db8aeda..188917994a26881ccafe58a313ac6cb4559c2a67 100644 (file)
@@ -32,8 +32,8 @@ public final class ForEachObjectContextProcedure<C> implements AsyncContextMulti
        }
 
        @Override
-       public void finished(AsyncReadGraph graph) {
-               user.finished(graph);
+       public void finished(AsyncReadGraph graph, C context) {
+               user.finished(graph, context);
        }
 
        @Override
index 9ec12047c6c501a0dc2a58a836c3f69d073a10fe..4162f91636d0b39dfb193d7bb93c076e9885b849 100644 (file)
@@ -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
index d910f13ff946a77e40d9b2dce830c2020c678f40..a2e64868f7c21d43c1456c4662810c20f6ca4ed6 100644 (file)
@@ -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<InternalEntry> result;
+       final Set<Resource> childrenWithNoName;
        final AsyncContextMultiProcedure<InternalEntry, Resource> structure;
        final AsyncContextMultiProcedure<InternalEntry, Resource> names;
 
-    public static List<InternalEntry> walk(ReadGraph graph, ResourceMap<ExtentStatus> status, Collection<Resource> resources, Set<Resource> exclusions, boolean ignoreVirtual) throws DatabaseException {
+       public static Pair<List<InternalEntry>,Set<Resource>> walk(ReadGraph graph, ResourceMap<ExtentStatus> status, Collection<Resource> resources, Set<Resource> 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<InternalEntry>();
-               
+               childrenWithNoName = new HashSet<>();
                names = dqs.compileForEachObject(graph, L0.HasName, new AsyncContextMultiProcedure<InternalEntry, Resource>() {
 
                        @Override
@@ -58,8 +62,16 @@ class ConsistsOfProcess {
                                graph.forPossibleValue(nameResource, new Procedure<String>() {
 
                                        @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<InternalEntry, Resource>() {
@@ -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
index bd67680db6704f73bbe3a73d69aaa7774f8d3b5f..7a0a5f06bee35eb5c4eebf87691dd8e8bdf97c3a 100644 (file)
@@ -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<List<InternalEntry>,Set<Resource>> 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();
 
index f0a0893eb447d40455835d39fdd41cc40d6e3c5f..1d3cf61f54c6c6ad296b06a959f62dac66601537 100644 (file)
@@ -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);
                                }
index c7e697e6291773b58e44d8bd3a8c2afbf0952442..518efc882e45964dafb612ced7068636972a6f6b 100644 (file)
@@ -991,7 +991,8 @@ public class Subgraphs {
              * � All o are internal
              * � All stm are included
                         */
-                       List<InternalEntry> entries = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true); 
+                       Pair<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true);
+                       List<InternalEntry> 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.
index ffa39974315a1a06b50c57aada1816ae2677130e..0bd71af863fa4330b94b01969aff6e736c7c46b4 100644 (file)
@@ -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<InternalEntry> entries = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true); 
+                    Pair<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true); 
+                    List<InternalEntry> entries = pair.first;
                     for(InternalEntry entry : entries) {
                         if(findByIdentifier(graph, targetRoot, entry.resource))
                             return new GUIDExclusionFunction(graph);
index ea1c779faff615a3fdd256d69c8f95d8dcbb132d..1d3563fc1a3b5fca63688dca04a52c4805bdee50 100644 (file)
@@ -306,7 +306,7 @@ public class QuerySupportImpl implements QuerySupport {
                        
                 }
                        }
-                       procedure.finished(graph);
+                       procedure.finished(graph, context);
 //             graph.dec();
                return;
                
index 69450de7c8efc045e6aa6bab583e1c668f5a3507..c0ead5d073744444305acdf0247903c5f2593337 100644 (file)
@@ -304,7 +304,7 @@ public class IntHash extends IntHashTrait {
 
        }
        
-       procedure.finished(graph);
+       procedure.finished(graph, context);
 //     graph.dec();
        assert(size == count);
        
index 42ca6b018dd9348c5309f75e31084838c862ea73..da3b7903e7e270f2f1f6f5885ba12a3900700690 100644 (file)
@@ -167,7 +167,7 @@ public final class ObjectTable extends Table<int[]> {
        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;
         }
index 23d15dcfdb13fe6a10a7af104a5537fb18079d22..90519a36c3f6cb5916c7429c5af8e8ca41414deb 100644 (file)
@@ -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);
     }
 
index 84090af415e944ce757687706c2b7f67d646f71d..e997b731870159486a38cfebab9a2b7eb64f7c36 100644 (file)
@@ -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);
     }
     
index df5920c47b611463a08025aa9428c678666abf1d..2c57f3627323ebdfcb88d050df524c32fd09fcf3 100644 (file)
@@ -184,7 +184,7 @@ final class TableIntArraySet {
             
         }
         
-               procedure.finished(graph);
+               procedure.finished(graph, context);
 //             graph.state.dec(0);
         
     }
index 875ee37abe6dab1cb37e4a6e0568e2c883630bd1..c393d32dad8dc5d9753e8c02f32df2fe8755c687 100644 (file)
@@ -43,7 +43,7 @@ public interface AsyncContextMultiProcedure<Context, Result> {
      * 
      * @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