01: /**
02: * Copyright (C) 2001-2005 France Telecom R&D
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * 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: */package org.objectweb.speedo.runtime.query;
18:
19: import java.util.Collection;
20: import java.util.Iterator;
21:
22: import javax.jdo.PersistenceManager;
23: import javax.jdo.Query;
24:
25: import org.objectweb.speedo.SpeedoTestHelper;
26: import org.objectweb.speedo.pobjects.ref.cursor.MesProduits;
27: import org.objectweb.util.monolog.api.BasicLevel;
28:
29: /**
30: *
31: *
32: * @author Y.Bersihand
33: */
34: public class TestCursor extends SpeedoTestHelper {
35:
36: public TestCursor() {
37: super ("TestCursor");
38: }
39:
40: public TestCursor(String n) {
41: super (n);
42: }
43:
44: protected String getLoggerName() {
45: return SpeedoTestHelper.LOG_NAME + ".TestCursor";
46: }
47:
48: /**
49: * Test to check that database cursors
50: * are closed when closing the query and the pm.
51: */
52: public void testCursorOpen() {
53: logger.log(BasicLevel.INFO, "testCursorOpen");
54: PersistenceManager pm = pmf.getPersistenceManager();
55: Query query = pm.newQuery(MesProduits.class);
56: query.setFilter("(catalogue.startsWith( param1))");
57: query.declareParameters("String param1");
58: Collection results = (Collection) query.execute("catalogue");
59: Iterator it = results.iterator();
60: MesProduits monProduit = null;
61: while (it.hasNext()) {
62: monProduit = (MesProduits) it.next();
63: System.out.println("MesProduits catalogue* : "
64: + monProduit.toString());
65: }
66: query.closeAll();
67: pm.close();
68:
69: try {
70: logger.log(BasicLevel.DEBUG, "Wait for 10 seconds...");
71: Thread.sleep(10000);
72: } catch (InterruptedException e1) {
73: e1.printStackTrace();
74: }
75: }
76: }
|