]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGTransferableGraphSource.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / TGTransferableGraphSource.java
1 package org.simantics.db.layer0.util;
2
3 import java.io.IOException;
4 import java.util.TreeMap;
5
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;
18
19 public class TGTransferableGraphSource implements TransferableGraphSource {
20
21         final private TransferableGraph1 tg;
22         
23         public TGTransferableGraphSource(TransferableGraph1 tg) {
24                 this.tg = tg;
25         }
26
27         @Override
28         public DataContainer getHeader() throws Exception {
29             return null;
30         }
31         
32         @Override
33         public int getResourceCount() {
34                 return tg.resourceCount;
35         }
36         
37         @Override
38         public int getIdentityCount() {
39                 return tg.identities.length;
40         }
41         
42         @Override
43         public int getStatementCount() {
44                 return tg.statements.length;
45         }
46         
47         @Override
48         public int getValueCount() {
49                 return tg.values.length;
50         }
51
52         @Override
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);
61                 }
62         }
63
64         @Override
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]);
68                 }
69         }
70
71         @Override
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]);
75                 }
76         }
77
78     @Override
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))));
86         }
87     }
88         
89         @Override
90         public TreeMap<String, Variant> getExtensions() {
91                 return tg.extensions;
92         }
93     
94     @Override
95     public void reset() {
96     }
97
98     @Override
99     public void close() {
100     }
101
102 }