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;
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());
}
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);
try {
- Collection<Resource> objects = getObjects(subject, relation);
- return !objects.isEmpty();
+ SyncReadProcedure<RelationInfo> procedure = new SyncReadProcedure<RelationInfo>();
+ processor.forRelationInfo(this, relation, procedure);
+ Collection<Resource> predicates = getPredicates(subject);
+
+ if(procedure.result.isFinal) {
+
+ return predicates.contains(relation);
+
+ } else if (procedure.result.isFunctional) {
+
+ try {
+ int result = processor.getSingleObject(this, subject, relation);
+ return result != 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) {