]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/PossibleObjectProcedure.java
Use Consumer interface instead of deprecated Callback interface
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / PossibleObjectProcedure.java
1 package org.simantics.db.impl.graph;
2
3 import org.simantics.db.Resource;
4 import org.simantics.db.exception.DatabaseException;
5 import org.simantics.db.impl.query.IntProcedure;
6 import org.simantics.db.impl.query.QueryProcessor;
7
8 public class PossibleObjectProcedure implements IntProcedure {
9
10         private static DatabaseException DUMMY = new DatabaseException();
11         
12         final private QueryProcessor processor;
13         private DatabaseException exception;
14         private Resource result;
15         
16         public PossibleObjectProcedure(QueryProcessor processor) {
17                 this.processor = processor;
18         }
19         
20         @Override
21         public void execute(ReadGraphImpl graph, int i) {
22                 Resource resource = processor.querySupport.getResource(i);
23                 if(result != null) {
24                         exception = DUMMY;
25                 } else {
26                         result = resource;
27                 }
28         }
29
30         @Override
31         public void finished(ReadGraphImpl graph) {
32         }
33
34         @Override
35         public void exception(ReadGraphImpl graph, Throwable throwable) {
36                 if(throwable instanceof DatabaseException) exception = (DatabaseException)throwable;
37                 else throwable = new DatabaseException(throwable);
38         }
39         
40         public Resource get() throws DatabaseException {
41                 if(exception == DUMMY) return null;
42                 else if(exception != null) throw exception;
43                 else return result;
44         }
45
46 }