1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.layer0.utils.queries;
\r
14 import org.simantics.db.AsyncReadGraph;
\r
15 import org.simantics.db.RequestProcessor;
\r
16 import org.simantics.db.WriteGraph;
\r
17 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
\r
18 import org.simantics.db.common.request.ReadRequest;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.db.procedure.AsyncListener;
\r
21 import org.simantics.db.procedure.AsyncMultiProcedure;
\r
22 import org.simantics.db.request.AsyncMultiRead;
\r
25 public abstract class QueryExecutor2 extends ReadRequest implements AsyncListener<Object> {
\r
27 // Object DUMMY = new Object();
\r
30 // public void perform(SyncReadGraph graph,
\r
31 // SingleQueryProcedure4<Object> procedure) {
\r
32 // doPerform(graph);
\r
33 // procedure.execute(graph, DUMMY);
\r
37 // protected abstract void doPerform(SyncReadGraph g);
\r
40 public void execute(AsyncReadGraph graph, Object result) {
\r
43 public void execute(WriteGraph graph) throws DatabaseException {
\r
44 graph.syncRequest(QueryExecutor2.this, QueryExecutor2.this);
\r
47 public void execute(RequestProcessor processor) throws DatabaseException {
\r
49 AsyncMultiRead<Object> request = new AsyncMultiRead<Object>() {
\r
52 public int threadHash() {
\r
57 public void perform(AsyncReadGraph graph,
\r
58 AsyncMultiProcedure<Object> callback) {
\r
59 graph.asyncRequest(QueryExecutor2.this, QueryExecutor2.this);
\r
60 callback.finished(graph);
\r
65 AsyncMultiProcedureAdapter<Object> procedure = new AsyncMultiProcedureAdapter<Object>() {
\r
68 public void exception(AsyncReadGraph graph, Throwable t) {
\r
69 t.printStackTrace();
\r
74 if(processor instanceof WriteGraph) processor.syncRequest(request, procedure);
\r
75 else processor.asyncRequest(request, procedure);
\r
80 public void exception(AsyncReadGraph graph, Throwable t) {
\r
81 t.printStackTrace();
\r