/**
* Copyright (C) 2001-2004 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.objectweb.speedo.runtime.odis;
import org.objectweb.speedo.SpeedoTestHelper;
import org.objectweb.speedo.pobjects.odis.Concurrent;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Extent;
import java.util.Collection;
import java.util.Iterator;
import java.util.Calendar;
import java.sql.Time;
/**
*
* @author S.Chassande-Barrioz
*/
public class TestConcurrent extends SpeedoTestHelper {
public TestConcurrent(String s) {
super(s);
}
protected String getLoggerName() {
return LOG_NAME + "rt.odis.TestConcurrent";
}
public void testA() {
PersistenceManager pm = pmf.getPersistenceManager();
int nbobj = 10;
Concurrent[] cs = new Concurrent[nbobj];
for(int i=0; i<nbobj ; i++) {
cs[i] = new Concurrent(i + 10, "d" + i,
new Time(Calendar.getInstance().getTimeInMillis()));
}
pm.makePersistentAll(cs);
pm.close();
pm = pmf.getPersistenceManager();
Query q = pm.newQuery(Concurrent.class);
q.setFilter("(dossard==p1)");
q.declareParameters("String p1");
Collection col = (Collection) q.execute("d3");
Iterator it = col.iterator();
while(it.hasNext()) {
Concurrent c = (Concurrent) it.next();
System.out.println("concurrent : cid=" + c.getCid()
+ ", dossard=" + c.getDossard()
+ ", temps=" + c.getTemps());
}
q.closeAll();
pm.close();
pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Extent e = pm.getExtent(Concurrent.class, false);
it = e.iterator();
while(it.hasNext()) {
pm.deletePersistent(it.next());
}
pm.currentTransaction().commit();
pm.close();
}
}