]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/request/SingleObjectWithType.java
Ignore NoSingleResultException in DependenciesRelation
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / SingleObjectWithType.java
index ae72985c4679b1dd691dde5c679613a899b239b2..a986034889963bf6eedcdd99ff17fc4c3d9d2aef 100644 (file)
@@ -29,23 +29,25 @@ public final class SingleObjectWithType extends ResourceRead3<Resource> {
     @Override
     public Resource perform(ReadGraph graph) throws DatabaseException {
         Resource result = null;
+        int resultCount = 0;
         for (Resource object : graph.getObjects(resource, resource2)) {
             if (graph.isInstanceOf(object, resource3)) {
-                if (result != null)
-                    throw new NoSingleResultException("More than 1 objects for relation "
-                            + NameUtils.getSafeName(graph, resource2) + " with type "
-                            + NameUtils.getSafeName(graph, resource3) + " at "
-                            + NameUtils.getSafeName(graph, resource));
-
-                result = object;
+                if (result == null) {
+                    result = object;
+                } else {
+                    // okay, too many results but lets calculate for debug
+                    resultCount++;
+                }
             }
         }
-
-        if (result == null)
-            throw new NoSingleResultException("No objects for relation "
+        
+        if (resultCount != 1) {
+            String reason = resultCount == 0 ? "No objects for relation " : "Multiple objects for relation ";
+            throw new NoSingleResultException(reason
                     + NameUtils.getSafeName(graph, resource2) + " with type "
                     + NameUtils.getSafeName(graph, resource3) + " at "
-                    + NameUtils.getSafeName(graph, resource));
+                    + NameUtils.getSafeName(graph, resource), resultCount);
+        }
 
         return result;
     }