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