From: Hannu Niemistö Date: Sat, 17 Nov 2018 06:59:34 +0000 (+0000) Subject: Merge "Utility function for claiming literals" X-Git-Tag: v1.43.0~136^2~264 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=3fe6778c21d6437e90d08987de6dae7bca89bc6d;hp=e03f9cfaaaed5f3d4978fe5c80e7540f90e7bb47 Merge "Utility function for claiming literals" --- diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java index ee97fdb58..d89d71652 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java @@ -927,6 +927,27 @@ public class Layer0Utils { return stm != null && stm.isAsserted(subject); } + /* + * Works around problems in WriteGraph methods with similar signature. + * Especially handles better some cases with existing literals. + * + */ + public static void claimLiteral(WriteGraph graph, Resource r, Resource p, Resource i, Resource t, Object value, Binding binding) throws DatabaseException { + Statement stm = graph.getPossibleStatement(r, p); + if(stm != null && !stm.isAsserted(r)) { + if(graph.isInstanceOf(stm.getObject(), t)) { + // Existing statement is compatible, reuse the literal + graph.claimValue(stm.getObject(), value, binding); + return; + } else { + // Existing statement is incompatible - remove it + graph.deny(stm); + } + } + // Create new statement + graph.claimLiteral(r, p, i, t, value, binding); + } + public static void setExpression(WriteGraph graph, Variable context, String text, Resource expressionValueType) throws DatabaseException { Resource value = context.getRepresents(graph);