for (int i = 0; i < NB_WORKER; i++) {
Address a = new Address("w_street_" + i,
"w_city_" + i,
"w_state_" + i,
"w_zipcode_" + i);
Worker w = new Worker("worker_fn_" + i, "worker_ln_" + i, a, d,
"jobName_" + i, "company_" + i, (float) (i * 2000.0));
pm.makePersistent(w);
}
pm.currentTransaction().commit();
pm.evictAll();
pm.close();
//find worker only
pm = pmf.getPersistenceManager();
pm.currentTransaction().begin();
Query q = pm.newQuery(Worker.class);
q.setOrdering("firstname ascending");
Collection c = (Collection) q.execute();
int cpt = 0;
try {
for (Iterator it = c.iterator(); it.hasNext();) {
Worker w = (Worker) it.next();
assertEquals("Bad worker first name",
"worker_fn_" + cpt, w.getFirstname());
cpt ++;
}
assertEquals("Bad worker number", NB_WORKER, cpt);
} finally {
q.closeAll();