Examples of ValueStrategyPC


Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

    public void setUp() {
        deleteAll(ValueStrategyPC.class);
    }

    public void testIgnoreUpdate() {
        ValueStrategyPC pc = new ValueStrategyPC();
        pc.setName("pc");
        pc.setIgnoreUpdate(10);

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pm.persist(pc);
        assertEquals(10, pc.getIgnoreUpdate());
        endTx(pm);
        Object oid = pm.getObjectId(pc);
        endEm(pm);

        //pm = getPM(false, false);
        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(10, pc.getIgnoreUpdate());
        startTx(pm);
        pc.setIgnoreUpdate(100);
        assertFalse(pm.isDirty(pc));
        pm.transactional(pc, false);
        endTx(pm);
        assertEquals(10, pc.getIgnoreUpdate());
        endEm(pm);

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(10, pc.getIgnoreUpdate());
        endEm(pm);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        assertEquals(10, pc.getIgnoreUpdate());
        endEm(pm);
    }

    public void testRestrictUpdate() {
        ValueStrategyPC pc = new ValueStrategyPC();
        pc.setName("pc");
        pc.setRestrictUpdate(10);

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pm.persist(pc);
        assertEquals(10, pc.getRestrictUpdate());
        endTx(pm);
        Object oid = pm.getObjectId(pc);
        endEm(pm);

        //pm = getPM(false, false);
        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(10, pc.getRestrictUpdate());
        startTx(pm);
        try {
            pc.setRestrictUpdate(100);
            fail("Allowed update of restricted field.");
        } catch (RuntimeException re) {
        }
        endTx(pm);
        assertEquals(10, pc.getRestrictUpdate());
        endEm(pm);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        assertEquals(10, pc.getRestrictUpdate());
        endEm(pm);
    }

    public void testUUID() {
        ValueStrategyPC pc = new ValueStrategyPC();
        ValueStrategyPC pc2 = new ValueStrategyPC();
        pc.setName("pc");
        pc2.setName("pc2");
        assertNull(pc.getUUID());
        assertNull(pc2.getUUID());
        assertNull(pc.getUUIDHex());
        assertNull(pc2.getUUIDHex());

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        pm.setOptimistic(true);
        startTx(pm);
        pm.persist(pc);
        pm.persist(pc2);
        String str = pc.getUUID();
        String hex = pc.getUUIDHex();
        assertTrue(!pm.isStoreActive());    // no flush needed
        endTx(pm);
        String str2 = pc2.getUUID();
        String hex2 = pc2.getUUIDHex();
        Object oid = pm.getObjectId(pc);
        Object oid2 = pm.getObjectId(pc2);
        endEm(pm);

        assertNotNull(str);
        assertNotNull(str2);
        assertTrue(!str.equals(str2));
        assertNotNull(hex);
        assertNotNull(hex2);
        assertTrue(!hex.equals(hex2));

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        pc2 = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid2);
        assertEquals(str, pc.getUUID());
        assertEquals(str2, pc2.getUUID());
        assertEquals(hex, pc.getUUIDHex());
        assertEquals(hex2, pc2.getUUIDHex());
        startTx(pm);
        pc.setUUIDHex("foo");
        pc2.setUUIDHex("bar");
        endTx(pm);
        endEm(pm);

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        pc2 = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid2);
        assertEquals("foo", pc.getUUIDHex());
        assertEquals("bar", pc2.getUUIDHex());
        endEm(pm);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        assertEquals("bar", pc2.getUUIDHex());
        endEm(pm);
    }

    public void testSequence() {
        ValueStrategyPC pc = new ValueStrategyPC();
        ValueStrategyPC pc2 = new ValueStrategyPC();
        pc.setName("pc");
        pc2.setName("pc2");
        assertEquals(0, pc.getSequence());
        assertEquals(0, pc2.getSequence());

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        pm.setOptimistic(true);
        startTx(pm);
        pm.persist(pc);
        pm.persist(pc2);
        int seq = pc.getSequence();
        assertTrue(!pm.isStoreActive());    // no flush needed
        endTx(pm);
        int seq2 = pc2.getSequence();
        Object oid = pm.getObjectId(pc);
        Object oid2 = pm.getObjectId(pc2);
        endEm(pm);

        assertTrue(seq > 0);
        assertTrue(seq2 > 0);
        assertTrue(seq != seq2);

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        pc2 = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid2);
        assertEquals(seq, pc.getSequence());
        assertEquals(seq2, pc2.getSequence());
        startTx(pm);
        pc.setSequence(99);
        pc2.setSequence(100);
        endTx(pm);
        endEm(pm);

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        pc2 = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid2);
        assertEquals(99, pc.getSequence());
        assertEquals(100, pc2.getSequence());
        endEm(pm);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        map.put("openjpa.RemoteCommitProvider", "sjvm");
        versionTest(getEmf(map));
    }

    private void versionTest(EntityManagerFactory pmf) {
        ValueStrategyPC pc = new ValueStrategyPC();
        pc.setName("pc");

        OpenJPAEntityManager pm = (OpenJPAEntityManager)
            pmf.createEntityManager();
        startTx(pm);
        pm.persist(pc);
        ClassMetaData meta = getConfiguration()
            .getMetaDataRepositoryInstance().
            getMetaData(pc.getClass(), null, false);
        assertNotNull(meta.getVersionField());
        assertEquals("version", meta.getVersionField().getName());
        assertEquals(0, pc.getVersion());
        endTx(pm);
        assertEquals(1, pc.getVersion());
        Object oid = pm.getObjectId(pc);
        endEm(pm);

        // do no-op commit
        pm = (OpenJPAEntityManager) pmf.createEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(1, pc.getVersion());
        startTx(pm);
        try {
            pc.setVersion(10);
            fail("Allowed change to version field.");
        } catch (RuntimeException re) {
        }
        endTx(pm);
        assertEquals(1, pc.getVersion());
        endEm(pm);

        // do real commit
        pm = (OpenJPAEntityManager) pmf.createEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(1, pc.getVersion());
        startTx(pm);
        pc.setName("changed");
        pm.flush();
        assertEquals(1, pc.getVersion());
        endTx(pm);
        assertEquals("changed", pc.getName());
        assertEquals(2, pc.getVersion());
        endEm(pm);

        // rollback
        pm = (OpenJPAEntityManager) pmf.createEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(2, pc.getVersion());
        startTx(pm);
        pc.setName("changed2");
        pm.flush();
        assertEquals(2, pc.getVersion());
        rollbackTx(pm);
        assertEquals(2, pc.getVersion());
        endEm(pm);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        assertEquals(2, pc.getVersion());
        endEm(pm);
    }

    public void testVersionDetach() {
        ValueStrategyPC pc = new ValueStrategyPC();
        ValueStrategyPC pc2 = new ValueStrategyPC();
        pc.setName("pc");
        pc2.setName("pc2");

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pm.persist(pc);
        pm.persist(pc2);
        endTx(pm);
        startTx(pm);
        pc.setName("changed");
        pc2.setName("changed2");
        endTx(pm);
        assertEquals(2, pc.getVersion());
        assertEquals(2, pc2.getVersion());
        ValueStrategyPC detached = (ValueStrategyPC) pm.detach(pc);
        ValueStrategyPC detached2 = (ValueStrategyPC) pm.detach(pc2);
        endEm(pm);

        // clean attach
        pm = (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pc = (ValueStrategyPC) pm.merge(detached);
        assertEquals(2, pc.getVersion());
        endTx(pm);
        assertEquals(2, pc.getVersion());
        endEm(pm);

        // dirty attach
        detached.setName("changed-detached");
        pm = (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pc = (ValueStrategyPC) pm.merge(detached);
        assertEquals(2, pc.getVersion());
        endTx(pm);
        assertEquals(3, pc.getVersion());
        endEm(pm);

        // stale attach
        detached.setName("stale");
        pm = (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        try {
            pm.merge(detached);
            endTx(pm);
            fail("Committed stale version.");
        } catch (OpenJPAException je) {
        }
        if (isActiveTx(pm))
            rollbackTx(pm);
        endEm(pm);

        // modify version field in detached; allow either exception or
        // allow the update to be ignored
        detached2.setName("changed2-detached");
        detached2.setVersion(99);
        pm = (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        try {
            pc2 = (ValueStrategyPC) pm.merge(detached2);
            assertEquals(2, pc2.getVersion());
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        ;
        endEm(pm);
    }

    public void testVersionRefresh() {
        ValueStrategyPC pc = new ValueStrategyPC();
        pc.setName("pc");

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pm.persist(pc);
        endTx(pm);
        startTx(pm);
        pc.setName("changed");
        endTx(pm);
        assertEquals(2, pc.getVersion());

        // clean refresh
        startTx(pm);
        pm.refresh(pc);
        assertEquals(2, pc.getVersion());

        // concurrent mod
        OpenJPAEntityManager pm2 =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(pm2);
        ValueStrategyPC pc2 = (ValueStrategyPC) pm2.find
            (ValueStrategyPC.class, pm2.getObjectId(pc));
        pc2.setName("changed2");
        endTx(pm2);
        assertEquals(3, pc2.getVersion());
        endEm(pm2);

        // stale refresh
        pm.refresh(pc);
        assertEquals(3, pc.getVersion());
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

    public void setUp() {
        deleteAll(ValueStrategyPC.class);
    }

    public void testIgnoreUpdate() {
        ValueStrategyPC pc = new ValueStrategyPC();
        pc.setName("pc");
        pc.setIgnoreUpdate(10);

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pm.persist(pc);
        assertEquals(10, pc.getIgnoreUpdate());
        endTx(pm);
        Object oid = pm.getObjectId(pc);
        endEm(pm);

        //pm = getPM(false, false);
        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(10, pc.getIgnoreUpdate());
        startTx(pm);
        pc.setIgnoreUpdate(100);
        assertFalse(pm.isDirty(pc));
        pm.transactional(pc, false);
        endTx(pm);
        assertEquals(10, pc.getIgnoreUpdate());
        endEm(pm);

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(10, pc.getIgnoreUpdate());
        endEm(pm);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        assertEquals(10, pc.getIgnoreUpdate());
        endEm(pm);
    }

    public void testRestrictUpdate() {
        ValueStrategyPC pc = new ValueStrategyPC();
        pc.setName("pc");
        pc.setRestrictUpdate(10);

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        startTx(pm);
        pm.persist(pc);
        assertEquals(10, pc.getRestrictUpdate());
        endTx(pm);
        Object oid = pm.getObjectId(pc);
        endEm(pm);

        //pm = getPM(false, false);
        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        assertNotNull(pc);
        assertEquals(10, pc.getRestrictUpdate());
        startTx(pm);
        try {
            pc.setRestrictUpdate(100);
            fail("Allowed update of restricted field.");
        } catch (RuntimeException re) {
        }
        endTx(pm);
        assertEquals(10, pc.getRestrictUpdate());
        endEm(pm);
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC

        assertEquals(10, pc.getRestrictUpdate());
        endEm(pm);
    }

    public void testUUID() {
        ValueStrategyPC pc = new ValueStrategyPC();
        ValueStrategyPC pc2 = new ValueStrategyPC();
        pc.setName("pc");
        pc2.setName("pc2");
        assertNull(pc.getUUID());
        assertNull(pc2.getUUID());
        assertNull(pc.getUUIDHex());
        assertNull(pc2.getUUIDHex());

        OpenJPAEntityManager pm =
            (OpenJPAEntityManager) currentEntityManager();
        pm.setOptimistic(true);
        startTx(pm);
        pm.persist(pc);
        pm.persist(pc2);
        String str = pc.getUUID();
        String hex = pc.getUUIDHex();
        assertTrue(!pm.isStoreActive());    // no flush needed
        endTx(pm);
        String str2 = pc2.getUUID();
        String hex2 = pc2.getUUIDHex();
        Object oid = pm.getObjectId(pc);
        Object oid2 = pm.getObjectId(pc2);
        endEm(pm);

        assertNotNull(str);
        assertNotNull(str2);
        assertTrue(!str.equals(str2));
        assertNotNull(hex);
        assertNotNull(hex2);
        assertTrue(!hex.equals(hex2));

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        pc2 = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid2);
        assertEquals(str, pc.getUUID());
        assertEquals(str2, pc2.getUUID());
        assertEquals(hex, pc.getUUIDHex());
        assertEquals(hex2, pc2.getUUIDHex());
        startTx(pm);
        pc.setUUIDHex("foo");
        pc2.setUUIDHex("bar");
        endTx(pm);
        endEm(pm);

        pm = (OpenJPAEntityManager) currentEntityManager();
        pc = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid);
        pc2 = (ValueStrategyPC) pm.find(ValueStrategyPC.class, oid2);
        assertEquals("foo", pc.getUUIDHex());
        assertEquals("bar", pc2.getUUIDHex());
        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.