]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChange2.java
Merge "Save cluster sets only when creating DB snapshots"
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / ClusterChange2.java
index acbb5c73d923b9ea21b5c413482044b1c8db15f5..57bbd44049052c696bc627ea7e7bc816634a3db4 100644 (file)
@@ -1,74 +1,74 @@
-package fi.vtt.simantics.procore.internal;\r
-\r
-import java.util.Arrays;\r
-\r
-import org.simantics.db.procore.cluster.ClusterImpl;\r
-import org.simantics.db.service.Bytes;\r
-import org.simantics.db.service.ClusterUID;\r
-\r
-class ClusterChange2 {\r
-    public static final int VERSION = 2;\r
-    public static final byte SET_IMMUTABLE_OPERATION = 1; // <byte : 0 = false>\r
-    public static final byte UNDO_VALUE_OPERATION = 2; // <int : resource index>\r
-    public static final byte SET_DELETED_OPERATION = 3; // <byte : 0 = false>\r
-    private static final int INCREMENT = 1<<10;\r
-    private boolean dirty = false;\r
-    private byte[] bytes;\r
-    private int byteIndex;\r
-    private ClusterUID clusterUID;\r
-    ClusterChange2(ClusterUID clusterUID, ClusterImpl cluster) {\r
-        this.clusterUID = clusterUID;\r
-        init();\r
-    }\r
-    void init() {\r
-//        System.err.println("clusterChange2 dirty " + cluster.clusterId);\r
-        dirty = false;\r
-        bytes = new byte[INCREMENT];\r
-        byteIndex = 0;\r
-        addInt(0); // Size of byte vector. Set by flush.\r
-        addInt(VERSION);\r
-        byteIndex = clusterUID.toByte(bytes, 8);\r
-    }\r
-    boolean isDirty() {\r
-        return dirty;\r
-    }\r
-    void flush(GraphSession graphSession) {\r
-//        System.err.println("flush2 clusterChange2 " + dirty + this);\r
-        if (!dirty)\r
-            return;\r
-        Bytes.writeLE(bytes, 0, byteIndex - 4);\r
-        byte[] ops = Arrays.copyOf(bytes, byteIndex);\r
-//        System.err.println("flush2 clusterChange2 " + cluster.clusterId + " " + ops.length + " bytes.");\r
-        graphSession.updateCluster(new UpdateClusterFunction(ops));\r
-        init();\r
-    }\r
-    void setImmutable(boolean immutable) {\r
-        dirty = true;\r
-        addByte(SET_IMMUTABLE_OPERATION);\r
-        addByte((byte)(immutable ? -1 : 0));\r
-    }\r
-    void setDeleted(boolean deleted) {\r
-        dirty = true;\r
-        addByte(SET_DELETED_OPERATION);\r
-        addByte((byte)(deleted ? -1 : 0));\r
-    }\r
-    void undoValueEx(int resourceIndex) {\r
-        dirty = true;\r
-        addByte(UNDO_VALUE_OPERATION);\r
-        addInt(resourceIndex);\r
-    }\r
-    private final void checkSpace(int len) {\r
-        if (bytes.length - byteIndex > len)\r
-            return;\r
-       bytes = Arrays.copyOf(bytes, bytes.length + len + INCREMENT);\r
-    }\r
-    private final void addByte(byte value) {\r
-        checkSpace(1);\r
-        bytes[byteIndex++] = value;\r
-    }\r
-    private final void addInt(int value) {\r
-        checkSpace(4);\r
-        Bytes.writeLE(bytes, byteIndex, value);\r
-        byteIndex += 4;\r
-    }\r
-}\r
+package fi.vtt.simantics.procore.internal;
+
+import java.util.Arrays;
+
+import org.simantics.db.procore.cluster.ClusterImpl;
+import org.simantics.db.service.Bytes;
+import org.simantics.db.service.ClusterUID;
+
+class ClusterChange2 {
+    public static final int VERSION = 2;
+    public static final byte SET_IMMUTABLE_OPERATION = 1; // <byte : 0 = false>
+    public static final byte UNDO_VALUE_OPERATION = 2; // <int : resource index>
+    public static final byte SET_DELETED_OPERATION = 3; // <byte : 0 = false>
+    private static final int INCREMENT = 1<<10;
+    private boolean dirty = false;
+    private byte[] bytes;
+    private int byteIndex;
+    private ClusterUID clusterUID;
+    ClusterChange2(ClusterUID clusterUID, ClusterImpl cluster) {
+        this.clusterUID = clusterUID;
+        init();
+    }
+    void init() {
+//        System.err.println("clusterChange2 dirty " + cluster.clusterId);
+        dirty = false;
+        bytes = new byte[INCREMENT];
+        byteIndex = 0;
+        addInt(0); // Size of byte vector. Set by flush.
+        addInt(VERSION);
+        byteIndex = clusterUID.toByte(bytes, 8);
+    }
+    boolean isDirty() {
+        return dirty;
+    }
+    void flush(GraphSession graphSession) {
+//        System.err.println("flush2 clusterChange2 " + dirty + this);
+        if (!dirty)
+            return;
+        Bytes.writeLE(bytes, 0, byteIndex - 4);
+        byte[] ops = Arrays.copyOf(bytes, byteIndex);
+//        System.err.println("flush2 clusterChange2 " + cluster.clusterId + " " + ops.length + " bytes.");
+        graphSession.updateCluster(new UpdateClusterFunction(ops));
+        init();
+    }
+    void setImmutable(boolean immutable) {
+        dirty = true;
+        addByte(SET_IMMUTABLE_OPERATION);
+        addByte((byte)(immutable ? -1 : 0));
+    }
+    void setDeleted(boolean deleted) {
+        dirty = true;
+        addByte(SET_DELETED_OPERATION);
+        addByte((byte)(deleted ? -1 : 0));
+    }
+    void undoValueEx(int resourceIndex) {
+        dirty = true;
+        addByte(UNDO_VALUE_OPERATION);
+        addInt(resourceIndex);
+    }
+    private final void checkSpace(int len) {
+        if (bytes.length - byteIndex > len)
+            return;
+       bytes = Arrays.copyOf(bytes, bytes.length + len + INCREMENT);
+    }
+    private final void addByte(byte value) {
+        checkSpace(1);
+        bytes[byteIndex++] = value;
+    }
+    private final void addInt(int value) {
+        checkSpace(4);
+        Bytes.writeLE(bytes, byteIndex, value);
+        byteIndex += 4;
+    }
+}