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.layer0.utils.queries;
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.RequestProcessor;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter;
18 import org.simantics.db.common.request.ReadRequest;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.procedure.AsyncListener;
21 import org.simantics.db.procedure.AsyncMultiProcedure;
22 import org.simantics.db.request.AsyncMultiRead;
25 public abstract class QueryExecutor2 extends ReadRequest implements AsyncListener<Object> {
27 // Object DUMMY = new Object();
30 // public void perform(SyncReadGraph graph,
31 // SingleQueryProcedure4<Object> procedure) {
33 // procedure.execute(graph, DUMMY);
37 // protected abstract void doPerform(SyncReadGraph g);
40 public void execute(AsyncReadGraph graph, Object result) {
43 public void execute(WriteGraph graph) throws DatabaseException {
44 graph.syncRequest(QueryExecutor2.this, QueryExecutor2.this);
47 public void execute(RequestProcessor processor) throws DatabaseException {
49 AsyncMultiRead<Object> request = new AsyncMultiRead<Object>() {
52 public int threadHash() {
57 public void perform(AsyncReadGraph graph,
58 AsyncMultiProcedure<Object> callback) {
59 graph.asyncRequest(QueryExecutor2.this, QueryExecutor2.this);
60 callback.finished(graph);
65 AsyncMultiProcedureAdapter<Object> procedure = new AsyncMultiProcedureAdapter<Object>() {
68 public void exception(AsyncReadGraph graph, Throwable t) {
74 if(processor instanceof WriteGraph) processor.syncRequest(request, procedure);
75 else processor.asyncRequest(request, procedure);
80 public void exception(AsyncReadGraph graph, Throwable t) {