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.IntProcedureAdapter;
18 public abstract class CollectionUnaryQuery extends UnaryQuery<IntProcedure> implements IntProcedure {
20 public CollectionUnaryQuery(final int id) {
24 public abstract void compute(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException;
27 public final void clearResult(QuerySupport support) {
28 setResult(new IntArray());
32 public final void setReady() {
34 IntArray v = (IntArray)getResult();
36 if(size == 0) setResult(IntArray.EMPTY);
41 public final Object performFromCache(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException {
45 if(handleException(graph, procedure)) return EXCEPTED;
47 final IntArray value = (IntArray)getResult();
48 if(value.data == null) {
49 if(value.sizeOrData != IntArray.NO_DATA) procedure.execute(graph, value.sizeOrData);
51 for(int i = 0;i < value.sizeOrData ; i++) procedure.execute(graph, value.data[i]);
54 procedure.finished(graph);
61 public final void recompute(ReadGraphImpl graph) throws DatabaseException {
63 compute(graph, new IntProcedureAdapter() {
66 public void finished(ReadGraphImpl graph) {
70 public void exception(ReadGraphImpl graph, Throwable t) {
71 new Error("Error in recompute.", t).printStackTrace();
79 final boolean isImmutable(ReadGraphImpl graph) {
80 return graph.processor.isImmutable(id);
84 public final void execute(ReadGraphImpl graph, int i) throws DatabaseException {
85 IntArray v = (IntArray)getResult();
90 public final void finished(ReadGraphImpl graph) throws DatabaseException {
95 public final void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {