]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java
9814925e3715daba6e0efcc16451d5d59a76b0e3
[simantics/platform.git] / bundles / org.simantics.layer0.utils / src / org / simantics / layer0 / utils / queries / QueryExecutor2.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.layer0.utils.queries;
13
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;
23
24 @Deprecated
25 public abstract class QueryExecutor2 extends ReadRequest implements AsyncListener<Object> {
26
27 //      Object DUMMY = new Object();
28 //      
29 //      @Override
30 //      public void perform(SyncReadGraph graph,
31 //              SingleQueryProcedure4<Object> procedure) {
32 //              doPerform(graph);
33 //              procedure.execute(graph, DUMMY);
34 //              
35 //      }
36         
37 //      protected abstract void doPerform(SyncReadGraph g);
38         
39         @Override
40         public void execute(AsyncReadGraph graph, Object result) {
41         }
42
43         public void execute(WriteGraph graph) throws DatabaseException {
44                 graph.syncRequest(QueryExecutor2.this, QueryExecutor2.this);
45         }
46
47         public void execute(RequestProcessor processor) throws DatabaseException {
48                 
49                 AsyncMultiRead<Object> request = new AsyncMultiRead<Object>() {
50
51                         @Override
52                         public int threadHash() {
53                                 return hashCode();
54                         }
55                         
56                         @Override
57                         public void perform(AsyncReadGraph graph,
58                                         AsyncMultiProcedure<Object> callback) {
59                                 graph.asyncRequest(QueryExecutor2.this, QueryExecutor2.this);
60                                 callback.finished(graph);
61                         }
62                         
63                 }; 
64                 
65                 AsyncMultiProcedureAdapter<Object> procedure = new AsyncMultiProcedureAdapter<Object>() {
66
67                         @Override
68                         public void exception(AsyncReadGraph graph, Throwable t) {
69                                 t.printStackTrace();
70                         }
71                         
72                 }; 
73                 
74                 if(processor instanceof WriteGraph) processor.syncRequest(request, procedure);
75                 else processor.asyncRequest(request, procedure);
76                 
77         }
78
79         @Override
80         public void exception(AsyncReadGraph graph, Throwable t) {
81                 t.printStackTrace();
82         }
83         
84 }