1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.impl.query;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.impl.graph.ReadGraphImpl;
16 import org.simantics.db.impl.procedure.InternalProcedure;
18 final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
20 ValueQuery(final int resource) {
25 final public void removeEntry(QueryProcessor provider) {
26 provider.cache.remove(this);
29 public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure) throws DatabaseException {
31 graph.ensureLoaded(r);
33 byte[] value = graph.getValue(r);
35 entry.setResult(value);
38 if(procedure != null) {
39 procedure.execute(graph, value);
46 public static byte[] computeForEach(ReadGraphImpl graph, final int r) {
48 graph.ensureLoaded(r);
50 return graph.getValue(r);
55 public Object compute(ReadGraphImpl graph, final InternalProcedure<byte[]> procedure) throws DatabaseException {
56 return computeForEach(graph, id, this, procedure);
60 public String toString() {
61 return "Value[" + id + "]";
65 public Object performFromCache(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
66 return compute(graph, procedure);
70 public void recompute(ReadGraphImpl graph) throws DatabaseException {
72 compute(graph, new InternalProcedure<byte[]>() {
75 public void execute(ReadGraphImpl graph, byte[] result) {
79 public void exception(ReadGraphImpl graph, Throwable t) {
80 throw new Error("Error in recompute.", t);
88 boolean isImmutable(ReadGraphImpl graph) {
89 return graph.processor.isImmutable(id);