]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/NodeManagerVariableBuilder.java
Index query fixes after commit 4e7fd7de
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / NodeManagerVariableBuilder.java
1 package org.simantics.db.layer0.variable;
2
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.layer0.Layer0;
8
9 abstract public class NodeManagerVariableBuilder implements VariableBuilder {
10
11     @Override
12     public Variable buildChild(ReadGraph graph, Variable parent, VariableNode node, Resource child) throws DatabaseException {
13         Layer0 L0 = Layer0.getInstance(graph);
14         String childName = graph.getRelatedValue(child, L0.HasName, Bindings.STRING);
15         String sessionName = parent.getURI(graph) + "/" + childName;
16         return createChild(graph, parent, sessionName, child);
17     }
18     
19     protected Variable createChild(ReadGraph graph, Variable parent, String sessionName, Resource child) throws DatabaseException {
20         NodeSupport<?> support = getNodeSupport(graph, sessionName);
21         return new StandardGraphChildVariable(parent, new VariableNode(support, getRoot(graph, support, sessionName)), child);
22     }
23
24     @Override
25     public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode node, Resource subject, Resource predicate) throws DatabaseException {
26         throw new UnsupportedOperationException();
27     }
28     
29     protected abstract NodeSupport<?> getNodeSupport(ReadGraph graph, String sessionName) throws DatabaseException;
30     protected abstract Object getRoot(ReadGraph graph, NodeSupport<?> support, String sessionName) throws DatabaseException;
31
32 }