X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.procore%2Fsrc%2Ffi%2Fvtt%2Fsimantics%2Fprocore%2Finternal%2FClusterChange2.java;h=57bbd44049052c696bc627ea7e7bc816634a3db4;hp=acbb5c73d923b9ea21b5c413482044b1c8db15f5;hb=d09be9d2b8bf2e982ab7cf5760d39014e7ca4fa1;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChange2.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChange2.java index acbb5c73d..57bbd4404 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChange2.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/ClusterChange2.java @@ -1,74 +1,74 @@ -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; // - public static final byte UNDO_VALUE_OPERATION = 2; // - public static final byte SET_DELETED_OPERATION = 3; // - 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; - } -} +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; // + public static final byte UNDO_VALUE_OPERATION = 2; // + public static final byte SET_DELETED_OPERATION = 3; // + 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; + } +}