import org.simantics.db.impl.graph.ReadGraphImpl;
import org.simantics.db.impl.procedure.InternalProcedure;
-final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
+final public class ValueQuery extends UnaryQueryP<byte[]> {
ValueQuery(final int resource) {
super(resource);
final public void removeEntry(QueryProcessor provider) {
provider.cache.remove(this);
}
+
+ @Override
+ public void compute(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ }
- public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure) throws DatabaseException {
+ public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure_) throws DatabaseException {
+
+ InternalProcedure<byte[]> procedure = entry != null ? entry : procedure_;
graph.ensureLoaded(r);
byte[] value = graph.getValue(r);
- if(entry != null) {
- entry.setResult(value);
- entry.setReady();
- }
- if(procedure != null) {
- procedure.execute(graph, value);
- }
+ if(procedure != null) procedure.execute(graph, value);
+
+ if(entry != null && procedure_ != null) entry.performFromCache(graph, procedure_);
return value;
}
-
-// public Object compute(ReadGraphImpl graph, final InternalProcedure<byte[]> procedure) throws DatabaseException {
-// return computeForEach(graph, id, this, procedure);
-// }
@Override
public String toString() {
return "Value[" + id + "]";
}
-
- @Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
- return computeForEach(graph, id, this, procedure);
- }
-
- @Override
- public void recompute(ReadGraphImpl graph) throws DatabaseException {
-
- computeForEach(graph, id, this, new InternalProcedure<byte[]>() {
-
- @Override
- public void execute(ReadGraphImpl graph, byte[] result) {
- }
-
- @Override
- public void exception(ReadGraphImpl graph, Throwable t) {
- throw new Error("Error in recompute.", t);
- }
-
- });
-
- }
-
- @Override
- boolean isImmutable(ReadGraphImpl graph) {
- return graph.processor.isImmutable(id);
- }
}