KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > query > TestCursor


1 /**
2  * Copyright (C) 2001-2005 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package org.objectweb.speedo.runtime.query;
19
20 import java.util.Collection JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.jdo.PersistenceManager;
24 import javax.jdo.Query;
25
26 import org.objectweb.speedo.SpeedoTestHelper;
27 import org.objectweb.speedo.pobjects.ref.cursor.MesProduits;
28 import org.objectweb.util.monolog.api.BasicLevel;
29
30
31 /**
32  *
33  *
34  * @author Y.Bersihand
35  */

36 public class TestCursor extends SpeedoTestHelper {
37
38     public TestCursor() {
39         super("TestCursor");
40     }
41     
42     public TestCursor(String JavaDoc n) {
43         super(n);
44     }
45     
46     protected String JavaDoc getLoggerName() {
47         return SpeedoTestHelper.LOG_NAME + ".TestCursor";
48     }
49     
50     /**
51      * Test to check that database cursors
52      * are closed when closing the query and the pm.
53      */

54     public void testCursorOpen() {
55         logger.log(BasicLevel.INFO, "testCursorOpen");
56         PersistenceManager pm = pmf.getPersistenceManager();
57         Query query=pm.newQuery(MesProduits.class);
58         query.setFilter("(catalogue.startsWith( param1))");
59         query.declareParameters("String param1");
60         Collection JavaDoc results = (Collection JavaDoc)query.execute("catalogue");
61         Iterator JavaDoc it=results.iterator() ;
62         MesProduits monProduit= null;
63         while (it.hasNext()){
64             monProduit = (MesProduits) it.next();
65             System.out.println("MesProduits catalogue* : "+monProduit.toString());
66         }
67         query.closeAll();
68         pm.close();
69         
70         try {
71             logger.log(BasicLevel.DEBUG, "Wait for 10 seconds...");
72             Thread.sleep(10000);
73         } catch (InterruptedException JavaDoc e1) {
74             e1.printStackTrace();
75         }
76     }
77 }
78
Popular Tags