1 /*******************************************************************************
2 * Copyright (c) 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 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.impl.query;
14 import org.simantics.db.common.exception.DebugException;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.impl.graph.ReadGraphImpl;
17 import org.simantics.db.impl.procedure.InternalProcedure;
19 public abstract class UnaryQueryP<R> extends UnaryQuery<InternalProcedure<R>> implements InternalProcedure<R> {
21 public UnaryQueryP(int r) {
25 public abstract void compute(ReadGraphImpl graph, InternalProcedure<R> procedure) throws DatabaseException;
28 public final void recompute(ReadGraphImpl graph) throws DatabaseException {
30 compute(graph, new InternalProcedure<R>() {
33 public void execute(ReadGraphImpl graph, R result) {
37 public void exception(ReadGraphImpl graph, Throwable t) {
38 if (DebugException.DEBUG)
39 new DebugException(t).printStackTrace();
40 throw new Error("Error in recompute.", t);
48 public final Object performFromCache(ReadGraphImpl graph, InternalProcedure<R> procedure)
49 throws DatabaseException {
51 if (handleException(graph, procedure))
52 return (Throwable) statusOrException;
54 procedure.execute(graph, (R)getResult());
61 public final void execute(ReadGraphImpl graph, R result) throws DatabaseException {
67 public final void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
72 final boolean isImmutable(ReadGraphImpl graph) {
73 return graph.processor.isImmutable(id);