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

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


        deleteAll();

        OpenJPAEntityManager pm = getPM();
        startTx(pm);
        AttachB b = new AttachB();
        pm.persist(b);
        b.setAint(5);
        b.setBstr("5");
        b.getStringIntMap().put("5", new Integer(5));

        AttachE e = new AttachE();
        e.setEstr("E");
        e.setEint(5);

        AttachD d = new AttachD();
        d.setDint(5);
        d.setEmbeddedE(e);
        b.getDs().add(d);

        pm.persist(d);

        oid = b.getId();
        doid = d.getId();
        endTx(pm);
        endEm(pm);
    }
View Full Code Here


        endEm(pm);
    }

    public void testDetach() {
        OpenJPAEntityManager pm = getPM();
        AttachB b = pm.find(AttachB.class, oid);

        assertNotNull("b is null in testDetach", b);

        b = (AttachB) pm.detach(b);
        endEm(pm);

        assertTrue(pm.isDetached(b));
        assertEquals(5, b.getAint());
        assertEquals("5", b.getBstr());
        assertNull(b.getStringIntMap());

        b.setAint(12);
        b.setBstr("12");
        TreeMap map = new TreeMap();
        map.put("12", new Integer(12));
        b.setStringIntMap(map);

        pm = getPM();
        startTx(pm);
        AttachB attached = (AttachB) pm.merge(b);
        assertEquals(12, attached.getAint());
        assertEquals("12", attached.getBstr());
        assertNull(attached.getStringIntMap().get("12"));
        assertEquals(new Integer(5), attached.getStringIntMap().get("5"));
        endTx(pm);
        endEm(pm);

        pm = getPM();
        b = pm.find(AttachB.class, oid);
View Full Code Here

        OpenJPAEntityManager pm = getPM();
        //FIXME jthomas
//        pm.getFetchPlan().setDetachmentOptions(FetchPlanImpl.DETACH_LOAD_FIELDS | FetchPlanImpl.DETACH_UNLOAD_FIELDS);
        pm.setDetachState(DetachStateType.FETCH_GROUPS);
        pm.getFetchPlan().addFetchGroup("all");
        AttachB b = pm.find(AttachB.class, oid);

        assertNotNull("b is null in testDetachWithGroups", b);

        b = (AttachB) pm.detach(b);
        endEm(pm);

        assertTrue(pm.isDetached(b));
        assertEquals("b.getAint() not 5", 5, b.getAint());
        assertEquals("b.getAint() not 5str", "5", b.getBstr());
        assertEquals("b.getStringIntMap().size() not equal to 1", 1,
            b.getStringIntMap().size());

        b.setAint(12);
        b.setBstr("12");
        b.getStringIntMap().put("12", new Integer(12));

        pm = getPM();
        startTx(pm);
        AttachB attached = (AttachB) pm.merge(b);
        assertEquals("not 12", 12, attached.getAint());
        assertEquals("not 12str", "12", attached.getBstr());
        assertEquals("not newInteger(12)", new Integer(12),
            attached.getStringIntMap().get("12"));
        assertEquals("not newInteger(5)", new Integer(5),
            attached.getStringIntMap().get("5"));
        endTx(pm);
        endEm(pm);

        pm = getPM();
        b = (AttachB) pm.find(AttachB.class, oid);
View Full Code Here

        endEm(pm);
    }

    public void testDetachNoOverwrite() {
        OpenJPAEntityManager pm = getPM();
        AttachB b = (AttachB) pm.find(AttachB.class, oid);
        b = (AttachB) pm.detach(b);
        endEm(pm);

        b.setBstr("12");

        pm = getPM();
        startTx(pm);
        AttachB orig = pm.find(AttachB.class, oid);
        orig.setAint(50);

        AttachB attached = (AttachB) pm.merge(b);
        assertEquals(attached, orig);
        assertEquals(50, attached.getAint());
        assertEquals("12", attached.getBstr());
        endTx(pm);
        endEm(pm);

        pm = getPM();
        b = (AttachB) pm.find(AttachB.class, oid);
View Full Code Here

        endEm(pm);
    }

    public void testOptimisticLock() {
        OpenJPAEntityManager pm = getPM();
        AttachB b = (AttachB) pm.find(AttachB.class, oid);

        assertNotNull("b is null in testOptimisticLock", b);

        b = (AttachB) pm.detach(b);
        endEm(pm);

        b.setAint(12);
        b.setBstr("12");
        TreeMap map = new TreeMap();
        map.put("12", new Integer(12));
        b.setStringIntMap(map);

        pm = getPM();
        startTx(pm);
        AttachB b2 = (AttachB) pm.find(AttachB.class, oid);
        b2.setAint(15);
        endTx(pm);
        endEm(pm);

        pm = getPM();
        startTx(pm);
View Full Code Here

        endEm(pm);
    }

    public void testNullCollection() {
        OpenJPAEntityManager pm = getPM();
        AttachB b = (AttachB) pm.find(AttachB.class, oid);
        b.getDs();
        b = (AttachB) pm.detach(b);
        endEm(pm);

        assertEquals(1, b.getDs().size());
        b.setDs(null);

        pm = getPM();
        startTx(pm);
        b = (AttachB) pm.merge(b);
        assertNull(b.getDs());
        endTx(pm);
        endEm(pm);

        pm = getPM();
        b = (AttachB) pm.find(AttachB.class, oid);
        assertTrue(b.getDs() == null || b.getDs().size() == 0);
        endEm(pm);
    }
View Full Code Here

        doCollectionTest(true);
    }

    private void doCollectionTest(boolean remove) {
        OpenJPAEntityManager pm = getPM();
        AttachB b = (AttachB) pm.find(AttachB.class, oid);

        assertNotNull("b is null in doCollectionTest", b);
        b.getDs();
        b = (AttachB) pm.detach(b);
        endEm(pm);

        assertEquals("b is null in doCollectionTest", 1, b.getDs().size());
        if (remove) {
            for (Iterator it = b.getDs().iterator(); it.hasNext();) {
                it.next();
                it.remove();
            }
        }
        AttachD d = new AttachD();
        d.setDint(12);
        b.getDs().add(d);

        pm = getPM();
        startTx(pm);
        b = (AttachB) pm.merge(b);
        assertSize(remove ? 1 : 2, b.getDs());
        endTx(pm);
        endEm(pm);

        pm = getPM();
        b = (AttachB) pm.find(AttachB.class, oid);
        assertSize(remove ? 1 : 2, b.getDs());
        boolean found1 = false;
        boolean found2 = false;
        for (Iterator it = b.getDs().iterator(); it.hasNext();) {
            d = (AttachD) it.next();
            switch (d.getDint()) {
                case 5:
                    if (found1)
                        fail("Refound.");
View Full Code Here

        OpenJPAEntityManager pm;

        pm = getPM();
        startTx(pm);
        AttachE e = new AttachE();
        AttachB b = new AttachB();
        e.setB(b);
        pm.persist(e);

        endTx(pm);
        endEm(pm);
View Full Code Here

     */
    public void testFetchGroupInstantiated() {
        OpenJPAEntityManager pm = getPM();
        startTx(pm);
        AttachE e = new AttachE();
        AttachB b = new AttachB();
        e.setB(b);
        pm.persist(e);

        endTx(pm);
        endEm(pm);
View Full Code Here

        deleteAll();

        OpenJPAEntityManager pm = getPM();
        startTx(pm);
        AttachB b = new AttachB();
        pm.persist(b);
        b.setAint(5);
        b.setBstr("5");
        b.getStringIntMap().put("5", new Integer(5));

        AttachE e = new AttachE();
        e.setEstr("E");
        e.setEint(5);

        AttachD d = new AttachD();
        d.setDint(5);
        d.setEmbeddedE(e);
        b.getDs().add(d);

        pm.persist(d);

        oid = b.getId();
        doid = d.getId();
        endTx(pm);
        endEm(pm);
    }
View Full Code Here

TOP

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

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.