1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.common.request;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.utils.NameUtils;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.exception.NoSingleResultException;
21 * @author Tuukka Lehtonen
23 public final class SingleObjectWithType extends ResourceRead3<Resource> {
25 public SingleObjectWithType(Resource resource, Resource predicate, Resource type) {
26 super(resource, predicate, type);
30 public Resource perform(ReadGraph graph) throws DatabaseException {
31 Resource result = null;
33 for (Resource object : graph.getObjects(resource, resource2)) {
34 if (graph.isInstanceOf(object, resource3)) {
40 if (resultCount != 1) {
41 String reason = resultCount == 0 ? "No objects for relation " : "Multiple objects for relation ";
42 throw new NoSingleResultException(reason
43 + NameUtils.getSafeName(graph, resource2) + " with type "
44 + NameUtils.getSafeName(graph, resource3) + " at "
45 + NameUtils.getSafeName(graph, resource), resultCount);