1 package org.simantics.acorn.internal;
3 import java.util.ArrayList;
4 import java.util.Arrays;
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;
17 public class UndoClusterUpdateProcessor extends ClusterUpdateProcessorBase {
19 public final static boolean DEBUG = false;
21 final private ClusterChangeSet ccs;
23 private int oldValuesIndex = 0;
24 private int statementMaskIndex = 0;
26 final public List<Entry> entries = new ArrayList<Entry>();
28 public UndoClusterUpdateProcessor(ClusterManager client, ClusterStreamChunk chunk, ClusterChangeSet ccs) throws DatabaseException {
29 super(client, readOperation(client, chunk, ccs));
33 private static byte[] readOperation(ClusterManager manager, ClusterStreamChunk chunk, ClusterChangeSet ccs) throws AcornAccessVerificationException, IllegalAcornStateException {
35 // ClusterStreamChunk chunk;
36 // manager.streamLRU.acquireMutex();
38 // chunk = ccs.getChunk(manager);
39 // } catch (Throwable t) {
40 // throw new IllegalStateException(t);
42 // manager.streamLRU.releaseMutex();
45 // chunk.acquireMutex();
49 return chunk.getOperation(ccs.chunkOffset);
50 // } catch (Throwable t) {
51 // throw new IllegalStateException(t);
53 // chunk.releaseMutex();
58 void create() throws DatabaseException {
62 void delete(int ri) throws DatabaseException {
64 byte[] old = ccs.oldValues.get(oldValuesIndex);
65 boolean oldValueEx = ccs.oldValueEx.get(oldValuesIndex) > 0;
69 entries.add(new Entry(ri, oldValueEx, old, null));
75 void modify(int resourceKey, long offset, int size, byte[] bytes, int pos)
76 throws DatabaseException {
81 void set(int resourceKey, byte[] bytes, int length)
82 throws DatabaseException {
84 byte[] old = ccs.oldValues.get(oldValuesIndex);
85 boolean oldValueEx = ccs.oldValueEx.get(oldValuesIndex) > 0;
88 entries.add(new Entry(resourceKey, oldValueEx, old, Arrays.copyOf(valueBuffer, length)));
93 void claim(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
94 throws DatabaseException {
96 boolean add = ccs.statementMask.get(statementMaskIndex++) > 0;
98 entries.add(new Entry(Type.ADD, resourceKey, puid, predicateKey & 0xFFF, ouid, objectKey & 0xFFF));
104 void deny(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
105 throws DatabaseException {
107 boolean remove = ccs.statementMask.get(statementMaskIndex++) > 0;
109 entries.add(new Entry(Type.REMOVE, resourceKey, puid, predicateKey & 0xFFF, ouid, objectKey & 0xFFF));