]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChange.java
Truncate big value cluster file if its size decreases
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / ClusterChange.java
index 1a264dc515d5329d22ec1f285f1043cf08771d1a..0b17631341b275059d1241ff3ac28413575527b4 100644 (file)
@@ -54,7 +54,9 @@ public final class ClusterChange {
     public ClusterImpl clusterImpl;
 
     public ClusterChange(ClusterStream clusterStream, ClusterImpl clusterImpl) {
+       
         this.clusterImpl = clusterImpl;
+
         clusterUID = clusterImpl.getClusterUID();
         long[] longs = new long[ClusterUID.getLongLength()];
         clusterUID.toLong(longs, 0);
@@ -69,9 +71,13 @@ public final class ClusterChange {
             Bytes.writeLE(header, offset, longs[i]);
         //initBuffer();
         this.clusterStream = clusterStream;
-        this.clusterChange2 = new ClusterChange2(clusterUID, clusterImpl);
+        this.clusterChange2 = new ClusterChange2(clusterUID);
         clusterStream.changes.add(this);
     }
+    
+    public void adopt(ClusterImpl impl) {
+        this.clusterImpl = impl;
+    }
 
     private void setHeaderVectorSize(int size) {
         if (size < 0)
@@ -81,7 +87,7 @@ public final class ClusterChange {
     }
     @Override
     public String toString() {
-        return super.toString() + " cluster=" + clusterImpl.getClusterUID() + " id=" + clusterImpl.getClusterId() + " off=" + byteIndex;
+        return super.toString() + " cluster=" + clusterUID + " id=" + clusterImpl.getClusterId() + " off=" + byteIndex;
     }
     private final void initBuffer() {
         flushed = false;
@@ -195,8 +201,8 @@ public final class ClusterChange {
         }
         if (0 != foreign) {
             if (foreign > 256)
-                throw new RuntimeDatabaseException("Internal error, contact application support." +
-                "Too big foreing index=" + foreign + " max=256");
+                throw new RuntimeDatabaseException("Internal error." +
+                "Too big foreign index=" + foreign + " max=256");
             --foreign;
             bytes[byteIndex++] = foreign;
             return ClusterEnum.ForeignShort;
@@ -208,8 +214,8 @@ public final class ClusterChange {
             if (DEBUG_STAT)
                 info.sForeign = foreignTable.size();
             if (clusterUID.equals(ClusterUID.Null))
-                throw new RuntimeDatabaseException("Internal error, contact application support." +
-                "Cluster unique id not defined for foreing cluster.");
+                throw new RuntimeDatabaseException("Internal error." +
+                "Cluster unique id not defined for foreign cluster.");
             addForeignLong(resourceIndex, clusterUID);
             return ClusterEnum.ForeignLong;
         }
@@ -487,6 +493,8 @@ public final class ClusterChange {
             left -= written;
             checkBufferSpace(12);
         }
+        // Possibly truncate file
+        modiValue(ri, length_, new byte[0], 0, 0);
         return sum;
     }