]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.acorn/src/org/simantics/acorn/internal/UndoClusterUpdateProcessor.java
Removed contact application support prints
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / internal / UndoClusterUpdateProcessor.java
1 package org.simantics.acorn.internal;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.List;
6
7 import org.simantics.acorn.ClusterManager;
8 import org.simantics.acorn.exception.AcornAccessVerificationException;
9 import org.simantics.acorn.exception.IllegalAcornStateException;
10 import org.simantics.acorn.lru.ClusterChangeSet;
11 import org.simantics.acorn.lru.ClusterStreamChunk;
12 import org.simantics.acorn.lru.ClusterChangeSet.Entry;
13 import org.simantics.acorn.lru.ClusterChangeSet.Type;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.service.ClusterUID;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class UndoClusterUpdateProcessor extends ClusterUpdateProcessorBase {
20
21         private static final Logger LOGGER = LoggerFactory.getLogger(UndoClusterUpdateProcessor.class);
22
23         public final static boolean DEBUG = false;
24
25         final private ClusterChangeSet ccs;
26
27         private int oldValuesIndex = 0;
28         private int statementMaskIndex = 0;
29
30         final public List<Entry> entries = new ArrayList<>();
31         
32         public UndoClusterUpdateProcessor(ClusterManager client, ClusterStreamChunk chunk, ClusterChangeSet ccs) throws DatabaseException {
33                 super(client, readOperation(client, chunk, ccs));
34                 this.ccs = ccs;
35         }
36         
37         private static byte[] readOperation(ClusterManager manager, ClusterStreamChunk chunk, ClusterChangeSet ccs) throws AcornAccessVerificationException, IllegalAcornStateException {
38                 chunk.makeResident();
39                 return chunk.getOperation(ccs.chunkOffset);
40         }
41         
42         @Override
43         void create() throws DatabaseException {
44         }
45
46         @Override
47         void delete(int ri) throws DatabaseException {
48                 
49                 byte[] old = ccs.oldValues.get(oldValuesIndex);
50                 boolean oldValueEx = ccs.oldValueEx.get(oldValuesIndex) > 0;
51                 oldValuesIndex++;
52                 
53                 if(old != null) {
54                         entries.add(new Entry(ri, oldValueEx, old, null));
55                 }
56                 
57         }
58
59         @Override
60         void modify(int resourceKey, long offset, int size, byte[] bytes, int pos)
61                         throws DatabaseException {
62                 
63         }
64
65         @Override
66         void set(int resourceKey, byte[] bytes, int length)
67                         throws DatabaseException {
68
69                 byte[] old = ccs.oldValues.get(oldValuesIndex);
70                 boolean oldValueEx = ccs.oldValueEx.get(oldValuesIndex) > 0;
71                 oldValuesIndex++;
72
73                 entries.add(new Entry(resourceKey, oldValueEx, old, Arrays.copyOf(valueBuffer, length)));
74                 
75         }
76
77         @Override
78         void claim(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
79                         throws DatabaseException {
80                 
81                 boolean add = ccs.statementMask.get(statementMaskIndex++) > 0;
82                 if(add) {
83                         entries.add(new Entry(Type.ADD, resourceKey, puid, predicateKey & 0xFFF, ouid, objectKey & 0xFFF));
84                 }
85                 
86         }
87
88         @Override
89         void deny(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
90                         throws DatabaseException {
91                 
92                 boolean remove = ccs.statementMask.get(statementMaskIndex++) > 0;
93                 if(remove) {
94                         entries.add(new Entry(Type.REMOVE, resourceKey, puid, predicateKey & 0xFFF, ouid, objectKey & 0xFFF));
95                 }
96
97         }
98
99         @Override
100         void setImmutable(boolean value) {
101                 LOGGER.error("Attempted to undo `setImmutable({})` cluster operation for cluster {} which is not supported.", value, ccs.cuid);
102         }
103
104 }