X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fgraph%2FReadGraphImpl.java;h=2309af76440b10bc2a3e9d336cf2fc4bdfc14819;hp=61580bfdcb6ae9a96680952b070261057b9a2fe6;hb=e10760b08746837538ad4c2b4c37736aa34c7a47;hpb=73884c78cf2695329aa3b6559c4c6a196792ac9b diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index 61580bfdc..2309af764 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -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()); } @@ -1511,15 +1515,15 @@ public class ReadGraphImpl implements AsyncReadGraph { try { - int result = processor.getSingleObject(this, subject, relation); - if(result == 0) return null; - - return processor.querySupport.getResource(result); + int result = processor.getSingleObject(this, subject, relation); + if(result == 0) return null; + + return processor.querySupport.getResource(result); - } catch (ManyObjectsForFunctionalRelationException e) { + } catch (ManyObjectsForFunctionalRelationException e) { + + throw new ManyObjectsForFunctionalRelationException("Many objects in " + subject + " for functional relation " + relation); - throw new ManyObjectsForFunctionalRelationException("subject=" + subject + ", relation=" + relation, e); - } catch (DatabaseException e) { throw new ServiceException(e); @@ -1846,13 +1850,42 @@ public class ReadGraphImpl implements AsyncReadGraph { try { - Collection objects = getObjects(subject, relation); - return !objects.isEmpty(); + RelationInfo rinfo = processor.getRelationInfo(this, relation); + Collection 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); + } }