--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.layer0.util;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.AsyncReadGraph;\r
+import org.simantics.db.DirectStatements;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.procedure.AsyncMultiProcedure;\r
+import org.simantics.db.procedure.AsyncProcedure;\r
+import org.simantics.db.service.DirectQuerySupport;\r
+import org.simantics.db.service.StatementSupport;\r
+import org.simantics.layer0.Layer0;\r
+\r
+final public class DomainStatementProcedure implements AsyncProcedure<DirectStatements> {\r
+\r
+ final private DirectQuerySupport dqs;\r
+ final private StatementSupport s;\r
+ final private Layer0 l0;\r
+ final private Collection<DirectStatements>[] results;\r
+ final private Collection<Resource>[] listElements;\r
+\r
+ public DomainStatementProcedure(DirectQuerySupport dqs, StatementSupport s, Layer0 l0, Collection<DirectStatements>[] results, Collection<Resource>[] listElements) {\r
+ this.dqs = dqs;\r
+ this.s = s;\r
+ this.l0 = l0;\r
+ this.results = results;\r
+ this.listElements = listElements;\r
+ }\r
+\r
+ @Override\r
+ public void execute(AsyncReadGraph graph, final DirectStatements ds) {\r
+\r
+ int thread = graph.thread();\r
+ results[thread].add(ds);\r
+\r
+ for(final Statement stm : ds) {\r
+\r
+ if (s.isList(stm)) {\r
+\r
+ graph.forIsSubrelationOf(stm.getPredicate(), l0.HasNext, new AsyncProcedure<Boolean>() {\r
+\r
+ @Override\r
+ public void execute(AsyncReadGraph graph, Boolean result) {\r
+\r
+ if (result) {\r
+\r
+ graph.forOrderedSet(stm.getSubject(),new AsyncMultiProcedure<Resource>() {\r
+\r
+ @Override\r
+ public void exception(AsyncReadGraph graph,Throwable throwable) {\r
+ throwable.printStackTrace();\r
+ }\r
+\r
+ @Override\r
+ public void execute(AsyncReadGraph graph, Resource item) {\r
+ listElements[graph.thread()].add(item);\r
+ //dqs.forEachDirectStatement(graph, item, DomainStatementProcedure.this);\r
+ }\r
+\r
+ @Override\r
+ public void finished(AsyncReadGraph graph) {\r
+ }\r
+\r
+ });\r
+\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void exception(AsyncReadGraph graph,Throwable throwable) {\r
+ throwable.printStackTrace();\r
+ }\r
+\r
+ });\r
+ \r
+ }\r
+\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void exception(AsyncReadGraph graph, Throwable throwable) {\r
+ throwable.printStackTrace();\r
+ }\r
+\r
+}\r