use of org.datanucleus.samples.store.CompactDisc in project tests by datanucleus.
the class ExtentTest method testExtentOfNewTable.
/**
* Test the use of extents with a class using "new-table" inheritance strategy.
*/
public void testExtentOfNewTable() throws Exception {
try {
// Create some objects.
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
CompactDisc cd = new CompactDisc("ABC", "Greatest Hits", "CD of our greatest hits", "http://www.jpox.org", "GBP", 10.00, 10.00, 10.00, 17.5, 1, "JPOX", "Greatest Hits", 2006, "JPOX Production", "JPOX Publishing");
Book book = new Book("DEF", "Long Stories", "Book of long stories", "http://www.amazon.com", "EUR", 5.99, 5.99, 5.99, 12.0, 2, "54321672578", "John Storyteller", "Long stories", 1, "McGraw Hill");
pm.makePersistent(cd);
pm.makePersistent(book);
tx.commit();
} catch (JDOUserException ue) {
assertTrue("Exception thrown during create of objects using new-table inheritance", false);
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
// Try to get extent of base class
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
Extent<Product> e = pm.getExtent(Product.class, true);
int number = 0;
Iterator<Product> iter = e.iterator();
while (iter.hasNext()) {
iter.next();
number++;
}
assertEquals("Extent for classes with new-table inheritance strategy returned incorrect number of objects", number, 2);
tx.commit();
} catch (Exception e) {
fail("Exception was thrown when requesting Extent of class using new-table inheritance strategy");
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
} finally {
// Clean out created data
clean(CompactDisc.class);
clean(Book.class);
}
}
Aggregations