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.impl.procedure.InternalProcedure;
17 import org.simantics.db.procedure.ListenerBase;
19 import gnu.trove.procedure.TIntProcedure;
21 final public class TypeHierarchy extends UnaryQuery<InternalProcedure<IntSet>> {
23 TypeHierarchy(final int resource) {
27 final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) throws DatabaseException {
28 QueryCache.runnerTypeHierarchy(graph, r, parent, listener, procedure);
32 final public void removeEntry(QueryProcessor provider) {
33 provider.cache.remove(this);
37 public IntSet compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
39 QueryProcessor processor = graph.processor;
41 final IntSet result = new IntSet(processor.querySupport, id);
43 final TIntProcedure addToResult = new TIntProcedure() {
45 public boolean execute(int r) {
51 QueryCache.runnerSuperTypes(graph, id, TypeHierarchy.this, null, new InternalProcedure<IntSet>() {
54 public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
56 types.forEach(addToResult);
57 addOrSet(graph, result, processor);
58 procedure.execute(graph, result);
63 public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
64 procedure.exception(graph, t);
74 public String toString() {
75 return "TypeHierarchy[" + id + "]";
78 private void addOrSet(ReadGraphImpl graph, final IntSet value, QueryProcessor provider) {
93 public Object performFromCache(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
97 if(handleException(graph, procedure)) return null;
99 IntSet result = getResult();
101 procedure.execute(graph, result);
108 public void recompute(ReadGraphImpl graph) throws DatabaseException {
110 compute(graph, new InternalProcedure<IntSet>() {
113 public void execute(ReadGraphImpl graph, IntSet result) {
117 public void exception(ReadGraphImpl graph, Throwable t) {
118 new Error("Error in recompute.", t).printStackTrace();
126 boolean isImmutable(ReadGraphImpl graph) {
127 return graph.processor.isImmutable(id);