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.lru.ClusterChangeSet;
9 import org.simantics.acorn.lru.ClusterStreamChunk;
10 import org.simantics.acorn.lru.ClusterChangeSet.Entry;
11 import org.simantics.acorn.lru.ClusterChangeSet.Type;
12 import org.simantics.db.exception.DatabaseException;
13 import org.simantics.db.service.ClusterUID;
15 public class UndoClusterUpdateProcessor extends ClusterUpdateProcessorBase {
17 public final static boolean DEBUG = false;
19 final private ClusterChangeSet ccs;
21 private int oldValuesIndex = 0;
22 private int statementMaskIndex = 0;
24 final public List<Entry> entries = new ArrayList<Entry>();
26 public UndoClusterUpdateProcessor(ClusterManager client, ClusterStreamChunk chunk, ClusterChangeSet ccs) throws DatabaseException {
27 super(client, readOperation(client, chunk, ccs));
31 private static byte[] readOperation(ClusterManager manager, ClusterStreamChunk chunk, ClusterChangeSet ccs) {
33 // ClusterStreamChunk chunk;
34 // manager.streamLRU.acquireMutex();
36 // chunk = ccs.getChunk(manager);
37 // } catch (Throwable t) {
38 // throw new IllegalStateException(t);
40 // manager.streamLRU.releaseMutex();
43 // chunk.acquireMutex();
47 return chunk.getOperation(ccs.chunkOffset);
48 // } catch (Throwable t) {
49 // throw new IllegalStateException(t);
51 // chunk.releaseMutex();
56 void create() throws DatabaseException {
60 void delete(int ri) throws DatabaseException {
62 byte[] old = ccs.oldValues.get(oldValuesIndex);
63 boolean oldValueEx = ccs.oldValueEx.get(oldValuesIndex) > 0;
67 entries.add(new Entry(ri, oldValueEx, old, null));
73 void modify(int resourceKey, long offset, int size, byte[] bytes, int pos)
74 throws DatabaseException {
79 void set(int resourceKey, byte[] bytes, int length)
80 throws DatabaseException {
82 byte[] old = ccs.oldValues.get(oldValuesIndex);
83 boolean oldValueEx = ccs.oldValueEx.get(oldValuesIndex) > 0;
86 entries.add(new Entry(resourceKey, oldValueEx, old, Arrays.copyOf(valueBuffer, length)));
91 void claim(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
92 throws DatabaseException {
94 boolean add = ccs.statementMask.get(statementMaskIndex++) > 0;
96 entries.add(new Entry(Type.ADD, resourceKey, puid, predicateKey & 0xFFF, ouid, objectKey & 0xFFF));
102 void deny(int resourceKey, int predicateKey, int objectKey, ClusterUID puid, ClusterUID ouid)
103 throws DatabaseException {
105 boolean remove = ccs.statementMask.get(statementMaskIndex++) > 0;
107 entries.add(new Entry(Type.REMOVE, resourceKey, puid, predicateKey & 0xFFF, ouid, objectKey & 0xFFF));