]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/internal/ClusterUpdateProcessor.java
Sharing org.simantics.acorn for everyone to use
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / internal / ClusterUpdateProcessor.java
diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/ClusterUpdateProcessor.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/ClusterUpdateProcessor.java
new file mode 100644 (file)
index 0000000..0044d72
--- /dev/null
@@ -0,0 +1,86 @@
+package org.simantics.acorn.internal;
+
+import org.simantics.acorn.ClusterManager;
+import org.simantics.acorn.cluster.ClusterImpl;
+import org.simantics.acorn.lru.CachingClusterSupport;
+import org.simantics.acorn.lru.ClusterUpdateOperation;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.ClusterSupport;
+import org.simantics.db.service.ClusterUID;
+
+public class ClusterUpdateProcessor extends ClusterUpdateProcessorBase {
+       
+       final ClusterSupport support;
+       final ClusterUpdateOperation info;
+       private ClusterImpl cluster;
+       
+       public ClusterUpdateProcessor(ClusterManager client, ClusterSupport support, byte[] operations, ClusterUpdateOperation info) throws DatabaseException {
+               super(client, operations);
+               this.support = support;
+               this.info = info;
+       }
+       
+       @Override
+       void create() throws DatabaseException {
+               cluster.createResource(support);
+       }
+
+       @Override
+       void delete(int ri) throws DatabaseException {
+               
+               boolean oldValueEx = cluster.isValueEx(ri);
+               byte[] old = cluster.getValue(ri, support);
+               if(old != null) cluster.removeValue(ri, support);
+               info.ccs.oldValueEx.add(oldValueEx ? (byte)1 : 0);
+               info.ccs.oldValues.add(old);
+               
+       }
+
+       @Override
+       void modify(int resourceKey, long offset, int size, byte[] bytes, int pos)
+                       throws DatabaseException {
+               
+               cluster = (ClusterImpl)cluster.modiValueEx(resourceKey, offset, size, bytes, pos, support);
+               manager.modiFileEx(cluster.getClusterUID(), resourceKey, offset, size, bytes, pos, support);
+               
+       }
+
+       @Override
+       void set(int resourceKey, byte[] bytes, int length)
+                       throws DatabaseException {
+               
+               byte[] old = cluster.getValue(resourceKey, support);
+               boolean oldValueEx = cluster.isValueEx(resourceKey);
+               cluster = (ClusterImpl)cluster.setValue(resourceKey, valueBuffer, length, support);
+               info.ccs.oldValueEx.add(oldValueEx ? (byte)1 : 0);
+               info.ccs.oldValues.add(old);
+               
+       }
+
+       @Override
+       void claim(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
+                       throws DatabaseException {
+               
+               ClusterImpl c = (ClusterImpl)cluster.addRelation(resourceKey, puid, predicateKey, ouid, objectKey, support);
+               if(c != null) cluster = c;
+               info.ccs.statementMask.add(c != null ? (byte)1 : 0);
+               
+       }
+
+       @Override
+       void deny(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
+                       throws DatabaseException {
+               
+               boolean modified = cluster.removeRelation(resourceKey, predicateKey, objectKey, support);
+               info.ccs.statementMask.add(modified ? (byte)1 : 0);
+
+       }
+
+       public ClusterImpl process(ClusterImpl cluster) {
+               this.cluster = cluster;
+               process();
+               info.finish();
+               return this.cluster;
+       }
+       
+}