X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Frequest%2FSingleObjectWithType.java;h=a95f28728cd04581736cfe2d4f6abd89d14f794d;hb=1cd631466bc35e05bc585999b2f325f148cd5629;hp=ae72985c4679b1dd691dde5c679613a899b239b2;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git 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..a95f28728 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,21 @@ 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; + 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; }