]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
Fix non-compiling ReadGraphImpl.hasStatement implementation
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / ReadGraphImpl.java
index 27336b23d32474eda7bf7b00ab368a9cb5b56e02..2309af76440b10bc2a3e9d336cf2fc4bdfc14819 100644 (file)
@@ -50,6 +50,7 @@ import org.simantics.db.DevelopmentKeys;
 import org.simantics.db.ExternalValueSupport;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.RelationContext;
+import org.simantics.db.RelationInfo;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.Statement;
@@ -1349,7 +1350,10 @@ public class ReadGraphImpl implements AsyncReadGraph {
 
                Statement stm = getSingleStatement(resource, relation);
                
-               return adaptContextual(stm.getObject(), new RelationContextImpl(resource, stm), RelationContext.class, clazz);
+               Object o = adaptContextual(stm.getObject(), new RelationContextImpl(resource, stm), RelationContext.class, clazz);
+               if (clazz.isInstance(o))
+                       return (T)o;
+               throw new AdaptionException("Returned value is not expected class , got " + o.getClass().getName()+ " , expected " + clazz.getName());
                
        }
 
@@ -1846,13 +1850,42 @@ public class ReadGraphImpl implements AsyncReadGraph {
 
                try {
 
-                       Collection<Resource> objects = getObjects(subject, relation);
-                       return !objects.isEmpty();
+                       RelationInfo rinfo = processor.getRelationInfo(this, relation);
+                       Collection<Resource> predicates = getPredicates(subject);
+
+                       if (rinfo.isFinal) {
+
+                               return predicates.contains(relation);
+
+                       } else if (rinfo.isFunctional) {
+
+                               try {
+                                       return processor.getSingleObject(this, subject, relation) != 0;
+                               } catch (ManyObjectsForFunctionalRelationException e) {
+                                       return true;
+                               } catch (DatabaseException e) {
+                                       throw new ServiceException(e);
+                               }
+
+                       } else {
+
+                               for (Resource predicate : getPredicates(subject)) {
+                                       if (isSubrelationOf(predicate, relation))
+                                               return true;
+                               }
+
+                       }
+
+                       return false;
 
                } catch (ServiceException e) {
 
                        throw new ServiceException(e);
 
+               } catch (DatabaseException e) {
+
+                       throw new ServiceException(INTERNAL_ERROR_STRING, e);
+
                } 
                
        }