--- /dev/null
+package org.simantics.db.impl.graph;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.NoSingleResultException;\r
+import org.simantics.db.impl.query.IntProcedure;\r
+import org.simantics.db.impl.query.QueryProcessor;\r
+\r
+public class PossibleObjectProcedure implements IntProcedure {\r
+\r
+ private static DatabaseException DUMMY = new DatabaseException();\r
+ \r
+ final private QueryProcessor processor;\r
+ private DatabaseException exception;\r
+ private Resource result;\r
+ \r
+ public PossibleObjectProcedure(QueryProcessor processor) {\r
+ this.processor = processor;\r
+ }\r
+ \r
+ @Override\r
+ public void execute(ReadGraphImpl graph, int i) {\r
+ Resource resource = processor.querySupport.getResource(i);\r
+ if(result != null) {\r
+ exception = DUMMY;\r
+ } else {\r
+ result = resource;\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void finished(ReadGraphImpl graph) {\r
+ }\r
+\r
+ @Override\r
+ public void exception(ReadGraphImpl graph, Throwable throwable) {\r
+ if(throwable instanceof DatabaseException) exception = (DatabaseException)throwable;\r
+ else throwable = new DatabaseException(throwable);\r
+ }\r
+ \r
+ public Resource get() throws DatabaseException {\r
+ if(exception == DUMMY) return null;\r
+ else if(exception != null) throw exception;\r
+ else return result;\r
+ }\r
+\r
+}\r