]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainStatementProcedure.java
Always write model activation information in activations VG
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / DomainStatementProcedure.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.layer0.util;
13
14 import java.util.Collection;
15
16 import org.simantics.db.AsyncReadGraph;
17 import org.simantics.db.DirectStatements;
18 import org.simantics.db.Resource;
19 import org.simantics.db.Statement;
20 import org.simantics.db.procedure.AsyncMultiProcedure;
21 import org.simantics.db.procedure.AsyncProcedure;
22 import org.simantics.db.service.DirectQuerySupport;
23 import org.simantics.db.service.StatementSupport;
24 import org.simantics.layer0.Layer0;
25
26 final public class DomainStatementProcedure implements AsyncProcedure<DirectStatements> {
27
28         final private DirectQuerySupport dqs;
29         final private StatementSupport s;
30         final private Layer0 l0;
31         final private Collection<DirectStatements>[] results;
32         final private Collection<Resource>[] listElements;
33
34         public DomainStatementProcedure(DirectQuerySupport dqs, StatementSupport s, Layer0 l0, Collection<DirectStatements>[] results, Collection<Resource>[] listElements) {
35                 this.dqs = dqs;
36                 this.s = s;
37                 this.l0 = l0;
38                 this.results = results;
39                 this.listElements = listElements;
40         }
41
42         @Override
43         public void execute(AsyncReadGraph graph, final DirectStatements ds) {
44
45                 int thread = graph.thread();
46                 results[thread].add(ds);
47
48                 for(final Statement stm : ds) {
49
50                         if (s.isList(stm)) {
51
52                                 graph.forIsSubrelationOf(stm.getPredicate(), l0.HasNext, new AsyncProcedure<Boolean>() {
53
54                                         @Override
55                                         public void execute(AsyncReadGraph graph, Boolean result) {
56
57                                                 if (result) {
58
59                                                         graph.forOrderedSet(stm.getSubject(),new AsyncMultiProcedure<Resource>() {
60
61                                                                 @Override
62                                                                 public void exception(AsyncReadGraph graph,Throwable throwable) {
63                                                                         throwable.printStackTrace();
64                                                                 }
65
66                                                                 @Override
67                                                                 public void execute(AsyncReadGraph graph, Resource item) {
68                                                                         listElements[graph.thread()].add(item);
69                                                                         //dqs.forEachDirectStatement(graph, item, DomainStatementProcedure.this);
70                                                                 }
71
72                                                                 @Override
73                                                                 public void finished(AsyncReadGraph graph) {
74                                                                 }
75
76                                                         });
77
78                                                 }
79
80                                         }
81
82                                         @Override
83                                         public void exception(AsyncReadGraph graph,Throwable throwable) {
84                                                 throwable.printStackTrace();
85                                         }
86
87                                 });
88                                 
89                         }
90
91                 }
92
93         }
94
95         @Override
96         public void exception(AsyncReadGraph graph, Throwable throwable) {
97                 throwable.printStackTrace();
98         }
99
100 }