KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > runtime > odis > TestConcurrent


1 /**
2  * Copyright (C) 2001-2004 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.odis;
19
20 import org.objectweb.speedo.SpeedoTestHelper;
21 import org.objectweb.speedo.pobjects.odis.Concurrent;
22
23 import javax.jdo.PersistenceManager;
24 import javax.jdo.Query;
25 import javax.jdo.Extent;
26 import java.util.Collection JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Calendar JavaDoc;
29 import java.sql.Time JavaDoc;
30
31 /**
32  *
33  * @author S.Chassande-Barrioz
34  */

35 public class TestConcurrent extends SpeedoTestHelper {
36
37     public TestConcurrent(String JavaDoc s) {
38         super(s);
39     }
40
41     protected String JavaDoc getLoggerName() {
42         return LOG_NAME + "rt.odis.TestConcurrent";
43     }
44
45     public void testA() {
46         PersistenceManager pm = pmf.getPersistenceManager();
47         int nbobj = 10;
48         Concurrent[] cs = new Concurrent[nbobj];
49         for(int i=0; i<nbobj ; i++) {
50             cs[i] = new Concurrent(i + 10, "d" + i,
51                 new Time JavaDoc(Calendar.getInstance().getTimeInMillis()));
52         }
53         pm.makePersistentAll(cs);
54         pm.close();
55
56         pm = pmf.getPersistenceManager();
57         Query q = pm.newQuery(Concurrent.class);
58         q.setFilter("(dossard==p1)");
59         q.declareParameters("String p1");
60         Collection JavaDoc col = (Collection JavaDoc) q.execute("d3");
61         Iterator JavaDoc it = col.iterator();
62         while(it.hasNext()) {
63             Concurrent c = (Concurrent) it.next();
64             System.out.println("concurrent : cid=" + c.getCid()
65                 + ", dossard=" + c.getDossard()
66                 + ", temps=" + c.getTemps());
67         }
68         q.closeAll();
69         pm.close();
70
71         pm = pmf.getPersistenceManager();
72         pm.currentTransaction().begin();
73         Extent e = pm.getExtent(Concurrent.class, false);
74         it = e.iterator();
75         while(it.hasNext()) {
76             pm.deletePersistent(it.next());
77         }
78         pm.currentTransaction().commit();
79         pm.close();
80     }
81
82 }
83
Popular Tags