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.RelationInfo;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.impl.graph.ReadGraphImpl;
17 import org.simantics.db.impl.procedure.InternalProcedure;
18 import org.simantics.db.request.RequestFlags;
20 public final class RelationInfoQuery extends UnaryQueryP<RelationInfo> {
22 RelationInfoQuery(int resource) {
27 public final void removeEntry(QueryProcessor provider) {
28 provider.cache.remove(this);
31 private static void computeAssertions(ReadGraphImpl graph, int r, final boolean isFinal, final boolean isFunctional, RelationInfoQuery parent, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
33 QueryProcessor processor = graph.processor;
35 final int isUsedInAssertion = processor.getHasPredicateInverse();
36 assert(isUsedInAssertion != 0);
38 QueryCache.runnerDirectObjects(graph, r, isUsedInAssertion, parent, null, new IntProcedure() {
43 public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
46 RelationInfo result = new RelationInfo(r, isFunctional, isFinal, true);
47 procedure.execute(graph, result);
51 public void finished(ReadGraphImpl graph) throws DatabaseException {
54 RelationInfo result = new RelationInfo(r, isFunctional, isFinal, false);
55 procedure.execute(graph, result);
59 public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException {
62 DatabaseException e = new DatabaseException("Internal error in RelationInfoQuery");
63 procedure.exception(graph, e);
70 public static void computeForEach(ReadGraphImpl graph, int r, RelationInfoQuery entry, InternalProcedure<RelationInfo> procedure_) throws DatabaseException {
72 InternalProcedure<RelationInfo> procedure = entry != null ? entry : procedure_;
74 QueryProcessor provider = graph.processor;
76 final int superRelationOf = provider.getSuperrelationOf();
77 assert(superRelationOf != 0);
79 IntSet direct = QueryCache.resultDirectPredicates(graph, r, entry, null);
80 IntSet types = QueryCache.resultTypes(graph, r, entry, null);
82 computeAssertions(graph, r, !direct.contains(superRelationOf), types.contains(graph.processor.getFunctionalRelation()), entry, procedure);
84 if(entry != null) entry.performFromCache(graph, procedure_);
89 public void compute(ReadGraphImpl graph, final InternalProcedure<RelationInfo> procedure) throws DatabaseException {
90 computeForEach(graph, id, this, procedure);
94 public String toString() {
95 return "RelationInfoQuery[" + id + "]";
100 return RequestFlags.IMMEDIATE_UPDATE;