]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterSmall.java
Better fix for ClusterTable maps going out of sync
[simantics/platform.git] / bundles / org.simantics.db.procore / src / org / simantics / db / procore / cluster / ClusterSmall.java
index 4b963f38f9946bc0308f98ca3055056cec991bbe..ead0099847e70aacf5914535b74600c4d84dbb06 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.db.procore.cluster;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.util.function.Consumer;
 
 import org.simantics.db.Resource;
 import org.simantics.db.exception.DatabaseException;
@@ -32,7 +33,6 @@ import org.simantics.db.procedure.AsyncContextMultiProcedure;
 import org.simantics.db.procedure.AsyncMultiProcedure;
 import org.simantics.db.service.ClusterUID;
 import org.simantics.db.service.ResourceUID;
-import org.simantics.utils.datastructures.Callback;
 
 import fi.vtt.simantics.procore.DebugPolicy;
 import fi.vtt.simantics.procore.internal.ClusterChange;
@@ -40,7 +40,6 @@ import fi.vtt.simantics.procore.internal.ClusterStream;
 import fi.vtt.simantics.procore.internal.ClusterTable;
 import fi.vtt.simantics.procore.internal.SessionImplSocket;
 import gnu.trove.map.hash.TIntShortHashMap;
-import gnu.trove.procedure.TIntProcedure;
 import gnu.trove.set.hash.TIntHashSet;
 
 final public class ClusterSmall extends ClusterImpl {
@@ -940,7 +939,7 @@ final public class ClusterSmall extends ClusterImpl {
     }
 
     @Override
-    public void load(Callback<DatabaseException> r) {
+    public void load(Consumer<DatabaseException> r) {
         if (deleted) return;
         throw new Error("Not supported.");
     }
@@ -1009,6 +1008,7 @@ final public class ClusterSmall extends ClusterImpl {
         }
         if (deleted) return null; // Can't convert deleted cluster to big.
         ClusterBig big = new ClusterBig(getClusterUID(), clusterKey, support);
+        big.setImportance(importance);
         big.cc = this.cc;
         big.cc.clusterImpl = this;
         resourceTable.toBig(big, support, this);
@@ -1069,14 +1069,14 @@ final public class ClusterSmall extends ClusterImpl {
     public String toString() {
         if (deleted) return "ClusterSmall[" + getClusterId() + " - has been deleted or hasn't been created.]";
         try {
-            final TIntHashSet set = new TIntHashSet();
-            TIntShortHashMap map = foreignTable.getResourceHashMap();
-            map.forEachKey(new TIntProcedure() {
-                @Override
-                public boolean execute(int value) {
-                    set.add(value & 0xfffff000);
-                    return true;
-                }
+            ForeignTableSmall ft = foreignTable;
+            if (ft == null)
+                return "ClusterSmall[" + getClusterId() + " - " + getNumberOfResources() + "]";
+            TIntShortHashMap map = ft.getResourceHashMap();
+            TIntHashSet set = new TIntHashSet();
+            map.forEachKey(value -> {
+                set.add(value & 0xfffff000);
+                return true;
             });
             return "ClusterSmall[" + getClusterId() + " - " + getNumberOfResources() + " - " + foreignTable.getResourceHashMap().size() + " - " + set.size() + "]";
         } catch (Throwable e) {