01: /**
02: * Copyright (C) 2001-2004 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.odis;
18:
19: import org.objectweb.speedo.SpeedoTestHelper;
20: import org.objectweb.speedo.pobjects.odis.Concurrent;
21:
22: import javax.jdo.PersistenceManager;
23: import javax.jdo.Query;
24: import javax.jdo.Extent;
25: import java.util.Collection;
26: import java.util.Iterator;
27: import java.util.Calendar;
28: import java.sql.Time;
29:
30: /**
31: *
32: * @author S.Chassande-Barrioz
33: */
34: public class TestConcurrent extends SpeedoTestHelper {
35:
36: public TestConcurrent(String s) {
37: super (s);
38: }
39:
40: protected String getLoggerName() {
41: return LOG_NAME + "rt.odis.TestConcurrent";
42: }
43:
44: public void testA() {
45: PersistenceManager pm = pmf.getPersistenceManager();
46: int nbobj = 10;
47: Concurrent[] cs = new Concurrent[nbobj];
48: for (int i = 0; i < nbobj; i++) {
49: cs[i] = new Concurrent(i + 10, "d" + i, new Time(Calendar
50: .getInstance().getTimeInMillis()));
51: }
52: pm.makePersistentAll(cs);
53: pm.close();
54:
55: pm = pmf.getPersistenceManager();
56: Query q = pm.newQuery(Concurrent.class);
57: q.setFilter("(dossard==p1)");
58: q.declareParameters("String p1");
59: Collection col = (Collection) q.execute("d3");
60: Iterator it = col.iterator();
61: while (it.hasNext()) {
62: Concurrent c = (Concurrent) it.next();
63: System.out.println("concurrent : cid=" + c.getCid()
64: + ", dossard=" + c.getDossard() + ", temps="
65: + c.getTemps());
66: }
67: q.closeAll();
68: pm.close();
69:
70: pm = pmf.getPersistenceManager();
71: pm.currentTransaction().begin();
72: Extent e = pm.getExtent(Concurrent.class, false);
73: it = e.iterator();
74: while (it.hasNext()) {
75: pm.deletePersistent(it.next());
76: }
77: pm.currentTransaction().commit();
78: pm.close();
79: }
80:
81: }
|