]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.layer0.utils/src/org/simantics/layer0/utils/queries/QueryExecutor2.java
Multiple reader thread support for db client
[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 void perform(AsyncReadGraph graph,
53                                         AsyncMultiProcedure<Object> callback) {
54                                 graph.asyncRequest(QueryExecutor2.this, QueryExecutor2.this);
55                                 callback.finished(graph);
56                         }
57                         
58                 }; 
59                 
60                 AsyncMultiProcedureAdapter<Object> procedure = new AsyncMultiProcedureAdapter<Object>() {
61
62                         @Override
63                         public void exception(AsyncReadGraph graph, Throwable t) {
64                                 t.printStackTrace();
65                         }
66                         
67                 }; 
68                 
69                 if(processor instanceof WriteGraph) processor.syncRequest(request, procedure);
70                 else processor.syncRequest(request, procedure);
71                 
72         }
73
74         @Override
75         public void exception(AsyncReadGraph graph, Throwable t) {
76                 t.printStackTrace();
77         }
78         
79 }