Search in sources :

Example 1 with ElementE

use of org.jpox.samples.models.inheritance_mapped_collection.ElementE in project tests by datanucleus.

the class RelationshipTest method test1toNMappedByWithInheritance2.

/**
 * Test 1-N having a subclass on the source side (1=source, N=target) with the subclass having the
 * Set field.
 */
public void test1toNMappedByWithInheritance2() {
    try {
        addClassesToSchema(new Class[] { ContainerInheritanceRoot.class, ContainerInheritanceSub.class, ElementE.class });
        // Persist some objects
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        try {
            tx.begin();
            String orgaID = "test.jpox.org";
            ContainerInheritanceSub c0 = new ContainerInheritanceSub(orgaID, "abcxyz001");
            c0.setE(new ElementE(orgaID, 0, c0));
            ElementE e1 = new ElementE(orgaID, 1, c0);
            e1.setCollectionOwner(c0);
            c0.getEs().add(e1);
            ElementE e2 = new ElementE(orgaID, 2, c0);
            e2.setCollectionOwner(c0);
            c0.getEs().add(e2);
            pm.makePersistent(c0);
            tx.commit();
        } catch (Exception e) {
            LOG.error(">> Exception thrown persisting objects : ", e);
            fail("Could not persist objects! " + e.getMessage());
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
        }
        pm.close();
    } finally {
        // Clean up our data
        PersistenceManager pm = pmf.getPersistenceManager();
        Transaction tx = pm.currentTransaction();
        try {
            // Disconnect all relations
            tx.begin();
            Extent ex = pm.getExtent(ContainerInheritanceSub.class);
            Iterator containerIter = ex.iterator();
            while (containerIter.hasNext()) {
                ContainerInheritanceSub cont = (ContainerInheritanceSub) containerIter.next();
                ElementE e = cont.getE();
                cont.setE(null);
                e.setCollectionOwner(null);
                cont.getEs().clear();
            }
            tx.commit();
        } finally {
            if (tx.isActive()) {
                tx.rollback();
            }
            pm.close();
        }
        clean(ElementE.class);
        clean(ContainerInheritanceSub.class);
    }
}
Also used : ElementE(org.jpox.samples.models.inheritance_mapped_collection.ElementE) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) Extent(javax.jdo.Extent) Iterator(java.util.Iterator) ContainerInheritanceSub(org.jpox.samples.models.inheritance_mapped_collection.ContainerInheritanceSub)

Aggregations

Iterator (java.util.Iterator)1 Extent (javax.jdo.Extent)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 ContainerInheritanceSub (org.jpox.samples.models.inheritance_mapped_collection.ContainerInheritanceSub)1 ElementE (org.jpox.samples.models.inheritance_mapped_collection.ElementE)1