1 package org.simantics.db.layer0.util;
3 import java.io.IOException;
4 import java.util.TreeMap;
6 import org.simantics.databoard.Bindings;
7 import org.simantics.databoard.binding.Binding;
8 import org.simantics.databoard.binding.mutable.Variant;
9 import org.simantics.databoard.container.DataContainer;
10 import org.simantics.databoard.serialization.Serializer;
11 import org.simantics.databoard.type.Datatype;
12 import org.simantics.databoard.util.binary.ByteBufferReadable;
13 import org.simantics.db.ReadGraph;
14 import org.simantics.graph.db.TransferableGraphSource;
15 import org.simantics.graph.representation.Identity;
16 import org.simantics.graph.representation.TransferableGraph1;
17 import org.simantics.graph.representation.Value;
19 public class TGTransferableGraphSource implements TransferableGraphSource {
21 final private TransferableGraph1 tg;
23 public TGTransferableGraphSource(TransferableGraph1 tg) {
28 public DataContainer getHeader() throws Exception {
33 public int getResourceCount() {
34 return tg.resourceCount;
38 public int getIdentityCount() {
39 return tg.identities.length;
43 public int getStatementCount() {
44 return tg.statements.length;
48 public int getValueCount() {
49 return tg.values.length;
53 public void forStatements(ReadGraph graph, TransferableGraphSourceProcedure<int[]> procedure) throws Exception {
54 int[] value = new int[4];
55 for(int i=0;i<tg.statements.length;i+=4) {
56 value[0] = tg.statements[i];
57 value[1] = tg.statements[i+1];
58 value[2] = tg.statements[i+2];
59 value[3] = tg.statements[i+3];
60 procedure.execute(value);
65 public void forIdentities(ReadGraph graph, TransferableGraphSourceProcedure<Identity> procedure) throws Exception {
66 for(int i=0;i<tg.identities.length;i++) {
67 procedure.execute(tg.identities[i]);
72 public void forValues(ReadGraph graph, TransferableGraphSourceProcedure<Value> procedure) throws Exception {
73 for(int i=0;i<tg.values.length;i++) {
74 procedure.execute(tg.values[i]);
79 public void forValues2(ReadGraph graph, TransferableGraphSourceValueProcedure procedure) throws Exception {
80 for(int i=0;i<tg.values.length;i++) {
81 Value value = tg.values[i];
82 Binding binding = value.value.getBinding();
83 Datatype dt = binding.type();
84 Serializer s = Bindings.getSerializer(binding);
85 procedure.execute(value.resource, dt, new ByteBufferReadable(s.serialize(value.value.getValue(binding))));
90 public TreeMap<String, Variant> getExtensions() {