X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.layer0.utils%2Fsrc%2Forg%2Fsimantics%2Flayer0%2Futils%2Fqueries%2FQueryExecutor2.java;fp=bundles%2Forg.simantics.layer0.utils%2Fsrc%2Forg%2Fsimantics%2Flayer0%2Futils%2Fqueries%2FQueryExecutor2.java;h=90c23305ccb8b1ef80e3cc3bc1df044aeb149524;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java b/bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java new file mode 100644 index 000000000..90c23305c --- /dev/null +++ b/bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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(); + } + +}