]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.acorn/src/org/simantics/acorn/internal/ClusterUpdateProcessor.java
Merge commit 'bf75fd9'
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / internal / ClusterUpdateProcessor.java
1 package org.simantics.acorn.internal;
2
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;
10
11 public class ClusterUpdateProcessor extends ClusterUpdateProcessorBase {
12         
13         final ClusterSupport support;
14         final ClusterUpdateOperation info;
15         private ClusterImpl cluster;
16         
17         public ClusterUpdateProcessor(ClusterManager client, ClusterSupport support, byte[] operations, ClusterUpdateOperation info) throws DatabaseException {
18                 super(client, operations);
19                 this.support = support;
20                 this.info = info;
21         }
22         
23         @Override
24         void create() throws DatabaseException {
25                 cluster.createResource(support);
26         }
27
28         @Override
29         void delete(int ri) throws DatabaseException {
30                 
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);
36                 
37         }
38
39         @Override
40         void modify(int resourceKey, long offset, int size, byte[] bytes, int pos)
41                         throws DatabaseException {
42                 
43                 cluster = (ClusterImpl)cluster.modiValueEx(resourceKey, offset, size, bytes, pos, support);
44                 manager.modiFileEx(cluster.getClusterUID(), resourceKey, offset, size, bytes, pos, support);
45                 
46         }
47
48         @Override
49         void set(int resourceKey, byte[] bytes, int length)
50                         throws DatabaseException {
51                 
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);
57                 
58         }
59
60         @Override
61         void claim(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
62                         throws DatabaseException {
63                 
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);
67                 
68         }
69
70         @Override
71         void deny(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
72                         throws DatabaseException {
73                 
74                 boolean modified = cluster.removeRelation(resourceKey, predicateKey, objectKey, support);
75                 info.ccs.statementMask.add(modified ? (byte)1 : 0);
76
77         }
78
79         public ClusterImpl process(ClusterImpl cluster) throws IllegalAcornStateException {
80                 this.cluster = cluster;
81                 process();
82                 info.finish();
83                 return this.cluster;
84         }
85         
86 }