X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FSingleObjectWithType.java;h=a986034889963bf6eedcdd99ff17fc4c3d9d2aef;hp=ae72985c4679b1dd691dde5c679613a899b239b2;hb=bc5e6cb19f6af5f67bc5cfaad7d602841b8fdd0b;hpb=91682baa9a8252390f09b80fd724f47e5957b234 diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/SingleObjectWithType.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/SingleObjectWithType.java index ae72985c4..a98603488 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/request/SingleObjectWithType.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/request/SingleObjectWithType.java @@ -29,23 +29,25 @@ public final class SingleObjectWithType extends ResourceRead3 { @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; }