]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueQuery.java
e533ee30f4ee4f521316b56981c8a13f68c4c6af
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ValueQuery.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.impl.query;
13
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.impl.graph.ReadGraphImpl;
16 import org.simantics.db.impl.procedure.InternalProcedure;
17
18 final public class ValueQuery extends UnaryQueryP<byte[]> {
19     
20     ValueQuery(final int resource) {
21         super(resource);
22     }
23
24         @Override
25         final public void removeEntry(QueryProcessor provider) {
26                 provider.cache.remove(this);
27         }
28         
29         @Override
30         public void compute(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
31             computeForEach(graph, id, this, procedure);
32         }
33                 
34         public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure_) throws DatabaseException {
35             
36             InternalProcedure<byte[]> procedure = entry != null ? entry : procedure_;
37
38                 graph.ensureLoaded(r);
39                 
40                 byte[] value = graph.getValue(r);
41                 if(procedure != null) procedure.execute(graph, value);
42                 
43                 if(entry != null && procedure_ != null) entry.performFromCache(graph, procedure_);
44                 
45                 return value;
46                 
47         }
48     
49     @Override
50     public String toString() {
51         return "Value[" + id + "]";
52     }
53     
54 }