1 package org.simantics.db.impl.graph;
3 import org.simantics.db.Resource;
4 import org.simantics.db.exception.DatabaseException;
5 import org.simantics.db.exception.NoSingleResultException;
6 import org.simantics.db.impl.query.IntProcedure;
7 import org.simantics.db.impl.query.QueryProcessor;
9 public class SingleObjectProcedure implements IntProcedure {
11 final private QueryProcessor processor;
12 private DatabaseException exception;
13 private Resource result;
15 public SingleObjectProcedure(QueryProcessor processor) {
16 this.processor = processor;
20 public void execute(ReadGraphImpl graph, int i) {
21 Resource resource = processor.querySupport.getResource(i);
23 exception = new NoSingleResultException("", 2);
30 public void finished(ReadGraphImpl graph) {
31 if(result == null) exception = new NoSingleResultException("", 0);
35 public void exception(ReadGraphImpl graph, Throwable throwable) {
36 if(throwable instanceof DatabaseException) exception = (DatabaseException)throwable;
37 else throwable = new DatabaseException(throwable);
40 public Resource get() throws DatabaseException {
41 if(exception != null) throw exception;