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