Examples of ModRuntimeTest1


Examples of org.apache.openjpa.persistence.kernel.common.apps.ModRuntimeTest1

    }

    public void doCollectionTest(boolean newPC, int before, int after) {
        OpenJPAEntityManager pm = getPM();
        startTx(pm);
        ModRuntimeTest1 pc = new ModRuntimeTest1("orig", 1);
        ModRuntimeTest1 pc2 = newElement(pc, "persist", 2);
        ModRuntimeTest1 pc3 = newElement(pc, "delete", 3);
        pm.persist(pc);
        pm.persist(pc3);
        Object oid = pm.getObjectId(pc);
        ModRuntimeTest1 temp;
        if (!newPC) {
            endTx(pm);
            endEm(pm);

            pm = getPM();
            startTx(pm);
            pc = pm.find(ModRuntimeTest1.class, oid);
            assertEquals(2, pc.getSelfOneMany().size());
            for (Iterator it = pc.getSelfOneMany().iterator(); it.hasNext();) {
                temp = (ModRuntimeTest1) it.next();
                if (temp.getIntField() == 2)
                    pc2 = temp;
                else if (temp.getIntField() == 3)
                    pc3 = temp;
                else
                    fail("unknown");
            }
        }

        for (int i = 0; i < before; i++) {
            newElement(pc, "before" + i, (i + 1) * 10);
            pm.setSavepoint("before" + i);
        }
        pm.setSavepoint("test");
        pm.remove(pc3);
        pc.getSelfOneMany().remove(pc2);

        // kodo 4 is more stringent on deleted relations.
        pc.getSelfOneMany().remove(pc3);
        pc2.setSelfOneMany(null);

        for (int i = 0; i < after; i++) {
            newElement(pc, "after" + i, (i + 1) * -10);
            pm.setSavepoint("after" + i);
        }

        pm.rollbackToSavepoint("test");

        assertEquals("orig", pc.getStringField());
        assertFalse(pm.isRemoved(pc2));
        for (Iterator it = pc.getSelfOneMany().iterator(); it.hasNext();) {
            temp = (ModRuntimeTest1) it.next();
            assertFalse(pm.isRemoved(temp));
            assertEquals(pc, temp.getSelfOneOne());
            if (temp.getIntField() < 0)
                fail("shouldn't be here:" + temp.getStringField());
        }
        assertTrue(pc.getSelfOneMany().contains(pc2));
        assertTrue(pc.getSelfOneMany().contains(pc3));
        assertEquals(2 + before, pc.getSelfOneMany().size());
        endTx(pm);
        endEm(pm);

        pm = getPM();
        pc = pm.find(ModRuntimeTest1.class, oid);
        assertEquals("orig", pc.getStringField());
        assertEquals(2 + before, pc.getSelfOneMany().size());
        boolean found2 = false;
        boolean found3 = false;
        for (Iterator it = pc.getSelfOneMany().iterator(); it.hasNext();) {
            temp = (ModRuntimeTest1) it.next();
            assertEquals(pc, temp.getSelfOneOne());
            if (temp.getIntField() < 0)
                fail("shouldn't be here:" + temp.getStringField());
            else if (temp.getIntField() == 2)
                found2 = true;
            else if (temp.getIntField() == 3)
                found3 = true;
        }
        assertTrue(found2 && found3);
        endEm(pm);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.