1 package fi.vtt.simantics.procore.internal;
3 import gnu.trove.list.array.TByteArrayList;
5 import org.simantics.db.Resource;
6 import org.simantics.db.VirtualGraph;
7 import org.simantics.db.WriteOnlyGraph;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.exception.RuntimeDatabaseException;
10 import org.simantics.db.impl.ResourceImpl;
11 import org.simantics.db.impl.graph.WriteGraphImpl;
12 import org.simantics.db.impl.graph.WriteSupport;
13 import org.simantics.db.service.ClusterBuilder2;
14 import org.simantics.db.service.SerialisationSupport;
16 public class VirtualClusterBuilderImpl2 implements ClusterBuilder2 {
18 final private SessionImplSocket session;
19 final private VirtualGraph vg;
20 // final private ClusterSupport cs;
21 final private SerialisationSupport ss;
22 // final private ClusterStream stream;
23 // final private WriteSupport support;
24 // final private WriteSupport support;
25 @SuppressWarnings("unused")
26 final private boolean allowImmutables;
28 VirtualClusterBuilderImpl2(SessionImplSocket session, VirtualGraph vg, boolean allowImmutables) {
29 this.session = session;
31 this.allowImmutables = allowImmutables;
32 ss = session.getService(SerialisationSupport.class);
35 private WriteSupport getSupport() {
36 WriteGraphImpl graph = session.writeState.getGraph();
37 return graph.writeSupport;
41 public void newCluster() throws DatabaseException {
46 public void selectCluster(long cluster) throws DatabaseException {
51 public void newCluster(int setHandle) throws DatabaseException {
56 public void createClusterSet(int resource) throws DatabaseException {
61 public int newResource() throws DatabaseException {
62 Resource result = getSupport().createResource(vg);
63 return handle(result);
67 public int newResource(int set) throws DatabaseException {
68 Resource result = getSupport().createResource(vg, resource(set));
69 return handle(result);
73 public int resource(Resource res) throws DatabaseException {
74 ResourceImpl r = (ResourceImpl)res;
79 public void addStatement(WriteOnlyGraph graph, int subject, int predicate, int object) throws DatabaseException {
80 getSupport().claim(vg, subject, predicate, object);
83 // public void applyPredicate(ClusterImpl impl, int predicate) {
85 // int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(predicate);
86 // ClusterImpl cluster = clusterArray[clusterKey];
88 // impl.change.addStatementIndex1(predicate, cluster.clusterUID, (byte)0, impl.foreignLookup);
92 // public void applyObject(ClusterImpl impl, int object) {
94 // int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(object);
95 // ClusterImpl cluster = clusterArray[clusterKey];
97 // impl.change.addStatementIndex2(object, cluster.clusterUID, (byte)0, impl.foreignLookup);
102 public Resource resource(int key) {
104 return ss.getResource(key);
105 } catch (DatabaseException e) {
106 throw new RuntimeDatabaseException(e);
111 public int handle(Resource r) {
112 return ((ResourceImpl)r).id;
116 TByteArrayList valueBytes = new TByteArrayList();
118 // byte[] buffer = new byte[65536];
119 // int bufferOffset = 0;
120 int valueSubject = 0;
121 // int valueOffset = 0;
124 public void beginValue(int subject) {
126 valueSubject = subject;
130 public void appendValue(int byteValue) throws DatabaseException {
131 valueBytes.add((byte)byteValue);
135 public void endValue() throws DatabaseException {
136 byte[] bytes = valueBytes.toArray();
137 getSupport().claimValue(vg, valueSubject, bytes, bytes.length);