Search in sources :

Example 1 with Circon

use of org.datanucleus.samples.models.hashsetcollection.Circon in project tests by datanucleus.

the class AttachDetachTest method testCircularDetach.

/**
 * Test of detaching object graph with circular references
 */
public void testCircularDetach() {
    PersistenceManager pm = newPM();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Master m = new Master();
        m.setId("tcMaster");
        Detail d = new Detail();
        d.setId("tcDetail");
        Circon c = new Circon();
        c.setId("tcConnector");
        m.addDetail(d);
        m.setCircon(c);
        d.setMaster(m);
        d.addCircon(c);
        c.setDetail(d);
        c.addMaster(m);
        pm.makePersistent(m);
        assertTrue(JDOHelper.isPersistent(m));
        assertTrue(JDOHelper.isPersistent(d));
        assertTrue(JDOHelper.isPersistent(c));
        pm.getFetchPlan().addGroup("all");
        pm.getFetchPlan().setMaxFetchDepth(2);
        Master dm = (Master) pm.detachCopy(m);
        assertTrue(JDOHelper.isDetached(dm));
        assertTrue(JDOHelper.isDetached(dm.getCircon()));
        assertTrue(JDOHelper.isDetached(dm.getCircon().getDetail()));
        tx.rollback();
    } catch (JDOUserException ue) {
        LOG.error("Exception in test", ue);
        fail("Exception thrown while performing test : " + ue.getMessage());
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Master(org.datanucleus.samples.models.hashsetcollection.Master) Transaction(javax.jdo.Transaction) JDOPersistenceManager(org.datanucleus.api.jdo.JDOPersistenceManager) PersistenceManager(javax.jdo.PersistenceManager) Circon(org.datanucleus.samples.models.hashsetcollection.Circon) JDOUserException(javax.jdo.JDOUserException) Detail(org.datanucleus.samples.models.hashsetcollection.Detail)

Aggregations

JDOUserException (javax.jdo.JDOUserException)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)1 Circon (org.datanucleus.samples.models.hashsetcollection.Circon)1 Detail (org.datanucleus.samples.models.hashsetcollection.Detail)1 Master (org.datanucleus.samples.models.hashsetcollection.Master)1