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;
18 import gnu.trove.procedure.TIntProcedure;
20 public final class SuperTypes extends UnaryQueryP<IntSet> {
22 SuperTypes(int resource) {
27 public final void removeEntry(QueryProcessor provider) {
28 provider.cache.remove(this);
32 public void compute(ReadGraphImpl graph, final InternalProcedure<IntSet> procedure) throws DatabaseException {
33 computeForEach(graph, id, this, procedure);
36 public static Object computeForEach(ReadGraphImpl graph, int r, SuperTypes entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
38 InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
40 QueryProcessor provider = graph.processor;
42 final int inherits = provider.getInherits();
44 final IntSet result = new IntSet(provider.querySupport);
46 final TIntProcedure addToResult = new TIntProcedure() {
48 public boolean execute(int r) {
49 synchronized(result) {
56 QueryCache.runnerDirectObjects(graph, r, inherits, entry, null, new SyncIntProcedure() {
59 public void run(ReadGraphImpl graph) throws DatabaseException {
60 procedure.execute(graph, result);
64 public void execute(ReadGraphImpl graph, final int i) throws DatabaseException {
66 synchronized(result) {
72 QueryCache.runnerSuperTypes(graph, i, entry, null, new InternalProcedure<IntSet>() {
75 public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException {
77 types.forEach(addToResult);
83 public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
84 procedure.exception(graph, t);
92 public void finished(ReadGraphImpl graph) throws DatabaseException {
98 if(entry != null) entry.performFromCache(graph, procedure_);
105 public String toString() {
106 return "SuperTypes[" + id + "]";