1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.layer0.util;
14 import java.util.Collection;
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;
26 final public class DomainStatementProcedure implements AsyncProcedure<DirectStatements> {
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;
34 public DomainStatementProcedure(DirectQuerySupport dqs, StatementSupport s, Layer0 l0, Collection<DirectStatements>[] results, Collection<Resource>[] listElements) {
38 this.results = results;
39 this.listElements = listElements;
43 public void execute(AsyncReadGraph graph, final DirectStatements ds) {
45 int thread = graph.thread();
46 results[thread].add(ds);
48 for(final Statement stm : ds) {
52 graph.forIsSubrelationOf(stm.getPredicate(), l0.HasNext, new AsyncProcedure<Boolean>() {
55 public void execute(AsyncReadGraph graph, Boolean result) {
59 graph.forOrderedSet(stm.getSubject(),new AsyncMultiProcedure<Resource>() {
62 public void exception(AsyncReadGraph graph,Throwable throwable) {
63 throwable.printStackTrace();
67 public void execute(AsyncReadGraph graph, Resource item) {
68 listElements[graph.thread()].add(item);
69 //dqs.forEachDirectStatement(graph, item, DomainStatementProcedure.this);
73 public void finished(AsyncReadGraph graph) {
83 public void exception(AsyncReadGraph graph,Throwable throwable) {
84 throwable.printStackTrace();
96 public void exception(AsyncReadGraph graph, Throwable throwable) {
97 throwable.printStackTrace();