]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/misc/SyncAsyncSyncTest9.java
Merge "Multiple reader thread support for db client"
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / misc / SyncAsyncSyncTest9.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.db.tests.api.request.misc;
13
14 import org.junit.Test;
15 import org.simantics.db.AsyncReadGraph;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.Session;
19 import org.simantics.db.Statement;
20 import org.simantics.db.common.primitiverequest.PossibleStatement;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.procedure.AsyncListener;
23 import org.simantics.db.procedure.SyncListener;
24 import org.simantics.db.testing.base.ExistingDatabaseTest;
25 import org.simantics.layer0.Layer0;
26
27 public class SyncAsyncSyncTest9 extends ExistingDatabaseTest {
28         
29         @Test
30         public void test() throws Exception {
31                 
32                 Session session = getSession();
33                 
34         session.syncRequest(new TestAsyncReadRequest() {
35
36             @Override
37             public void run(AsyncReadGraph g) throws Throwable {
38
39                 final Layer0 b = Layer0.getInstance(g);
40
41                 g.forPossibleObject(g.getRootLibrary(), b.InstanceOf, new AsyncListener<Resource>() {
42
43                     @Override
44                     public void execute(AsyncReadGraph graph, Resource type) {
45
46                         graph.asyncRequest(new PossibleStatement(type, b.InstanceOf), new SyncListener<Statement>() {
47
48                             @Override
49                             public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
50                             }
51
52                             @Override
53                             public void execute(ReadGraph graph, Statement result) throws DatabaseException {
54                             }
55
56                             @Override
57                             public boolean isDisposed() {
58                                 return false;
59                             }
60                             
61                         });
62
63 //                        graph.syncRequest(new ForObjectSet(type, b.Inherits, new SyncSetListener<Resource>() {
64 //
65 //                            @Override
66 //                            public void add(ReadGraph graph, Resource result) throws DatabaseException {
67 //                                
68 //                                System.out.println(GraphUtils.getReadableName(graph, result));
69 //                                
70 //                                graph.asyncRequest(new PossibleStatement(result, b.InstanceOf), new SyncListener<Statement>() {
71 //
72 //                                    @Override
73 //                                    public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
74 //                                    }
75 //
76 //                                    @Override
77 //                                    public void execute(ReadGraph graph, Statement result) throws DatabaseException {
78 //                                    }
79 //
80 //                                    @Override
81 //                                    public boolean isDisposed() {
82 //                                        return false;
83 //                                    }
84 //                                    
85 //                                });
86 //                                
87 //                            }
88 //
89 //                            @Override
90 //                            public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
91 //                                assert(false);
92 //                            }
93 //
94 //                            @Override
95 //                            public void remove(ReadGraph graph, Resource result) throws DatabaseException {
96 //                                assert(false);
97 //                            }
98 //
99 //                            @Override
100 //                            public boolean isDisposed() {
101 //                                return false;
102 //                            }
103 //                            
104 //                        }));
105                         
106                     }
107
108                     @Override
109                     public void exception(AsyncReadGraph graph, Throwable throwable) {
110                         throwable.printStackTrace();
111                         assert(false);
112                     }
113
114                     @Override
115                     public boolean isDisposed() {
116                         return false;
117                     }
118                     
119                 });
120                 
121             }
122             
123         });
124         
125         }
126
127 }