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.request.RequestFlags;
18 final public class DirectObjects extends CollectionBinaryQuery<IntProcedure> implements IntProcedure {
20 DirectObjects(final int r1, final int r2) {
26 return RequestFlags.INVALIDATE;
30 final public void removeEntry(QueryProcessor provider) {
31 provider.cache.remove(this);
35 public Object compute(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
36 computeForEach(graph, r1(), r2(), this, procedure);
40 static public void computeForEach(ReadGraphImpl graph, int r1, int r2, final DirectObjects entry,
41 final IntProcedure procedure_) throws DatabaseException {
43 IntProcedure procedure = entry != null ? entry : procedure_;
45 QueryProcessor processor = graph.processor;
47 processor.querySupport.ensureLoaded(graph, r1, r2);
49 processor.querySupport.getObjects(graph, r1, r2, procedure);
51 procedure.finished(graph);
54 entry.performFromCache(graph, procedure_);
59 public String toString() {
60 return "DirectObjects[" + r1() + " - " + r2() + "]";
64 public void setReady() {
65 statusOrException = READY;
68 // final public void add(int add) {
70 // assert(isPending());
72 // IntArray value = (IntArray)getResult();
78 public Object performFromCache(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException {
82 if (handleException(graph, procedure))
85 final IntArray value = (IntArray) getResult();
86 if (value.data == null) {
87 if (value.sizeOrData != IntArray.NO_DATA)
88 procedure.execute(graph, value.sizeOrData);
90 for (int i = 0; i < value.sizeOrData; i++)
91 procedure.execute(graph, value.data[i]);
94 procedure.finished(graph);
101 public void recompute(ReadGraphImpl graph) throws DatabaseException {
103 compute(graph, new IntProcedure() {
106 public void finished(ReadGraphImpl graph) {
110 public void exception(ReadGraphImpl graph, Throwable t) {
111 throw new Error("Error in recompute.", t);
115 public void execute(ReadGraphImpl graphd, int i) {
123 boolean isImmutable(ReadGraphImpl graph) {
124 return graph.processor.isImmutable(r1());
128 public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
129 IntArray value = (IntArray) getResult();
134 public void finished(ReadGraphImpl graph) throws DatabaseException {
139 public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {