X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fgraph%2FSingleObjectProcedure.java;h=662d2d32dfc49cd53c42dafbfa5344e988ff770e;hb=refs%2Fchanges%2F29%2F1529%2F8;hp=2080165d106ff6656ebac44feb67daffe3e267b1;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/SingleObjectProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/SingleObjectProcedure.java index 2080165d1..662d2d32d 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/SingleObjectProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/SingleObjectProcedure.java @@ -1,45 +1,45 @@ -package org.simantics.db.impl.graph; - -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.NoSingleResultException; -import org.simantics.db.impl.query.IntProcedure; -import org.simantics.db.impl.query.QueryProcessor; - -public class SingleObjectProcedure implements IntProcedure { - - final private QueryProcessor processor; - private DatabaseException exception; - private Resource result; - - public SingleObjectProcedure(QueryProcessor processor) { - this.processor = processor; - } - - @Override - public void execute(ReadGraphImpl graph, int i) { - Resource resource = processor.querySupport.getResource(i); - if(result != null) { - exception = new NoSingleResultException(""); - } else { - result = resource; - } - } - - @Override - public void finished(ReadGraphImpl graph) { - if(result == null) exception = new NoSingleResultException(""); - } - - @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 != null) throw exception; - else return result; - } - -} +package org.simantics.db.impl.graph; + +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; +import org.simantics.db.impl.query.IntProcedure; +import org.simantics.db.impl.query.QueryProcessor; + +public class SingleObjectProcedure implements IntProcedure { + + final private QueryProcessor processor; + private DatabaseException exception; + private Resource result; + + public SingleObjectProcedure(QueryProcessor processor) { + this.processor = processor; + } + + @Override + public void execute(ReadGraphImpl graph, int i) { + Resource resource = processor.querySupport.getResource(i); + if(result != null) { + exception = new NoSingleResultException("", 2); + } else { + result = resource; + } + } + + @Override + public void finished(ReadGraphImpl graph) { + if(result == null) exception = new NoSingleResultException("", 0); + } + + @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 != null) throw exception; + else return result; + } + +}