openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dez...@apache.org
Subject svn commit: r930357 [6/8] - in /openjpa/branches/1.1.x: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/ openjpa-persistence-jdbc/sr...
Date Fri, 02 Apr 2010 19:38:58 GMT
Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java?rev=930357&r1=930356&r2=930357&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java
Fri Apr  2 19:38:58 2010
@@ -1,404 +1,404 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.    
- */
-package org.apache.openjpa.persistence.meta;
-
-import java.util.HashMap;
-import java.util.Map;
-import javax.persistence.EntityManagerFactory;
-
-
-import org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC;
-import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
-import org.apache.openjpa.meta.ClassMetaData;
-import org.apache.openjpa.persistence.OpenJPAEntityManager;
-import org.apache.openjpa.util.OpenJPAException;
-
-/**
- * <p>Test value and update strategies.  Also tests version fields, which
- * are represented in JDO as a value strategy.</p>
- *
- * @author Abe White
- */
-public class TestValueStrategies
-    extends AbstractTestCase {
-
-    public TestValueStrategies(String test) {
-        super(test, "metacactusapp");
-    }
-
-    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);
-    }
-
-    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);
-    }
-
-    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);
-    }
-
-    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);
-    }
-
-    public void testVersion() {
-        versionTest(getEmf());
-    }
-
-    public void testVersionDataCache() {
-
-        Map map = new HashMap();
-        map.put("openjpa.DataCache", "true");
-        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);
-    }
-
-    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());
-            endTx(pm);
-            assertEquals(3, pc2.getVersion());
-        } catch (OpenJPAException je) {
-        }
-        if (isActiveTx(pm))
-            rollbackTx(pm);
-        ;
-        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());
-
-        // dirty refresh
-        pc.setName("changed-1");
-        pm.refresh(pc);
-        assertEquals(3, pc.getVersion());
-
-        pc.setName("changed-2");
-        endTx(pm);
-        assertEquals(4, pc.getVersion());
-        endEm(pm);
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.meta;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.EntityManagerFactory;
+
+
+import org.apache.openjpa.persistence.meta.common.apps.ValueStrategyPC;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.util.OpenJPAException;
+
+/**
+ * <p>Test value and update strategies.  Also tests version fields, which
+ * are represented in JDO as a value strategy.</p>
+ *
+ * @author Abe White
+ */
+public class TestValueStrategies
+    extends AbstractTestCase {
+
+    public TestValueStrategies(String test) {
+        super(test, "metacactusapp");
+    }
+
+    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);
+    }
+
+    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);
+    }
+
+    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);
+    }
+
+    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);
+    }
+
+    public void testVersion() {
+        versionTest(getEmf());
+    }
+
+    public void testVersionDataCache() {
+
+        Map map = new HashMap();
+        map.put("openjpa.DataCache", "true");
+        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);
+    }
+
+    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.detachCopy(pc);
+        ValueStrategyPC detached2 = (ValueStrategyPC) pm.detachCopy(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());
+            endTx(pm);
+            assertEquals(3, pc2.getVersion());
+        } catch (OpenJPAException je) {
+        }
+        if (isActiveTx(pm))
+            rollbackTx(pm);
+        ;
+        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());
+
+        // dirty refresh
+        pc.setName("changed-1");
+        pm.refresh(pc);
+        assertEquals(3, pc.getVersion());
+
+        pc.setName("changed-2");
+        endTx(pm);
+        assertEquals(4, pc.getVersion());
+        endEm(pm);
+    }
+}

Propchange: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestValueStrategies.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java?rev=930357&r1=930356&r2=930357&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLRS.java
Fri Apr  2 19:38:58 2010
@@ -79,7 +79,7 @@ public class TestLRS
         OpenJPAEntityManager em = emf.createEntityManager();
         LRSEntity lrs = em.find(LRSEntity.class, id);
         assertLRS(lrs, "lrs");
-        lrs = em.detach(lrs); 
+        lrs = em.detachCopy(lrs); 
         assertEquals("lrs", lrs.getName());
         assertNull(lrs.getLRSList());
         em.close();

Modified: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java?rev=930357&r1=930356&r2=930357&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java
Fri Apr  2 19:38:58 2010
@@ -73,7 +73,7 @@ public class TestFlushBeforeDetach exten
 
         i.setItemData("EFGH");
 
-        OpenJPAPersistence.cast(em).detach(i);
+        OpenJPAPersistence.cast(em).detachCopy(i);
         em.getTransaction().rollback();
         assertNotSQL("UPDATE ITEM SET.*");
         em.close();

Propchange: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestFlushBeforeDetach.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java?rev=930357&r1=930356&r2=930357&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
(original)
+++ openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
Fri Apr  2 19:38:58 2010
@@ -97,10 +97,17 @@ public class EntityManagerFactoryImpl
         return _factory.getConfiguration();
     }
 
-    public Properties getProperties() {
+    public Properties getPropertiesAsProperties() {
         return _factory.getProperties();
     }
 
+    public Map<String, Object> getProperties() {
+        @SuppressWarnings("unchecked")
+        HashMap<String, Object> retv = 
+                new HashMap<String, Object>((Map) getPropertiesAsProperties());
+        return retv;
+    }
+
     public Object putUserObject(Object key, Object val) {
         return _factory.putUserObject(key, val);
     }

Propchange: openjpa/branches/1.1.x/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message