public void testA() {
//Make persitent the a instance
PersistenceManager pm = pmf.getPersistenceManager();
A a = new A(0);
pm.makePersistent(a);
pm.close();
//Add B instances into the map
final int NB_B = 10;
final String IDX_PREFIX = "index2B";
final String F1_PREFIX = "toto";
pm = pmf.getPersistenceManager();
for(int i=0; i<NB_B; i++) {
a.add(IDX_PREFIX + i, new B(i, F1_PREFIX + i));
}
pm.close();
//Clear the cache
a = null; //permit the GC to garbage instances
pm = pmf.getPersistenceManager();
pm.evictAll();
pm.close();
//Check the instance existing
pm = pmf.getPersistenceManager();
try {
a = (A) pm.getObjectById(pm.newObjectIdInstance(A.class, "" + 0), false);
} catch (JDOException e) {
fail("The A instance is not found on the data support");
}
Collection names = a.names();
assertNotNull("name collection is null", names);
assertEquals("Bad name collection size", NB_B, names.size());
B[] bs = new B[NB_B];
for(int i=0; i<NB_B; i++) {
String idx = IDX_PREFIX + i;
assertTrue("The name collection does not contain the index: " + idx,
names.contains(idx));
bs[i] = a.getB(idx);
assertNotNull("Null element assocaited to the index " + idx, bs[i]);
assertEquals("Bad F1 value for the element assocaited to the index "
+ idx, F1_PREFIX + i, bs[i].getF1());
}
a.clear();
pm.currentTransaction().begin();
pm.deletePersistentAll(bs);
pm.deletePersistent(a);
pm.currentTransaction().commit();
pm.close();