1 package org.simantics.db.layer0.variable;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.databoard.adapter.AdaptException;
5 import org.simantics.databoard.binding.Binding;
6 import org.simantics.databoard.type.Datatype;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.WriteGraph;
10 import org.simantics.db.exception.DatabaseException;
12 public class ConstantValueStandardGraphPropertyVariable extends StandardGraphPropertyVariable {
14 final private Object value;
15 final private Datatype datatype;
17 public ConstantValueStandardGraphPropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource predicate, Object value, Datatype datatype) throws DatabaseException {
18 super(graph, parent, null, parentResource, predicate);
20 this.datatype = datatype;
23 @SuppressWarnings("unchecked")
25 public <T> T getValue(ReadGraph graph) throws DatabaseException {
29 @SuppressWarnings("unchecked")
31 public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {
33 return (T)Bindings.adapt(value, Bindings.getBinding(datatype), binding);
34 } catch (AdaptException e) {
35 throw new DatabaseException(e);
40 public Datatype getDatatype(ReadGraph graph) throws DatabaseException {
45 public void setValue(WriteGraph graph, Object value) throws DatabaseException {
46 throw new DatabaseException("setValue is not supported.");
50 public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
51 throw new DatabaseException("setValue is not supported.");