1 package org.simantics.acorn.internal;
3 import org.simantics.acorn.ClusterManager;
4 import org.simantics.acorn.cluster.ClusterImpl;
5 import org.simantics.acorn.exception.IllegalAcornStateException;
6 import org.simantics.acorn.lru.ClusterUpdateOperation;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.impl.ClusterSupport;
9 import org.simantics.db.service.ClusterUID;
11 public class ClusterUpdateProcessor extends ClusterUpdateProcessorBase {
13 final ClusterSupport support;
14 final ClusterUpdateOperation info;
15 private ClusterImpl cluster;
17 public ClusterUpdateProcessor(ClusterManager client, ClusterSupport support, byte[] operations, ClusterUpdateOperation info) throws DatabaseException {
18 super(client, operations);
19 this.support = support;
24 void create() throws DatabaseException {
25 cluster.createResource(support);
29 void delete(int ri) throws DatabaseException {
31 boolean oldValueEx = cluster.isValueEx(ri);
32 byte[] old = cluster.getValue(ri, support);
33 if(old != null) cluster.removeValue(ri, support);
34 info.ccs.oldValueEx.add(oldValueEx ? (byte)1 : 0);
35 info.ccs.oldValues.add(old);
40 void modify(int resourceKey, long offset, int size, byte[] bytes, int pos)
41 throws DatabaseException {
43 cluster = (ClusterImpl)cluster.modiValueEx(resourceKey, offset, size, bytes, pos, support);
44 manager.modiFileEx(cluster.getClusterUID(), resourceKey, offset, size, bytes, pos, support);
49 void set(int resourceKey, byte[] bytes, int length)
50 throws DatabaseException {
52 byte[] old = cluster.getValue(resourceKey, support);
53 boolean oldValueEx = cluster.isValueEx(resourceKey);
54 cluster = (ClusterImpl)cluster.setValue(resourceKey, valueBuffer, length, support);
55 info.ccs.oldValueEx.add(oldValueEx ? (byte)1 : 0);
56 info.ccs.oldValues.add(old);
61 void claim(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
62 throws DatabaseException {
64 ClusterImpl c = (ClusterImpl)cluster.addRelation(resourceKey, puid, predicateKey, ouid, objectKey, support);
65 if(c != null) cluster = c;
66 info.ccs.statementMask.add(c != null ? (byte)1 : 0);
71 void deny(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
72 throws DatabaseException {
74 boolean modified = cluster.removeRelation(resourceKey, predicateKey, objectKey, support);
75 info.ccs.statementMask.add(modified ? (byte)1 : 0);
80 void setImmutable(boolean value) {
81 cluster.setImmutable(value, support);
84 public ClusterImpl process(ClusterImpl cluster) throws IllegalAcornStateException {
85 this.cluster = cluster;