From 701fffa16a9aec0e0565da12bd5da5d372f6e612 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Thu, 9 Jan 2020 14:54:45 +0200 Subject: [PATCH] Make StandardVariableBuilder singleton gitlab #441 Change-Id: I28bb5ccb8f5164e3bbe4f0e0c68d4b221cb35d24 --- bundles/org.simantics.db.layer0/adapters.xml | 3 +- .../variable/StandardVariableBuilder.java | 29 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) 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); + } } -- 2.47.1