/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.db.impl.query; import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.InternalProcedure; final public class ValueQuery extends UnaryQuery> { ValueQuery(final int resource) { super(resource); } @Override final public void removeEntry(QueryProcessor provider) { provider.cache.remove(this); } public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure procedure) throws DatabaseException { graph.ensureLoaded(r); byte[] value = graph.getValue(r); if(entry != null) { entry.setResult(value); entry.setReady(); } if(procedure != null) { procedure.execute(graph, value); } return value; } public static byte[] computeForEach(ReadGraphImpl graph, final int r) { graph.ensureLoaded(r); return graph.getValue(r); } @Override public Object compute(ReadGraphImpl graph, final InternalProcedure procedure) throws DatabaseException { return computeForEach(graph, id, this, procedure); } @Override public String toString() { return "Value[" + id + "]"; } @Override public Object performFromCache(ReadGraphImpl graph, InternalProcedure procedure) throws DatabaseException { return compute(graph, procedure); } @Override public void recompute(ReadGraphImpl graph) throws DatabaseException { compute(graph, new InternalProcedure() { @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); } }