use of org.jpox.samples.compoundidentity.CompoundMapTarget in project tests by datanucleus.
the class CompoundIdentityTest method testOneToManyMapBiKeyInValue.
/**
* Test of compound identity 1-N relations with a map using ForeignKey and the map key stored in the value.
*/
public void testOneToManyMapBiKeyInValue() {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
CompoundMapTarget[] values = new CompoundMapTarget[6];
try {
tx.begin();
CompoundHolder holder1 = new CompoundHolder("First Holder");
values[0] = new CompoundMapTarget("First", holder1, 1.0);
values[1] = new CompoundMapTarget("Second", holder1, 2.0);
values[2] = new CompoundMapTarget("Third", holder1, 3.0);
values[3] = new CompoundMapTarget("Fourth", holder1, 4.0);
values[4] = new CompoundMapTarget("Fifth", holder1, 5.0);
values[5] = new CompoundMapTarget("Sixth", holder1, 6.0);
for (int i = 0; i < 6; i++) {
holder1.getMap1().put(values[i].getName(), values[i]);
}
pm.makePersistent(holder1);
tx.commit();
id = pm.getObjectId(holder1);
tx.begin();
CompoundHolder holder2 = (CompoundHolder) pm.getObjectById(id, true);
assertEquals(6, holder2.getMap1().size());
assertEquals(values[0], holder2.getMap1().get("First"));
assertEquals(values[1], holder2.getMap1().get("Second"));
assertEquals(values[2], holder2.getMap1().get("Third"));
assertEquals(values[3], holder2.getMap1().get("Fourth"));
assertEquals(values[4], holder2.getMap1().get("Fifth"));
assertEquals(values[5], holder2.getMap1().get("Sixth"));
tx.commit();
} catch (Exception e) {
LOG.error(e);
e.printStackTrace();
fail(e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
clean(CompoundHolder.class);
clean(CompoundMapTarget.class);
}
}
Aggregations