Make StandardVariableBuilder singleton
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / StandardVariableBuilder.java
1 package org.simantics.db.layer0.variable;
2
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.exception.DatabaseException;
6
7 public class StandardVariableBuilder<Node> implements VariableBuilder<Node> {
8
9     private static StandardVariableBuilder<?> INSTANCE = null;
10
11     private StandardVariableBuilder() {}
12
13     public static synchronized StandardVariableBuilder<?> get() {
14         if(INSTANCE == null) {
15             INSTANCE = new StandardVariableBuilder<>();
16         }
17         return INSTANCE;
18     }
19
20     @Override
21     public Variable buildChild(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource child) {
22         return new StandardGraphChildVariable(parent, node, child);
23     }
24
25     @Override
26     public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource subject, Resource predicate) throws DatabaseException {
27         return new StandardGraphPropertyVariable(graph, parent, node, subject, predicate);
28     }
29
30 }