]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
Truncate size of the binary file
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / ReadGraphImpl.java
index 3feb22e00ebda688379b6ed7c8785b09fb8035ca..79fe974642d2a71e66054fe6de5d00a60424b7bf 100644 (file)
@@ -45,6 +45,7 @@ import org.simantics.databoard.type.Datatype;
 import org.simantics.databoard.util.binary.BinaryFile;
 import org.simantics.databoard.util.binary.RandomAccessBinary;
 import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ComputationalValue;
 import org.simantics.db.DevelopmentKeys;
 import org.simantics.db.ExternalValueSupport;
 import org.simantics.db.ReadGraph;
@@ -5913,6 +5914,8 @@ public class ReadGraphImpl implements AsyncReadGraph {
             }
             Serializer serializer = binding.serializer();
             byte[] bytes = serializer.serialize(initialValue);
+            // In case the file has been previously accessed and was larger we set the correct size now
+            rd.binaryFile.setLength(bytes.length);
             rd.binaryFile.write(bytes);
             ravs.put(resource, rd);
             return rd;
@@ -6102,12 +6105,18 @@ public class ReadGraphImpl implements AsyncReadGraph {
                        return getValue(r, binding);
                }
        } else if(types.contains(L0.ExternalValue)) {
-               try {
-                       return (T)ReflectionUtils.getValue(getURI(r)).getValue();
-               } catch(ValueNotFoundException e) {
-                       throw new DatabaseException(e);
-               } catch(ClassCastException e) {
-                       throw new DatabaseException(e);
+               ComputationalValue cv = syncRequest(new PossibleAdapter<ComputationalValue>(r, ComputationalValue.class), TransientCacheAsyncListener.instance());
+               if(cv != null) {
+                       return cv.getValue(this, r);
+               } else {
+                       // This should not even be possible since L0 defines an adapter for all values
+                       try {
+                               return (T)ReflectionUtils.getValue(getURI(r)).getValue();
+                       } catch(ValueNotFoundException e) {
+                               throw new DatabaseException(e);
+                       } catch(ClassCastException e) {
+                               throw new DatabaseException(e);
+                       }
                }
        }
        else {