From: Antti Villberg Date: Thu, 9 Jan 2020 12:54:45 +0000 (+0200) Subject: Make StandardVariableBuilder singleton X-Git-Tag: v1.43.0~136^2~8 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=701fffa16a9aec0e0565da12bd5da5d372f6e612;p=simantics%2Fplatform.git Make StandardVariableBuilder singleton gitlab #441 Change-Id: I28bb5ccb8f5164e3bbe4f0e0c68d4b221cb35d24 --- diff --git a/bundles/org.simantics.db.layer0/adapters.xml b/bundles/org.simantics.db.layer0/adapters.xml index 11a3ff235..bdf1f1435 100644 --- a/bundles/org.simantics.db.layer0/adapters.xml +++ b/bundles/org.simantics.db.layer0/adapters.xml @@ -35,7 +35,8 @@ + class="org.simantics.db.layer0.variable.StandardVariableBuilder" + constructor="get" > diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardVariableBuilder.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardVariableBuilder.java index b1af87f98..992e3e699 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardVariableBuilder.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardVariableBuilder.java @@ -6,14 +6,25 @@ import org.simantics.db.exception.DatabaseException; public class StandardVariableBuilder implements VariableBuilder { - @Override - public Variable buildChild(ReadGraph graph, Variable parent, VariableNode node, Resource child) { - return new StandardGraphChildVariable(parent, node, child); - } - - @Override - public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode 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, Resource child) { + return new StandardGraphChildVariable(parent, node, child); + } + + @Override + public Variable buildProperty(ReadGraph graph, Variable parent, VariableNode node, Resource subject, Resource predicate) throws DatabaseException { + return new StandardGraphPropertyVariable(graph, parent, node, subject, predicate); + } }