]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectPredicates.java
Add possibility to bookkeep barrier tracing with env var
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / DirectPredicates.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2018 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.impl.query;
13
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;
18
19 public final class DirectPredicates extends UnaryQueryP<IntSet> {
20
21         DirectPredicates(final int resource) {
22                 super(resource);
23         }
24
25         @Override
26         public final void removeEntry(QueryProcessor provider) {
27                 provider.cache.remove(this);
28         }
29
30         @Override
31         public void compute(ReadGraphImpl graph, InternalProcedure<IntSet> procedure) throws DatabaseException {
32                 computeForEach(graph, id, this, procedure);
33         }
34
35         public static Object computeForEach(ReadGraphImpl graph, int id, final DirectPredicates entry, final InternalProcedure<IntSet> procedure_) throws DatabaseException {
36
37                 InternalProcedure<IntSet> procedure = entry != null ? entry : procedure_;
38
39                 graph.processor.querySupport.ensureLoaded(graph, id);
40
41                 final IntSet list = new IntSet(graph.processor.querySupport);
42
43                 graph.processor.querySupport.getPredicates(graph, id, new IntProcedure() {
44
45                         @Override
46                         public void execute(ReadGraphImpl graph, int i) {
47                                 list.add(i);
48                         }
49
50                         @Override
51                         public void finished(ReadGraphImpl graph) {
52                         }
53
54                         @Override
55                         public void exception(ReadGraphImpl graph, Throwable t) {
56                                 if(DebugException.DEBUG) new DebugException(t).printStackTrace();
57                         }
58
59                 });
60
61                 procedure.execute(graph, list);
62
63                 if(entry != null) entry.performFromCache(graph, procedure_);
64
65                 return list;
66
67         }
68
69         @Override
70         public String toString() {
71                 return "DirectPredicates[" + id + "]";
72         }
73
74 }