1 /*******************************************************************************
2 * Copyright (c) 2007, 2018 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 public final class ValueQuery extends UnaryQueryP<byte[]> {
20 ValueQuery(int resource) {
25 public final void removeEntry(QueryProcessor provider) {
26 provider.cache.remove(this);
30 public void compute(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
31 computeForEach(graph, id, this, procedure);
34 public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure_) throws DatabaseException {
36 InternalProcedure<byte[]> procedure = entry != null ? entry : procedure_;
38 graph.ensureLoaded(r);
40 byte[] value = graph.getValue(r);
41 if(procedure != null) procedure.execute(graph, value);
43 if(entry != null && procedure_ != null) entry.performFromCache(graph, procedure_);
50 public void serializeValue(QuerySerializer serializer) {
51 byte[] result = getResult();
53 serializer.writeLE(-1);
55 serializer.writeLE(result.length);
56 serializer.add(result);
61 public String toString() {
62 return "Value[" + id + "]";