use of org.jpox.samples.valuegeneration.MixedGeneratorItemSub in project tests by datanucleus.
the class ValueGeneratorTest method testMixedGeneratorInherited.
/**
* Test the use of multiple "value-strategy" fields with inheritance
*/
public void testMixedGeneratorInherited() throws Exception {
try {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// Create a few objects.
MixedGeneratorItemSub item = null;
item = new MixedGeneratorItemSub();
pm.makePersistent(item);
item = new MixedGeneratorItemSub();
pm.makePersistent(item);
item = new MixedGeneratorItemSub();
pm.makePersistent(item);
item = new MixedGeneratorItemSub();
pm.makePersistent(item);
tx.commit();
JDOHelper.getObjectId(item).getClass();
} catch (JDOUserException e) {
fail("Exception thrown during insert of objects in mixed generators test " + e.getMessage());
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
// Retrieve the items
Query q = pm.newQuery(pm.getExtent(MixedGeneratorItemSub.class, true));
Collection c = (Collection) q.execute();
// Check on the number of items
assertTrue("Number of MixedGeneratorItemSub's retrieved is incorrect (" + c.size() + ") : should have been 4", c.size() == 4);
Iterator iter = c.iterator();
while (iter.hasNext()) {
iter.next();
}
tx.commit();
} catch (JDOUserException ue) {
assertTrue("Exception thrown during test " + ue.getMessage(), false);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out any data we have created
clean(MixedGeneratorItemSub.class);
}
}
Aggregations