/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.layer0.utils.queries; import org.simantics.db.AsyncReadGraph; import org.simantics.db.RequestProcessor; import org.simantics.db.WriteGraph; import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncListener; import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.request.AsyncMultiRead; @Deprecated public abstract class QueryExecutor2 extends ReadRequest implements AsyncListener { // Object DUMMY = new Object(); // // @Override // public void perform(SyncReadGraph graph, // SingleQueryProcedure4 procedure) { // doPerform(graph); // procedure.execute(graph, DUMMY); // // } // protected abstract void doPerform(SyncReadGraph g); @Override public void execute(AsyncReadGraph graph, Object result) { } public void execute(WriteGraph graph) throws DatabaseException { graph.syncRequest(QueryExecutor2.this, QueryExecutor2.this); } public void execute(RequestProcessor processor) throws DatabaseException { AsyncMultiRead request = new AsyncMultiRead() { @Override public int threadHash() { return hashCode(); } @Override public void perform(AsyncReadGraph graph, AsyncMultiProcedure callback) { graph.asyncRequest(QueryExecutor2.this, QueryExecutor2.this); callback.finished(graph); } }; AsyncMultiProcedureAdapter procedure = new AsyncMultiProcedureAdapter() { @Override public void exception(AsyncReadGraph graph, Throwable t) { t.printStackTrace(); } }; if(processor instanceof WriteGraph) processor.syncRequest(request, procedure); else processor.asyncRequest(request, procedure); } @Override public void exception(AsyncReadGraph graph, Throwable t) { t.printStackTrace(); } }