Search in sources :

Example 1 with MixedGeneratorItemSub

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);
    }
}
Also used : MixedGeneratorItemSub(org.jpox.samples.valuegeneration.MixedGeneratorItemSub) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) Iterator(java.util.Iterator) Collection(java.util.Collection) JDOUserException(javax.jdo.JDOUserException)

Aggregations

Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 JDOUserException (javax.jdo.JDOUserException)1 PersistenceManager (javax.jdo.PersistenceManager)1 Query (javax.jdo.Query)1 Transaction (javax.jdo.Transaction)1 MixedGeneratorItemSub (org.jpox.samples.valuegeneration.MixedGeneratorItemSub)1