X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FSCLValueAccessor.java;h=5d4915d94035d204ba0c966dd949ebfc0d55256f;hb=refs%2Fchanges%2F38%2F238%2F2;hp=82dcec1c63485c4dc38565a5f886dd2f8dc2861e;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java index 82dcec1c6..5d4915d94 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java @@ -1,96 +1,96 @@ -package org.simantics.db.layer0.variable; - -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.type.Datatype; -import org.simantics.db.ReadGraph; -import org.simantics.db.WriteGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.scl.runtime.SCLContext; -import org.simantics.scl.runtime.function.Function1; -import org.simantics.scl.runtime.function.Function2; -import org.simantics.scl.runtime.function.Function3; - -public class SCLValueAccessor implements ValueAccessor { - - private final Function1 getValue1; - private final Function2 getValue2; - private final Function2 setValue2; - private final Function3 setValue3; - private final Function1 getDatatype; - - public SCLValueAccessor(Function1 getValue1, Function2 getValue2, - Function2 setValue2, Function3 setValue3, - Function1 getDatatype) { - this.getValue1 = getValue1; - this.getValue2 = getValue2; - this.setValue2 = setValue2; - this.setValue3 = setValue3; - this.getDatatype = getDatatype; - } - - @Override - public Object getValue(ReadGraph graph, Variable context) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.put("graph", graph); - try { - return getValue1.apply(context); - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - } - - @Override - public Object getValue(ReadGraph graph, Variable context, Binding binding) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.put("graph", graph); - try { - return getValue2.apply(context, binding); - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - } - - @Override - public void setValue(WriteGraph graph, Variable context, Object value) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.put("graph", graph); - try { - setValue2.apply(context, value); - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - } - - @Override - public void setValue(WriteGraph graph, Variable context, Object value, Binding binding) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.put("graph", graph); - try { - setValue3.apply(context, value, binding); - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - } - - @Override - public Datatype getDatatype(ReadGraph graph, Variable context) throws DatabaseException { - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.put("graph", graph); - try { - return getDatatype.apply(context); - } catch (Throwable t) { - throw new DatabaseException(t); - } finally { - sclContext.put("graph", oldGraph); - } - } - -} +package org.simantics.db.layer0.variable; + +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.type.Datatype; +import org.simantics.db.ReadGraph; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.function.Function2; +import org.simantics.scl.runtime.function.Function3; + +public class SCLValueAccessor implements ValueAccessor { + + private final Function1 getValue1; + private final Function2 getValue2; + private final Function2 setValue2; + private final Function3 setValue3; + private final Function1 getDatatype; + + public SCLValueAccessor(Function1 getValue1, Function2 getValue2, + Function2 setValue2, Function3 setValue3, + Function1 getDatatype) { + this.getValue1 = getValue1; + this.getValue2 = getValue2; + this.setValue2 = setValue2; + this.setValue3 = setValue3; + this.getDatatype = getDatatype; + } + + @Override + public Object getValue(ReadGraph graph, Variable context) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.put("graph", graph); + try { + return getValue1.apply(context); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + + @Override + public Object getValue(ReadGraph graph, Variable context, Binding binding) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.put("graph", graph); + try { + return getValue2.apply(context, binding); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + + @Override + public void setValue(WriteGraph graph, Variable context, Object value) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.put("graph", graph); + try { + setValue2.apply(context, value); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + + @Override + public void setValue(WriteGraph graph, Variable context, Object value, Binding binding) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.put("graph", graph); + try { + setValue3.apply(context, value, binding); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + + @Override + public Datatype getDatatype(ReadGraph graph, Variable context) throws DatabaseException { + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.put("graph", graph); + try { + return getDatatype.apply(context); + } catch (Throwable t) { + throw new DatabaseException(t); + } finally { + sclContext.put("graph", oldGraph); + } + } + +}