X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FClusterTable.java;h=6cab018a6f4beadde5859f94fc86de4b75638a92;hb=4c5ff8ec11947aae4d49106365819717cfa43209;hp=c6fd11c4eb35900763e1176b51fe90f7001819e3;hpb=b29a69792f689d2ac7beffb725c814aa65fca301;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterTable.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterTable.java index c6fd11c4e..6cab018a6 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterTable.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterTable.java @@ -135,7 +135,7 @@ public final class ClusterTable implements IClusterTable { int clusterKey = hashMap.size(); ClusterSmall sentinel = new ClusterSmall(clusterUID, clusterKey, ClusterTable.this, sessionImpl.clusterTranslator); if (sentinel.clusterId != sentinel.clusterUID.second) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); create(sentinel); return sentinel; } @@ -144,25 +144,25 @@ public final class ClusterTable implements IClusterTable { create(proxy); if (null != old) { if (old.clusterKey != proxy.clusterKey) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); if (old.clusterId != proxy.clusterId) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); if (!old.clusterUID.equals(proxy.clusterUID)) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); } } private ClusterSmall freeProxy(ClusterImpl proxy) { ClusterImpl clusterImpl = hashMap.get(proxy.clusterId); if (null == clusterImpl) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); // ClusterUID clusterUID = ClusterUID.make(0, proxy.clusterId); // ClusterImpl clusterImpl2 = clusterU2I.get(clusterUID ); // if (clusterImpl != clusterImpl2) -// throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); +// throw new RuntimeDatabaseException("ClusterTable corrupted."); if (proxy.clusterId != clusterImpl.clusterId) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); if (proxy.clusterKey != clusterImpl.clusterKey) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); ClusterSmall sentinel = new ClusterSmall(makeClusterUID(proxy.clusterId) , proxy.clusterKey, ClusterTable.this, sessionImpl.clusterTranslator); return (ClusterSmall)create(sentinel); } @@ -289,14 +289,29 @@ public final class ClusterTable implements IClusterTable { } } - synchronized void replaceCluster(ClusterI cluster) { - //printMaps("replaceCluster"); + synchronized void replaceCluster(ClusterI cluster_) { + ClusterImpl cluster = (ClusterImpl) cluster_; checkCollect(); int clusterKey = cluster.getClusterKey(); - ClusterI existing = clusterArray[clusterKey]; + ClusterImpl existing = (ClusterImpl) clusterArray[clusterKey]; if (existing.hasVirtual()) cluster.markVirtual(); + if (existing.cc != null) { + if (existing.isLoaded()) { + // This shall be promoted to actual exception in the future - + // for now, minimal changes + new Exception("Trying to replace cluster with pending changes " + existing.getClusterUID()) + .printStackTrace(); + } else { + // Adopt changes to loaded cluster + cluster.cc = existing.cc; + cluster.cc.adopt(cluster); + cluster.foreignLookup = existing.foreignLookup; + cluster.change = existing.change; + } + } + importanceMap.remove(existing.getImportance()); if (collectorPolicy != null) collectorPolicy.removed((ClusterImpl)existing); @@ -580,7 +595,7 @@ public final class ClusterTable implements IClusterTable { void removeWriteOnlyClusters() { for (ClusterI proxy : writeOnlyClusters) { if (!(proxy instanceof ClusterImpl)) - throw new RuntimeDatabaseException("ClusterTable corrupted. Contact application support."); + throw new RuntimeDatabaseException("ClusterTable corrupted."); clusters.freeProxy((ClusterImpl)proxy); } writeOnlyClusters.clear(); @@ -589,7 +604,6 @@ public final class ClusterTable implements IClusterTable { public boolean execute(int clusterKey) { ClusterImpl proxy = clusterArray[clusterKey]; ClusterUID clusterUID = proxy.getClusterUID(); - System.err.println("writeOnlyInvalidate " + clusterUID); clusters.freeProxy(proxy); return true; } @@ -812,7 +826,7 @@ public final class ClusterTable implements IClusterTable { System.err.println("value " + cc.getValueIndex()[i] + " changed."); } } - final void refreshImportance(ClusterImpl c) { + final synchronized void refreshImportance(ClusterImpl c) { if (c.isWriteOnly()) return; @@ -886,7 +900,7 @@ public final class ClusterTable implements IClusterTable { } @SuppressWarnings("unchecked") - public final T getClusterByResourceKey(final int resourceKey) { + public synchronized final T getClusterByResourceKey(final int resourceKey) { int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(resourceKey); if (ClusterTraitsBase.isVirtualClusterKey(clusterKey)) throw new RuntimeException("Tried to get a persistent cluster for a virtual resource.");