1 package fi.vtt.simantics.procore.internal;
\r
3 import org.simantics.db.ExternalValueSupport;
\r
4 import org.simantics.db.ReadGraph;
\r
5 import org.simantics.db.Resource;
\r
6 import org.simantics.db.WriteGraph;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.db.impl.ClusterI;
\r
9 import org.simantics.db.impl.ClusterTranslator;
\r
10 import org.simantics.db.impl.ResourceImpl;
\r
12 import fi.vtt.simantics.procore.DebugPolicy;
\r
14 public class ExternalValueSupportImpl implements ExternalValueSupport {
\r
15 private final boolean DEBUG = DebugPolicy.REPORT_CLUSTER_EVENTS;
\r
16 private final SessionImplSocket session;
\r
17 private ClusterTranslator clusterTranslator;
\r
18 private final ClusterTable clusterTable;
\r
19 ExternalValueSupportImpl(SessionImplSocket session) {
\r
20 this.session = session;
\r
21 this.clusterTranslator = session.clusterTranslator;
\r
22 this.clusterTable = session.getClusterTable();
\r
24 private final void check4Translator() {
\r
25 if (null == clusterTranslator)
\r
26 this.clusterTranslator = session.clusterTranslator;
\r
29 public void writeValue(WriteGraph graph, Resource resource, long offset, int length, byte[] bytes)
\r
30 throws DatabaseException {
\r
32 assert(length <= bytes.length);
\r
33 ResourceImpl resourceImpl = (ResourceImpl)resource;
\r
34 ClusterI cluster = clusterTable.getClusterByResourceKey(resourceImpl.id);
\r
35 cluster.modiValueEx(resourceImpl.id, offset, length, bytes, 0, clusterTranslator);
\r
37 // This breaks undo.
\r
39 // public void moveValue(WriteGraph graph, Resource resource)
\r
40 // throws DatabaseException {
\r
41 // this.writeValue(graph, resource, (1L<<58)-1, 0, new byte[0]);
\r
43 // This breaks undo.
\r
45 // public void commitAndContinue(WriteGraph graph, WriteTraits wtraits, Resource resource)
\r
46 // throws DatabaseException {
\r
47 // XSupport xs = graph.getService(XSupport.class);
\r
48 // xs.commitAndContinue(graph, wtraits);
\r
49 // clusterTranslator.wait4RequestsLess(1);
\r
52 public byte[] readValue(ReadGraph graph, Resource resource, long offset, int length)
\r
53 throws DatabaseException {
\r
55 ResourceImpl resourceImpl = (ResourceImpl)resource;
\r
56 ClusterI cluster = clusterTable.getClusterByResourceKey(resourceImpl.id);
\r
57 return cluster.readValueEx(resourceImpl.id, offset, length, clusterTranslator);
\r
59 public long getValueSize(ReadGraph graph, Resource resource)
\r
60 throws DatabaseException {
\r
62 ResourceImpl resourceImpl = (ResourceImpl)resource;
\r
63 ClusterI cluster = clusterTable.getClusterByResourceKey(resourceImpl.id);
\r
64 long size = cluster.getValueSizeEx(resourceImpl.id, clusterTranslator);
\r
66 System.out.println("DEBUG: resource=" + resource + " value length=" + size + ".");
\r
70 public void removeValue(WriteGraph graph, Resource resource)
\r
71 throws DatabaseException {
\r
73 ResourceImpl resourceImpl = (ResourceImpl)resource;
\r
74 ClusterI cluster = clusterTable.getClusterByResourceKey(resourceImpl.id);
\r
75 cluster.modiValueEx(resourceImpl.id, 0, 0, new byte[0], 0, clusterTranslator);
\r
76 cluster.removeValue(resourceImpl.id, clusterTranslator);
\r
79 public int wait4RequestsLess(int limit)
\r
80 throws DatabaseException {
\r
82 return clusterTranslator.wait4RequestsLess(limit);
\r