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.InternalProcedure;
17 import org.simantics.db.procedure.ListenerBase;
19 import gnu.trove.procedure.TIntProcedure;
21 public final class TypeHierarchy extends UnaryQueryP<IntSet> {
23 TypeHierarchy(int resource) {
27 public static final 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 public final void removeEntry(QueryProcessor provider) {
33 provider.cache.remove(this);
37 public void compute(final ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
38 computeForEach(graph, id, this, procedure);
41 public static IntSet computeForEach(ReadGraphImpl graph, int id, TypeHierarchy entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
43 InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
45 QueryProcessor processor = graph.processor;
47 final IntSet result = new IntSet(processor.querySupport, id);
49 final TIntProcedure addToResult = new TIntProcedure() {
51 public boolean execute(int r) {
57 QueryCache.runnerSuperTypes(graph, id, entry, null, new InternalProcedure<IntSet>() {
60 public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
61 types.forEach(addToResult);
62 procedure.execute(graph, result);
66 public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
67 procedure.exception(graph, t);
72 if(entry != null) entry.performFromCache(graph, procedure_);
79 public String toString() {
80 return "TypeHierarchy[" + id + "]";