Package org.apache.openjpa.persistence.kernel.common.apps

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


        assertEquals(8, pc.getRuntimeTest5s().size());
        endEm(pm);
    }

    private ModRuntimeTest1 newElement(ModRuntimeTest1 one, String str, int i) {
        ModRuntimeTest1 two = new ModRuntimeTest1(str, i);
        two.setSelfOneOne(one);
        one.getSelfOneMany().add(two);
        return two;
    }
View Full Code Here

        OpenJPAEntityManager pm = getPM(true, false);
        startTx(pm);
        ModInstanceCallbackTests a = new ModInstanceCallbackTests("foo", 10);
        pm.persist(a);

        ModRuntimeTest1 parent = new ModRuntimeTest1("baz", 11);
        if (!before)
            pm.flush();

        if (persist)
            pm.persist(parent);

        a.setOneOne(parent);

        if (before)
            pm.flush();

        ModRuntimeTest1 oldParent = null;
        if (multi) {
            oldParent = parent;
            parent = new ModRuntimeTest1("newParent", 12);

            if (!before)
                pm.flush();

            if (persist)
View Full Code Here

    }

    public void testDeleteNew() {
        OpenJPAEntityManager pm = getPM(true, false);
        startTx(pm);
        ModRuntimeTest1 a = new ModRuntimeTest1("foo", 10);
        pm.persist(a);
        pm.remove(a);
        assertState(a, PCState.PNEWDELETED, pm);
    }
View Full Code Here

    public void testOptimisticLockGivesCorrectError() {
        OpenJPAEntityManager pm1 = getPM(true, false);
        OpenJPAEntityManager pm2 = getPM(true, false);

        ModRuntimeTest1 a1 = new ModRuntimeTest1("foo", 10);
        startTx(pm1);
        pm1.persist(a1);
        endTx(pm1);

        ModRuntimeTest1 a2 = (ModRuntimeTest1)
            pm2.find(ModRuntimeTest1.class, pm2.getObjectId(a1));
        startTx(pm2);
        a2.setStringField("foobar");
        endTx(pm2);

        startTx(pm1);
        a1.setStringField("foobarbaz");
        try {
View Full Code Here

        assertSize(0, flushPM.createNativeQuery("stringField == '" + name + "'",
            ModRuntimeTest1.class));
        assertSize(0, readPM.createNativeQuery("stringField == '" + name + "'",
            ModRuntimeTest1.class));

        ModRuntimeTest1 a = new ModRuntimeTest1(name, randomInt().intValue());

        flushPM.persist(a);

        assertSize(0, readPM.createNativeQuery("name == '" + name + "'",
            ModRuntimeTest1.class));
View Full Code Here

    public void testEmptyFlush() {
        OpenJPAEntityManager pm = getPM();
        TListener listener = new TListener();
        ((OpenJPAEntityManagerSPI) pm).addTransactionListener(listener);
        startTx(pm);
        ModRuntimeTest1 pc = new ModRuntimeTest1();
        pm.persist(pc);
        pm.flush();
        assertEquals(1, listener.flushes);
        assertEquals(0, listener.commits);

        pm.flush();
        assertEquals(1, listener.flushes);
        assertEquals(0, listener.commits);

        pc.setIntField(3);
        pm.flush();
        assertEquals(2, listener.flushes);
        assertEquals(0, listener.commits);

        endTx(pm);
View Full Code Here

        _meta.getField(1).setUsesImplData(_f1);
        _meta.getField(3).setUsesImplData(_f3);
    }

    public void testImplData() {
        ModRuntimeTest1 pc = new ModRuntimeTest1();

        OpenJPAEntityManager pm = getPM(false, false);
        startTx(pm);
        pm.persist(pc);
        OpenJPAStateManager sm = getStateManager(pc, pm);
View Full Code Here

        notClearedIfRetainValuesTest(true);
        notClearedIfRetainValuesTest(false);
    }

    private void notClearedIfRetainValuesTest(boolean optimistic) {
        ModRuntimeTest1 pc = new ModRuntimeTest1("pc", 1);
        int key = 1;
        Object value = new Object();

        // make instance persistent
        OpenJPAEntityManager pm = getPM(optimistic, true);
View Full Code Here

        OpenJPAEntityManager pm = getPM(false, false);
        startTx(pm);

        ModRuntimeTest2 b =
            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
        ModRuntimeTest1 parent = b.getSelfOneOne();
        pm.remove(b);
        assertPersistent(b, true, false, true, true);
        assertPersistent(parent, true, false, false, false);

        endTx(pm);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.persistence.kernel.common.apps.ModRuntimeTest1

Copyright © 2018 www.massapicom. 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.