use of org.jpox.samples.one_one.unidir_2.MediaWork in project tests by datanucleus.
the class ExtentTest method testExtentOfSubclassTable.
/**
* Test the use of extents with a class using "subclass-table" inheritance strategy.
*/
public void testExtentOfSubclassTable() throws Exception {
try {
// Create some objects.
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Newspaper paper = new Newspaper("Daily Vermin", 2, "George Bush", "Sleaze");
Magazine mag = new Magazine("Buenos Dias", 4, "Cachorro sa");
pm.makePersistent(paper);
pm.makePersistent(mag);
tx.commit();
} catch (JDOUserException ue) {
assertTrue("Exception thrown during create of objects using subclass-table inheritance", false);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Try to get extent of ExtentSub (superclass of both objects, using subclass-table)
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Extent<MediaWork> e = pm.getExtent(MediaWork.class, true);
int number = 0;
Iterator<MediaWork> iter = e.iterator();
while (iter.hasNext()) {
iter.next();
number++;
}
assertEquals("Extent for classes with subclass-table inheritance strategy returned incorrect number of objects", number, 2);
tx.commit();
} catch (Exception e) {
LOG.error("Exception thrown for Extent of class using subclass-table", e);
e.printStackTrace();
fail("Exception was thrown when requesting Extent of class using subclass-table inheritance strategy");
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out created data
clean(Newspaper.class);
clean(Magazine.class);
}
}
Aggregations