Search in sources :

Example 1 with Module

use of org.jpox.samples.abstractclasses.self.Module in project tests by datanucleus.

the class AbstractClassesTest method testAbstractWithCollection.

/**
 * Test of a complex self-referencing assembly, with collections of abstract objects
 */
public void testAbstractWithCollection() {
    Object id = null;
    try {
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            Module module = new Module();
            pm.makePersistent(module);
            tx.commit();
            id = pm.getObjectId(module);
            tx.begin();
            Extent extent = pm.getExtent(Module.class, true);
            Iterator mods = extent.iterator();
            Module mod = (Module) mods.next();
            mod.getRoot().traverse(1);
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
    } finally {
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            Module mod = (Module) pm.getObjectById(id);
            // Clears all relations
            mod.clearRoot();
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        clean(Module.class);
        clean(ComplexAssembly.class);
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) Extent(javax.jdo.Extent) Iterator(java.util.Iterator) Module(org.jpox.samples.abstractclasses.self.Module)

Aggregations

Iterator (java.util.Iterator)1 Extent (javax.jdo.Extent)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 Module (org.jpox.samples.abstractclasses.self.Module)1