]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueAccessorWithBinding.java
Initial support for concurrency in databoard, bindings and serializers
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / ValueAccessorWithBinding.java
1 package org.simantics.db.layer0.variable;
2
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.WriteGraph;
9 import org.simantics.db.exception.DatabaseException;
10
11 /**
12  * A default implementation of value accessor that has fixed binding.
13  */
14 public abstract class ValueAccessorWithBinding implements ValueAccessor {
15
16         public abstract Binding getBinding();
17         
18         @Override
19         public Object getValue(ReadGraph graph, Variable context, Binding binding)
20                         throws DatabaseException {
21                 try {
22                         return Bindings.adapt(getValue(graph, context), getBinding(), binding);
23                 } catch (AdaptException e) {
24                         throw new DatabaseException(e);
25                 }
26         }
27
28         @Override
29         public void setValue(WriteGraph graph, Variable context, Object value,
30                         Binding binding) throws DatabaseException {
31                 try {
32                         setValue(graph, context, Bindings.adapt(value, binding, getBinding()));
33                 } catch (AdaptException e) {
34                         throw new DatabaseException(e);
35                 }
36         }
37         
38         @Override
39         public Datatype getDatatype(ReadGraph graph, Variable context) throws DatabaseException {
40                 return getBinding().type();
41         }
42 }