]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Make StandardVariableBuilder singleton 68/3768/1
authorAntti Villberg <antti.villberg@semantum.fi>
Thu, 9 Jan 2020 12:54:45 +0000 (14:54 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Thu, 9 Jan 2020 12:54:45 +0000 (14:54 +0200)
gitlab #441

Change-Id: I28bb5ccb8f5164e3bbe4f0e0c68d4b221cb35d24

bundles/org.simantics.db.layer0/adapters.xml
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardVariableBuilder.java

index 11a3ff235c889257472f54e7d60e3af240b13f9f..bdf1f143574e9cf62caeec571ec9a12607f461ce 100644 (file)
@@ -35,7 +35,8 @@
 
        <target interface="org.simantics.db.layer0.variable.VariableBuilder">
                <type uri="http://www.simantics.org/Layer0-0.0/Entity"
-                       class="org.simantics.db.layer0.variable.StandardVariableBuilder" >
+                       class="org.simantics.db.layer0.variable.StandardVariableBuilder"
+                       constructor="get" >
                </type>
        </target>
 
index b1af87f98490016490d0891087da8e5679946d47..992e3e6990fba165c0fd6c6ca901a479b4521730 100644 (file)
@@ -6,14 +6,25 @@ import org.simantics.db.exception.DatabaseException;
 
 public class StandardVariableBuilder<Node> implements VariableBuilder<Node> {
 
-       @Override
-       public Variable buildChild(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource child) {
-               return new StandardGraphChildVariable(parent, node, child);
-       }
-
-       @Override
-       public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource subject, Resource predicate) throws DatabaseException {
-               return new StandardGraphPropertyVariable(graph, parent, node, subject, predicate);
-       }
+    private static StandardVariableBuilder<?> INSTANCE = null;
+
+    private StandardVariableBuilder() {}
+
+    public static synchronized StandardVariableBuilder<?> get() {
+        if(INSTANCE == null) {
+            INSTANCE = new StandardVariableBuilder<>();
+        }
+        return INSTANCE;
+    }
+
+    @Override
+    public Variable buildChild(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource child) {
+        return new StandardGraphChildVariable(parent, node, child);
+    }
+
+    @Override
+    public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode<Node> node, Resource subject, Resource predicate) throws DatabaseException {
+        return new StandardGraphPropertyVariable(graph, parent, node, subject, predicate);
+    }
 
 }