/**
* Copyright (C) 2001-2006 France Telecom R&D
*/
package relation.one_to_one;
import org.objectweb.util.monolog.api.BasicLevel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import common.MainHelper;
public class Main extends MainHelper {
public static void main(String[] args) {
new Main().init(args).run().end();
}
public MainHelper run() {
final int nbFoo = 4;
List foos = new ArrayList(nbFoo);
List bars = new ArrayList(nbFoo);
for (int i = 0; i < nbFoo; i++) {
Foo f = new Foo();
f.setFooId("foo_" + i);
foos.add(f);
Bar b = new Bar();
b.setBarId("bar_" + i);
bars.add(b);
f.setBar(b);
}
logger.log(BasicLevel.INFO, "Create " + nbFoo + "' foos and bars :" + foos + bars);
PersistenceManager pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
pm.makePersistentAll(foos);
pm.currentTransaction().commit();
logger.log(BasicLevel.INFO, "Empty Cache.");
foos.clear();
pm.evictAll();
pm.currentTransaction().begin();
Query q = pm.newQuery(Foo.class);
Collection c = (Collection) q.execute();
for (Iterator it = c.iterator(); it.hasNext();) {
Foo f = (Foo) it.next();
foos.add(f);
foos.add(f.getBar());
}
q.closeAll();
logger.log(BasicLevel.INFO, "Deleting " + foos.size() + " Foos and Bars.");
pm.deletePersistentAll(foos);
pm.currentTransaction().commit();
pm.close();
return this;
}
}