]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
Fix livelock situation in QueryProcessor
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / ReadGraphImpl.java
index 2ef40c29459d4be20009b30a73f54bd85b6fb08f..3e955febc54743e25134184a2d7c3d9d85b9135c 100644 (file)
@@ -5152,7 +5152,7 @@ public class ReadGraphImpl implements AsyncReadGraph {
                assert (request != null);
                assert (procedure != null);
        
-               processor.schedule(new SessionTask(this) {
+               processor.scheduleNow(new SessionTask(this) {
 
                        @Override
                        public void run0(int thread) {
@@ -5232,7 +5232,7 @@ public class ReadGraphImpl implements AsyncReadGraph {
                assert (request != null);
                assert (procedure != null);
 
-               processor.schedule(new SessionTask(this) {
+               processor.scheduleNow(new SessionTask(this) {
 
                        @Override
                        public void run0(int thread) {
@@ -5914,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;
@@ -6179,11 +6181,12 @@ public class ReadGraphImpl implements AsyncReadGraph {
     @Override
     public <T> T getRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException {
                if(Development.DEVELOPMENT) {
-                       String error = L0Validations.checkValueType(this, subject, relation);
-                       if(error != null) {
-                               Logger.defaultLogError(new ValidationException(error));
-                               //throw new ValidationException(error);
-                               new ValidationException(error).printStackTrace();
+                       if(Development.<Boolean>getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) {
+                               String error = L0Validations.checkValueType(this, subject, relation);
+                               if(error != null) {
+                                       Logger.defaultLogError(new ValidationException(error));
+                                       throw new ValidationException(error);
+                               }
                        }
                }
         return getValue2(getSingleObject(subject, relation), context);
@@ -6192,12 +6195,13 @@ public class ReadGraphImpl implements AsyncReadGraph {
     @Override
     public Variant getRelatedVariantValue2(Resource subject, Resource relation, Object context) throws DatabaseException {
         if(Development.DEVELOPMENT) {
-            String error = L0Validations.checkValueType(this, subject, relation);
-            if(error != null) {
-                Logger.defaultLogError(new ValidationException(error));
-                //throw new ValidationException(error);
-                new ValidationException(error).printStackTrace();
-            }
+                       if(Development.<Boolean>getProperty(DevelopmentKeys.L0_VALIDATION, Bindings.BOOLEAN)) {
+                               String error = L0Validations.checkValueType(this, subject, relation);
+                               if(error != null) {
+                                       Logger.defaultLogError(new ValidationException(error));
+                                       throw new ValidationException(error);
+                               }
+                       }
         }
         return getVariantValue2(getSingleObject(subject, relation), context);
     }
@@ -6308,7 +6312,7 @@ public class ReadGraphImpl implements AsyncReadGraph {
     public boolean performPending() {
         return processor.performPending(this);
     }
-
+    
     public Set<ReadGraphImpl> ancestorSet() {
         HashSet<ReadGraphImpl> result = new HashSet<>();
         ReadGraphImpl g = this;
@@ -6318,5 +6322,23 @@ public class ReadGraphImpl implements AsyncReadGraph {
         }
         return result;
     }
+    
+    public int getLevel() {
+        return getLevelStatic(this);
+    }
+    
+    private static int getLevelStatic(ReadGraphImpl impl) {
+        if(impl == null) return 0;
+        else return 1 + getLevelStatic(impl.parentGraph);
+    }
+    
+    public ReadGraphImpl getTopLevelGraph() {
+        return getTopLevelGraphStatic(this);
+    }
+
+    private static ReadGraphImpl getTopLevelGraphStatic(ReadGraphImpl impl) {
+        if(impl.parentGraph == null) return impl;
+        else return getTopLevelGraphStatic(impl.parentGraph);
+    }
 
 }