From: Antti Villberg Date: Tue, 13 Nov 2018 05:59:50 +0000 (+0200) Subject: Variable optimizations for documents (Simupedia) X-Git-Tag: v1.43.0~136^2~275^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=d4be6acae73573577010753ad17c646b33a48e57 Variable optimizations for documents (Simupedia) * Added ProxyVariableSupport - a mechanism to re-parent a Variable gitlab #169 Change-Id: I2852ef1895003a7b1735e1fa2505ac20d6a8ba46 --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariableSupport.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariableSupport.java new file mode 100644 index 000000000..225bef538 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariableSupport.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2018 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.db.layer0.variable; + +import org.simantics.db.ReadGraph; + +/** + * Allows attaching a variable under another one to create custom hierarchies + * from existing variables. + * + * @author Antti Villberg + * @since 1.36.0 + */ +public interface ProxyVariableSupport { + + Variable attachTo(ReadGraph graph, Variable parent); + Variable attachToRenamed(ReadGraph graph, Variable parent, String name); + +} diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java index db552650b..ddfe108cb 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ProxyVariables.java @@ -2,9 +2,29 @@ package org.simantics.db.layer0.variable; import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ProxyVariables { - + + private static final Logger LOGGER = LoggerFactory.getLogger(ProxyVariables.class); + + public static Variable tryToOwn(ReadGraph graph, Variable parent, Variable variable) { + if (variable instanceof ProxyVariableSupport) { + ProxyVariableSupport pvs = (ProxyVariableSupport) variable; + return pvs.attachTo(graph, parent); + } + return null; + } + + public static Variable tryToOwnRenamed(ReadGraph graph, Variable parent, Variable variable, String name) { + if (variable instanceof ProxyVariableSupport) { + ProxyVariableSupport pvs = (ProxyVariableSupport) variable; + return pvs.attachToRenamed(graph, parent, name); + } + return null; + } + public static Variable inputVariable(ReadGraph graph, Variable context) throws DatabaseException { Variable session = graph.syncRequest(new ProxySessionRequest(context)); if(session == null) return null; @@ -52,7 +72,7 @@ public class ProxyVariables { return input; } } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("proxySessionVariable failed", t); return null; } @@ -72,7 +92,7 @@ public class ProxyVariables { } } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("proxyVariableBase failed", t); return null; } @@ -108,7 +128,7 @@ public class ProxyVariables { } } catch (Throwable t) { - t.printStackTrace(); + LOGGER.error("proxyVariableRoot failed", t); return null; } @@ -118,5 +138,4 @@ public class ProxyVariables { return proxyVariableRoot(graph, variable) != null; } - } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java index b784754bf..bd0184e86 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java @@ -12,7 +12,6 @@ import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.exception.AssumptionException; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.VariableException; import org.simantics.db.layer0.exception.InvalidVariableException; import org.simantics.db.layer0.function.All; import org.simantics.db.layer0.request.ClassificationsRequest; @@ -24,7 +23,7 @@ import org.simantics.db.layer0.variable.Variables.Role; import org.simantics.layer0.Layer0; import org.simantics.simulator.variable.exceptions.NodeManagerException; -public class StandardGraphChildVariable extends AbstractChildVariable { +public class StandardGraphChildVariable extends AbstractChildVariable implements ProxyVariableSupport { /* * Extension points @@ -335,5 +334,20 @@ public class StandardGraphChildVariable extends AbstractChildVariable { public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException { return null; } - + + @Override + public Variable attachTo(ReadGraph graph, Variable parent) { + return new StandardGraphChildVariable(parent, node, resource); + } + + @Override + public Variable attachToRenamed(ReadGraph graph, Variable parent, String name) { + return new StandardGraphChildVariable(parent, node, resource) { + @Override + public String getName(ReadGraph graph) throws DatabaseException { + return name; + } + }; + } + }