]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/VirtualClusterBuilderImpl2.java
Merge commit '7684bae'
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / VirtualClusterBuilderImpl2.java
1 package fi.vtt.simantics.procore.internal;\r
2 \r
3 import gnu.trove.list.array.TByteArrayList;\r
4 \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
15 \r
16 public class VirtualClusterBuilderImpl2 implements ClusterBuilder2 {\r
17 \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
27     \r
28     VirtualClusterBuilderImpl2(SessionImplSocket session, VirtualGraph vg, boolean allowImmutables) {\r
29         this.session = session;\r
30         this.vg = vg;\r
31         this.allowImmutables = allowImmutables;\r
32         ss = session.getService(SerialisationSupport.class);\r
33     }\r
34     \r
35     private WriteSupport getSupport() {\r
36         WriteGraphImpl graph = session.writeState.getGraph();\r
37         return graph.writeSupport;\r
38     }\r
39 \r
40     @Override\r
41     public void newCluster() throws DatabaseException {\r
42         // Do nothing\r
43     }\r
44 \r
45     @Override\r
46     public void selectCluster(long cluster) throws DatabaseException {\r
47         // Do nothing\r
48     }\r
49     \r
50     @Override\r
51     public void newCluster(int setHandle) throws DatabaseException {\r
52         // Do nothing\r
53     }\r
54     \r
55     @Override\r
56     public void createClusterSet(int resource) throws DatabaseException {\r
57         // Do nothing\r
58     }\r
59     \r
60     @Override\r
61     public int newResource() throws DatabaseException {\r
62         Resource result = getSupport().createResource(vg); \r
63         return handle(result);\r
64     }\r
65 \r
66     @Override\r
67     public int newResource(int set) throws DatabaseException {\r
68         Resource result = getSupport().createResource(vg, resource(set));\r
69         return handle(result);\r
70     }\r
71     \r
72     @Override\r
73     public int resource(Resource res) throws DatabaseException {\r
74         ResourceImpl r = (ResourceImpl)res;\r
75         return r.id;\r
76     }\r
77 \r
78     @Override\r
79     public void addStatement(WriteOnlyGraph graph, int subject, int predicate, int object) throws DatabaseException {\r
80         getSupport().claim(vg, subject, predicate, object);\r
81     }\r
82     \r
83 //    public void applyPredicate(ClusterImpl impl, int predicate) {\r
84 //        \r
85 //        int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(predicate);\r
86 //        ClusterImpl cluster = clusterArray[clusterKey]; \r
87 //        \r
88 //        impl.change.addStatementIndex1(predicate, cluster.clusterUID, (byte)0, impl.foreignLookup);\r
89 //        \r
90 //    }\r
91 //\r
92 //    public void applyObject(ClusterImpl impl, int object) {\r
93 //\r
94 //        int clusterKey = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(object);\r
95 //        ClusterImpl cluster = clusterArray[clusterKey]; \r
96 //        \r
97 //        impl.change.addStatementIndex2(object, cluster.clusterUID, (byte)0, impl.foreignLookup);\r
98 //        \r
99 //    }\r
100 \r
101     @Override\r
102     public Resource resource(int key) {\r
103         try {\r
104             return ss.getResource(key);\r
105         } catch (DatabaseException e) {\r
106             throw new RuntimeDatabaseException(e);\r
107         }\r
108     }\r
109     \r
110     @Override\r
111     public int handle(Resource r) {\r
112         return ((ResourceImpl)r).id;\r
113     }\r
114 \r
115 \r
116     TByteArrayList valueBytes = new TByteArrayList();\r
117     \r
118 //    byte[] buffer = new byte[65536];\r
119 //    int bufferOffset = 0;\r
120     int valueSubject = 0;\r
121 //    int valueOffset = 0;\r
122     \r
123     @Override\r
124     public void beginValue(int subject) {\r
125         valueBytes.clear();\r
126         valueSubject = subject;\r
127     }\r
128         \r
129     @Override\r
130     public void appendValue(int byteValue) throws DatabaseException {\r
131         valueBytes.add((byte)byteValue);\r
132     }\r
133 \r
134     @Override\r
135     public void endValue() throws DatabaseException {\r
136         byte[] bytes = valueBytes.toArray();\r
137         getSupport().claimValue(vg, valueSubject, bytes, bytes.length);\r
138     }\r
139     \r
140 }\r