@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;
}