--- /dev/null
+package fi.vtt.simantics.procore.internal;\r
+\r
+import gnu.trove.list.array.TByteArrayList;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteOnlyGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.RuntimeDatabaseException;\r
+import org.simantics.db.impl.ResourceImpl;\r
+import org.simantics.db.impl.graph.WriteGraphImpl;\r
+import org.simantics.db.impl.graph.WriteSupport;\r
+import org.simantics.db.service.ClusterBuilder2;\r
+import org.simantics.db.service.SerialisationSupport;\r
+\r
+public class VirtualClusterBuilderImpl2 implements ClusterBuilder2 {\r
+\r
+ final private SessionImplSocket session;\r
+ final private VirtualGraph vg;\r
+// final private ClusterSupport cs;\r
+ final private SerialisationSupport ss;\r
+// final private ClusterStream stream;\r
+// final private WriteSupport support;\r
+// final private WriteSupport support;\r
+ @SuppressWarnings("unused")\r
+ final private boolean allowImmutables;\r
+ \r
+ VirtualClusterBuilderImpl2(SessionImplSocket session, VirtualGraph vg, boolean allowImmutables) {\r
+ this.session = session;\r
+ this.vg = vg;\r
+ this.allowImmutables = allowImmutables;\r
+ ss = session.getService(SerialisationSupport.class);\r
+ }\r
+ \r
+ private WriteSupport getSupport() {\r
+ WriteGraphImpl graph = session.writeState.getGraph();\r
+ return graph.writeSupport;\r
+ }\r
+\r
+ @Override\r
+ public void newCluster() throws DatabaseException {\r
+ // Do nothing\r
+ }\r
+\r
+ @Override\r
+ public void selectCluster(long cluster) throws DatabaseException {\r
+ // Do nothing\r
+ }\r
+ \r
+ @Override\r
+ public void newCluster(int setHandle) throws DatabaseException {\r
+ // Do nothing\r
+ }\r
+ \r
+ @Override\r
+ public void createClusterSet(int resource) throws DatabaseException {\r
+ // Do nothing\r
+ }\r
+ \r
+ @Override\r
+ public int newResource() throws DatabaseException {\r
+ Resource result = getSupport().createResource(vg); \r
+ return handle(result);\r
+ }\r
+\r
+ @Override\r
+ public int newResource(int set) throws DatabaseException {\r
+ Resource result = getSupport().createResource(vg, resource(set));\r
+ return handle(result);\r
+ }\r
+ \r
+ @Override\r
+ public int resource(Resource res) throws DatabaseException {\r
+ ResourceImpl r = (ResourceImpl)res;\r
+ return r.id;\r
+ }\r
+\r
+ @Override\r
+ public void addStatement(WriteOnlyGraph graph, int subject, int predicate, int object) throws DatabaseException {\r
+ getSupport().claim(vg, subject, predicate, object);\r
+ }\r
+ \r
+// public void applyPredicate(ClusterImpl impl, int predicate) {\r
+// \r
+// int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(predicate);\r
+// ClusterImpl cluster = clusterArray[clusterKey]; \r
+// \r
+// impl.change.addStatementIndex1(predicate, cluster.clusterUID, (byte)0, impl.foreignLookup);\r
+// \r
+// }\r
+//\r
+// public void applyObject(ClusterImpl impl, int object) {\r
+//\r
+// int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(object);\r
+// ClusterImpl cluster = clusterArray[clusterKey]; \r
+// \r
+// impl.change.addStatementIndex2(object, cluster.clusterUID, (byte)0, impl.foreignLookup);\r
+// \r
+// }\r
+\r
+ @Override\r
+ public Resource resource(int key) {\r
+ try {\r
+ return ss.getResource(key);\r
+ } catch (DatabaseException e) {\r
+ throw new RuntimeDatabaseException(e);\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ public int handle(Resource r) {\r
+ return ((ResourceImpl)r).id;\r
+ }\r
+\r
+\r
+ TByteArrayList valueBytes = new TByteArrayList();\r
+ \r
+// byte[] buffer = new byte[65536];\r
+// int bufferOffset = 0;\r
+ int valueSubject = 0;\r
+// int valueOffset = 0;\r
+ \r
+ @Override\r
+ public void beginValue(int subject) {\r
+ valueBytes.clear();\r
+ valueSubject = subject;\r
+ }\r
+ \r
+ @Override\r
+ public void appendValue(int byteValue) throws DatabaseException {\r
+ valueBytes.add((byte)byteValue);\r
+ }\r
+\r
+ @Override\r
+ public void endValue() throws DatabaseException {\r
+ byte[] bytes = valueBytes.toArray();\r
+ getSupport().claimValue(vg, valueSubject, bytes, bytes.length);\r
+ }\r
+ \r
+}\r