openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [28/39] - in /openjpa/trunk: openjpa-lib/src/test/java/org/apache/openjpa/lib/test/ openjpa-persistence-jdbc/ openjpa-persistence-jdbc/src/test/java/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ openjpa-per...
Date Fri, 15 Feb 2008 09:20:40 GMT
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInstanceCallbacks.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInstanceCallbacks.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInstanceCallbacks.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestInstanceCallbacks.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,291 @@
+/*
+ * TestInstanceCallbacks.java
+ *
+ * Created on October 12, 2006, 1:19 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * 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.kernel;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.InstanceCallbacksTest;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestInstanceCallbacks extends BaseKernelTest {
+
+    private static final int COMMIT = 0;
+    private static final int FLUSH = 1;
+    private static final int PRESTORE = 2;
+
+    private OpenJPAEntityManager _pm = null;
+    private InstanceCallbacksTest _callbacks = null;
+
+    public TestInstanceCallbacks(String name) {
+        super(name);
+    }
+
+    /**
+     * Creates a new instance of TestInstanceCallbacks
+     */
+    public TestInstanceCallbacks() {
+    }
+
+    public void setUp() throws Exception {
+        deleteAll(InstanceCallbacksTest.class);
+        deleteAll(RuntimeTest1.class);
+        _pm = getPM(true, true);
+        startTx(_pm);
+        _callbacks = new InstanceCallbacksTest();
+        _callbacks.setStringField("foo");
+        _pm.persist(_callbacks);
+        Object id = _pm.getObjectId(_callbacks);
+        endTx(_pm);
+        endEm(_pm);
+
+        // re-find with different PM
+        _pm = getPM();
+        _callbacks =
+            (InstanceCallbacksTest) _pm.find(InstanceCallbacksTest.class, id);
+    }
+
+    public void tearDown() throws Exception {
+        rollbackTx(_pm);
+        endEm(_pm);
+        super.tearDown();
+    }
+
+    public void testPostLoad() {
+        _callbacks.getStringField();
+        assertTrue(_callbacks.postLoadCalled);
+    }
+
+    public void testPreStore() {
+        preStoreTest(COMMIT);
+    }
+
+    public void testPreStoreWithFlush() {
+        preStoreTest(FLUSH);
+    }
+
+    public void testPreStoreWithPreStore() {
+        preStoreTest(PRESTORE);
+    }
+
+    private void preStoreTest(int action) {
+        assertNoCallbacksInvoked(_callbacks);
+//        _pm.begin();
+        startTx(_pm);
+
+        _callbacks.setStringField("bar");
+        Object oid = _pm.getObjectId(_callbacks);
+        if (action == COMMIT) {
+            _pm.flush();
+            endTx(_pm);
+        } else if (action == FLUSH)
+            _pm.flush();
+        else if (action == PRESTORE)
+            _pm.preFlush();
+        assertTrue("prestore wasnt called", _callbacks.preStoreCalled);
+        if (action != COMMIT) {
+//            _pm.commit();
+            if (action != FLUSH)
+                _pm.flush();
+            endTx(_pm);
+        }
+
+        OpenJPAEntityManager pm = getPM();
+        InstanceCallbacksTest callbacks = (InstanceCallbacksTest)
+            pm.find(InstanceCallbacksTest.class, oid);
+        assertNoCallbacksInvoked(callbacks);
+        assertEquals("getonetoone strng is not jdoprestore", "jdoPreStore",
+            callbacks.getOneOne().getStringField());
+        endEm(pm);
+    }
+
+    public void testPreDelete() {
+        assertNoCallbacksInvoked(_callbacks);
+        startTx(_pm);
+        _pm.remove(_callbacks);
+        assertTrue(_callbacks.preDeleteCalled);
+        endTx(_pm);
+    }
+
+    public void testPreDeleteRecursion() {
+        assertNoCallbacksInvoked(_callbacks);
+        startTx(_pm);
+        _callbacks.preDeleteCycle = 0;
+        _pm.remove(_callbacks);
+        assertEquals(1, _callbacks.preDeleteCycle);
+        endTx(_pm);
+    }
+
+    public void testSetRelatedReferenceInPreStore() {
+        assertNull(_callbacks.getRelId());
+        InstanceCallbacksTest callbacks2 = new InstanceCallbacksTest();
+        callbacks2.setRelId(_pm.getObjectId(_callbacks));
+        startTx(_pm);
+        _pm.persist(callbacks2);
+        _pm.flush();
+        endTx(_pm);
+        assertEquals(8888, _callbacks.getIntField());
+        try {
+            assertEquals(callbacks2, _callbacks.getRel());
+        } catch (AssertionFailedError afe) {
+            bug(1162, afe, "Setting a related object reference in "
+                + "preStore fails");
+        }
+    }
+
+    public void testFlushCausesFlush() {
+        //### JDO2MIG : this is failing because we're consuming exceptions
+        // throws from callbacks; need to decide what to do with them
+        causeFlushTest(FLUSH);
+    }
+
+    public void testPreStoreCausesFlush() {
+        //### JDO2MIG : this is failing because we're consuming exceptions
+        // throws from callbacks; need to decide what to do with them
+        causeFlushTest(PRESTORE);
+    }
+
+    private void causeFlushTest(int action) {
+        startTx(_pm);
+        _callbacks.setStringField("sss");
+        _callbacks.flushInPreStore = true;
+        try {
+            if (action == FLUSH)
+                _pm.flush();
+            else
+                _pm.preFlush();
+
+            bug(1139, "Recursive flush allowed because exception swallowed");
+        } catch (Exception je) {
+        }
+        rollbackTx(_pm);
+    }
+
+    private void assertNoCallbacksInvoked(InstanceCallbacksTest pc) {
+        OpenJPAEntityManager pm =
+            (OpenJPAEntityManager) currentEntityManager();
+
+        assertFalse("Expected preDelete to not have been called for object ID "
+            + pm.getObjectId(pc), pc.preDeleteCalled);
+        assertFalse("Expected preClear to not have been called for object ID "
+            + pm.getObjectId(pc), pc.preClearCalled);
+        assertFalse("Expected preStore to not have been called for object ID "
+            + pm.getObjectId(pc), pc.preStoreCalled);
+    }
+
+    /* 
+    // no JPA equivalent
+
+    public void testDetachAttach()
+    throws Exception {
+        OpenJPAEntityManager pm = getPM();
+        DetachAttachEvent pc = (DetachAttachEvent) pm.find
+                (DetachAttachEvent.class,createDetachableId(4));
+        DetachAttachEvent.EVENTS.clear();
+        pc = (DetachAttachEvent) pm.detach(pc);
+        assertDetachEvents(new String[]{ "PRED4", "POSTD4" });
+        endEm(pm,());
+        
+        assertTrue(pm.isDetached(pc));
+        
+        pm = getPM();
+        startTx(pm,());
+        //FIXME jthomas
+        
+//        pm.addInstanceLifecycleListener(new CreateLifecycleListener() {
+//            public void postCreate(InstanceLifecycleEvent ev) {
+//                fail("No post create necessary");
+//            }
+//        }, null);
+        pm.persist(pc);
+        assertDetachEvents(new String[]{ "PREA4", "POSTA4" });
+        endTx(pm,());
+        endEm(pm,());
+    }
+    
+    public void testDetachAttachRelations() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm,());
+        DetachAttachEvent pc = (DetachAttachEvent) pm.find
+                (DetachAttachEvent.class,createDetachableId(2));
+        pc.setOneOne((DetachAttachEvent) pm.find
+                (DetachAttachEvent.class,createDetachableId(4)));
+        endTx(pm,());
+        DetachAttachEvent.EVENTS.clear();
+        pc = (DetachAttachEvent) pm.detach(pc);
+        endEm(pm,());
+        assertDetachEvents(
+                new String[]{ "PRED2", "PRED4", "POSTD2", "POSTD4" });
+        
+        pm = getPM();
+        startTx(pm,());
+        pm.persist(pc);
+        assertDetachEvents(
+                new String[]{ "PREA2", "PREA4", "POSTA2", "POSTA4" });
+        rollbackTx(pm,());
+        endEm(pm,());
+    }
+    
+    private void assertDetachEvents(String[] expected) {
+        Collection events = DetachAttachEvent.EVENTS;
+        if (expected.length != events.size()) {
+            StringBuffer buf = new StringBuffer();
+            for (int i = 0; i < expected.length; i++)
+                buf.append(expected[i]).append(",");
+            buf.append("!=");
+            for (Iterator it = events.iterator(); it.hasNext();)
+                buf.append(it.next()).append(",");
+            fail("mismatch event count:" + buf);
+        }
+        String event;
+        for (int i = 0; i < expected.length; i++) {
+            if (!events.remove(expected[i]))
+                fail("Event not fired:" + expected[i]);
+            if (events.contains(expected[i]))
+                fail("Event fired twice:" + expected[i]);
+        }
+        if (!events.isEmpty())
+            fail("Excess events fired:" + events);
+        DetachAttachEvent.EVENTS.clear();
+    }
+    
+    private Object createDetachableId(int field) {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm,());
+        DetachAttachEvent pc = new DetachAttachEvent();
+        pc.setIntField(field);
+        pm.persist(pc);
+        endTx(pm,());
+        endEm(pm,());
+//        return pm.getObjectId(pc);
+        return pc.getId();
+    }
+    */
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfaces.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfaces.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfaces.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfaces.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,490 @@
+/*
+ * 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.kernel;
+
+import java.util.List;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterface;
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceEmbed;
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceOwner;
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceSup;
+import org.apache.openjpa.persistence.kernel.common.apps.MixedInterface;
+import org.apache.openjpa.persistence.kernel.common.apps.MixedInterfaceImpl;
+import org.apache.openjpa.persistence.kernel.common.apps.NonMappedInterfaceImpl;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestManagedInterfaces extends BaseKernelTest {
+
+    public void setUp() {
+        deleteAll(ManagedInterfaceSup.class);
+        deleteAll(ManagedInterfaceOwner.class);
+        deleteAll(MixedInterface.class);
+        deleteAll(MixedInterfaceImpl.class);
+        deleteAll(NonMappedInterfaceImpl.class);
+        deleteAll(RuntimeTest1.class);
+    }
+
+    public void testManagedInterface() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        ManagedInterface pc =
+            (ManagedInterface) pm.createInstance(ManagedInterface.class);
+        pc.setIntFieldSup(3);
+        pc.setIntField(4);
+        pc.setEmbed((ManagedInterfaceEmbed) pm
+            .createInstance(ManagedInterfaceEmbed.class));
+
+        pc.getEmbed().setIntField(5);
+        assertEquals(5, pc.getEmbed().getIntField());
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = pm.find(ManagedInterface.class, oid);
+        assertEquals(3, pc.getIntFieldSup());
+        assertEquals(4, pc.getIntField());
+        assertEquals(5, pc.getEmbed().getIntField());
+        startTx(pm);
+        pc.setIntField(14);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        startTx(pm);
+
+//        Query query = pm.newQuery(ManagedInterface.class, "intField==14");
+//        Collection c = (Collection) query.execute();
+
+        OpenJPAQuery query = pm.createQuery(
+            "SELECT o FROM ManagedInterface o WHERE o.intField = 14");
+        List l = query.getResultList();
+
+        assertEquals(1, l.size());
+        pc = (ManagedInterface) l.iterator().next();
+        assertEquals(14, pc.getIntField());
+        pm.remove(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        try {
+            pm.find(ManagedInterface.class, oid);
+            fail();
+        } catch (Exception onfe) {
+        }
+
+        endEm(pm);
+    }
+
+//    public void testInterfaceOwner() {
+//        OpenJPAEntityManager pm = getPM();
+//        ManagedInterfaceOwner pc = new ManagedInterfaceOwner();
+//        pc.setIFace((ManagedInterfaceSup) pm.createInstance 
+//            (ManagedInterfaceSup.class));
+//        pc.setEmbed((ManagedInterfaceEmbed) pm.createInstance 
+//            (ManagedInterfaceEmbed.class));
+//        pc.getIFace().setIntFieldSup(3);
+//        pc.getEmbed().setIntField(5);
+//
+//        startTx(pm);
+//        pm.persist(pc);
+//        Object oid = pm.getObjectId(pc);
+//        endTx(pm);
+//        pc = (ManagedInterfaceOwner) pm.getObjectById(oid, true);
+//        assertEquals(3, pc.getIFace().getIntFieldSup());
+//        assertEquals(5, pc.getEmbed().getIntField());
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterfaceOwner) pm.getObjectById(oid, true);
+//        assertEquals(3, pc.getIFace().getIntFieldSup());
+//        assertEquals(5, pc.getEmbed().getIntField());
+//        endEm(pm);
+//
+//        pm = getPM();
+//        startTx(pm);
+//        Query q = pm.newQuery(ManagedInterfaceOwner.class, 
+//            "iface.intFieldSup==3 && embed.intField==5");
+//        Collection c = (Collection) q.execute();
+//        pc = (ManagedInterfaceOwner) c.iterator().next();
+//        assertEquals(3, pc.getIFace().getIntFieldSup());
+//        assertEquals(5, pc.getEmbed().getIntField());
+//
+//        pc.getIFace().setIntFieldSup(13);
+//        pc.getEmbed().setIntField(15);
+//        assertEquals(13, pc.getIFace().getIntFieldSup());
+//        assertEquals(15, pc.getEmbed().getIntField());
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterfaceOwner) pm.getObjectById(oid, true);
+//        assertEquals(13, pc.getIFace().getIntFieldSup());
+//        assertEquals(15, pc.getEmbed().getIntField());
+//        endEm(pm);
+//    }
+//
+//    public void testCollection() {
+//        OpenJPAEntityManager pm = getPM();
+//        startTx(pm);
+//        ManagedInterface pc = (ManagedInterface) pm.createInstance
+//            (ManagedInterface.class);
+//        Set set = new HashSet();
+//        set.add(new Integer(3));
+//        set.add(new Integer(4));
+//        set.add(new Integer(5));
+//        pc.setSetInteger(set);
+//        pm.persist(pc);
+//        Object oid = pm.getObjectId(pc);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetInteger();
+//        assertEquals(3, set.size());
+//        assertTrue(set.contains(new Integer(3)));
+//        assertTrue(set.contains(new Integer(4)));
+//        assertTrue(set.contains(new Integer(5)));
+//        startTx(pm);
+//        set.remove(new Integer(4));
+//        set.add(new Integer(14));
+//        set.add(new Integer(15));
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetInteger();
+//        assertEquals(4, set.size());
+//        assertTrue(set.contains(new Integer(3)));
+//        assertTrue(set.contains(new Integer(5)));
+//        assertTrue(set.contains(new Integer(14)));
+//        assertTrue(set.contains(new Integer(15)));
+//        startTx(pm);
+//        pc.setSetInteger(null);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetInteger();
+//        assertTrue (set == null || set.size() == 0);
+//        endEm(pm);
+//    }
+//
+//    public void testCollectionPC() {
+//        OpenJPAEntityManager pm = getPM();
+//        startTx(pm);
+//        ManagedInterface pc = (ManagedInterface) pm.createInstance
+//            (ManagedInterface.class);
+//        Set set = new HashSet();
+//        set.add(new RuntimeTest1("a", 3));
+//        set.add(new RuntimeTest1("b", 4));
+//        set.add(new RuntimeTest1("c", 5));
+//        pc.setSetPC(set);
+//        pm.persist(pc);
+//        Object oid = pm.getObjectId(pc);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetPC();
+//        assertEquals(3, set.size());
+//        Collection seen = new ArrayList();
+//        RuntimeTest1 rel;
+//        RuntimeTest1 toRem = null;
+//        for (Iterator it = set.iterator(); it.hasNext();) {
+//            rel = (RuntimeTest1) it.next();
+//            seen.add(rel.getStringField());
+//            if (rel.getIntField() == 4)
+//                toRem = rel;
+//        }
+//        assertEquals(3, seen.size());
+//        assertTrue(seen.contains("a"));
+//        assertTrue(seen.contains("b"));
+//        assertTrue(seen.contains("c"));
+//        startTx(pm);
+//        assertNotNull(toRem);
+//        set.remove(toRem);
+//        set.add(new RuntimeTest1("x", 14));
+//        set.add(new RuntimeTest1("y", 15));
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetPC();
+//        assertEquals(4, set.size());
+//        seen.clear();
+//        for (Iterator it = set.iterator(); it.hasNext();) {
+//            rel = (RuntimeTest1) it.next();
+//            seen.add(rel.getStringField());
+//        }
+//        assertEquals(4, seen.size());
+//        assertTrue(seen.contains("a"));
+//        assertTrue(seen.contains("c"));
+//        assertTrue(seen.contains("x"));
+//        assertTrue(seen.contains("y"));
+//        startTx(pm);
+//        pc.setSetPC(null);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetPC();
+//        assertTrue (set == null || set.size() == 0);
+//        endEm(pm);
+//    }
+//
+//    public void testCollectionInterfaces() {
+//        OpenJPAEntityManager pm = getPM();
+//        startTx(pm);
+//        ManagedInterface pc = (ManagedInterface) pm.createInstance
+//            (ManagedInterface.class);
+//        Set set = new HashSet();
+//        set.add(createInstance(pm, 3));
+//        set.add(createInstance(pm, 4));
+//        set.add(createInstance(pm, 5));
+//        pc.setSetI(set);
+//        pm.persist(pc);
+//        Object oid = pm.getObjectId(pc);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetI();
+//        assertEquals(3, set.size());
+//        Collection seen = new ArrayList();
+//        ManagedInterface rel = null;
+//        ManagedInterface toRem = null;
+//        for (Iterator it = set.iterator(); it.hasNext();) {
+//            rel = (ManagedInterface) it.next();
+//            seen.add(new Integer(rel.getIntField()));
+//            if (rel.getIntField() == 4)
+//                toRem = rel;
+//        }
+//        assertEquals(3, seen.size());
+//        assertTrue(seen.contains(new Integer(3)));
+//        assertTrue(seen.contains(new Integer(4)));
+//        assertTrue(seen.contains(new Integer(5)));
+//        startTx(pm);
+//        assertNotNull(toRem);
+//        set.remove(toRem);
+//        set.add(createInstance(pm, 14));
+//        set.add(createInstance(pm, 15));
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetI();
+//        assertEquals(4, set.size());
+//        seen.clear();
+//        for (Iterator it = set.iterator(); it.hasNext();) {
+//            rel = (ManagedInterface) it.next();
+//            seen.add(new Integer(rel.getIntField()));
+//        }
+//        assertEquals(4, seen.size());
+//        assertTrue(seen.contains(new Integer(3)));
+//        assertTrue(seen.contains(new Integer(5)));
+//        assertTrue(seen.contains(new Integer(14)));
+//        assertTrue(seen.contains(new Integer(15)));
+//        startTx(pm);
+//        pc.setSetPC(null);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        set = pc.getSetPC();
+//        assertTrue (set == null || set.size() == 0);
+//        endEm(pm);
+//    }
+//
+//    public void testMixedQuery() {
+//        createMixed();
+//
+//        OpenJPAEntityManager pm = getPM();
+//        Query q = pm.newQuery(MixedInterface.class, "intField==4");
+//        Collection c = (Collection) q.execute();
+//        Set seen = new HashSet();
+//        assertEquals(2, c.size());
+//        MixedInterface pc;
+//        for (Iterator it = c.iterator(); it.hasNext();) {
+//            pc = (MixedInterface) it.next();
+//            assertEquals(4, pc.getIntField());
+//            seen.add(pc.getClass());
+//        }
+//        assertEquals(2, seen.size());
+//        endEm(pm);
+//    }
+//
+//    public void testMixedExtent() {
+//        createMixed();
+//
+//        OpenJPAEntityManager pm = getPM();
+//        Extent e = pm.getExtent(MixedInterface.class, true);
+//        Set seen = new HashSet();
+//        int size = 0;
+//        for (Iterator it = e.iterator(); it.hasNext();) {
+//            seen.add(it.next().getClass());
+//            size++;
+//        }
+//        assertEquals(3, size);
+//        assertEquals(2, seen.size());
+//
+//        e = pm.getExtent(MixedInterface.class, false);
+//        seen = new HashSet();
+//        size = 0;
+//        for (Iterator it = e.iterator(); it.hasNext();) {
+//            seen.add(it.next().getClass()); 
+//            size++;
+//        }
+//        assertEquals(1, size);
+//        assertNotEquals(MixedInterfaceImpl.class, seen.iterator().next());
+//        endEm(pm);
+//    }
+//
+//    private void createMixed() {
+//        OpenJPAEntityManager pm = getPM();
+//        startTx(pm);
+//        MixedInterface pc = (MixedInterface) pm.createInstance
+//            (MixedInterface.class);
+//        pc.setIntField(4);
+//        pm.persist(pc);
+//        pc = new MixedInterfaceImpl();
+//        pc.setIntField(4);
+//        pm.persist(pc);
+//        pc = new MixedInterfaceImpl();
+//        pc.setIntField(8);
+//        pm.persist(pc);
+//        endTx(pm);
+//        endEm(pm);
+//    }
+//
+//    public void testUnimplementedThrowsException() {
+//        OpenJPAEntityManager pm = getPM();
+//        ManagedInterface pc = createInstance(pm, 1);
+//        try {
+//            pc.unimplemented();
+//            fail("Exception expected.");
+//        } catch (JDOUserException jdoe) {} // good
+//        endEm(pm);
+//    }
+//
+//    public void testNonMappedcreateInstanceException() {
+//        OpenJPAEntityManager pm = getPM();
+//        try {
+//            pm.createInstance(NonMappedInterface.class);
+//            fail("Exception expected");
+//        } catch (JDOUserException jdoe) {} // good
+//        endEm(pm);
+//    }
+//
+//    public void testNonMappedPropertyAlias() 
+//        throws Exception {
+//        Object oid = createNonMappedImpl();
+//        OpenJPAEntityManager pm = getPM();
+//        Query q = pm.newQuery(NonMappedInterface.class, "intField==4");
+//        Collection c = (Collection) q.execute();
+//        assertEquals(1, c.size());
+//        assertEquals(oid, pm.getObjectId(c.iterator().next()));
+//        endEm(pm);
+//    }
+//
+//    public void testNonMappedPropertyAliasInMemory() 
+//        throws Exception {
+//        Object oid = createNonMappedImpl();
+//        OpenJPAEntityManager pm = getPM();
+//        Query q = pm.newQuery(NonMappedInterface.class, "intField==4");
+//        q.setCandidates((Collection) pm.newQuery(NonMappedInterfaceImpl.class).
+//            execute());
+//        Collection c = (Collection) q.execute();
+//        assertEquals(1, c.size());
+//        assertEquals(oid, pm.getObjectId(c.iterator().next()));
+//        endEm(pm);
+//    }
+//
+//    private Object createNonMappedImpl() 
+//        throws Exception {
+//        // load non-mapped-impl
+//        Class.forName(NonMappedInterfaceImpl.class.getNametrue,
+//            NonMappedInterfaceImpl.class.getClassLoader());
+//
+//     
+//        OpenJPAEntityManager pm = getPM();
+//        startTx(pm);
+//        NonMappedInterface pc = new NonMappedInterfaceImpl();
+//        pc.setIntField(4);
+//        pm.persist(pc);
+//        Object oid = pm.getObjectId(pc);
+//        pc = new NonMappedInterfaceImpl();
+//        pc.setIntField(8);
+//        pm.persist(pc);
+//        endTx(pm);
+//        endEm(pm);
+//        return oid;
+//    }
+//
+//    public void testDetach() {
+//        KodoOpenJPAEntityManager pm = getPM();
+//        startTx(pm);
+//        ManagedInterface pc = createInstance(pm, 4);
+//        pm.persist(pc);
+//        Object oid = pm.getObjectId(pc);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        ManagedInterface pcx = (ManagedInterface) pm.getObjectById(oid, true);
+//        pc = (ManagedInterface) pm.detachCopy(pcx);
+//        endEm(pm);
+//
+//        assertTrue(pm.isDetached(pc));
+//        pc.setIntField(7);
+//
+//        pm = getPM();
+//        startTx(pm);
+//        pm.persist(pc);
+//        endTx(pm);
+//        endEm(pm);
+//
+//        pm = getPM();
+//        pc = (ManagedInterface) pm.getObjectById(oid, true);
+//        assertEquals(7, pc.getIntField());
+//        endEm(pm);
+//
+//    }
+
+    private ManagedInterface createInstance(OpenJPAEntityManager pm, int i) {
+        ManagedInterface pc = (ManagedInterface) pm.createInstance
+            (ManagedInterface.class);
+        pc.setIntField(i);
+        return pc;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfacesAppId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfacesAppId.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfacesAppId.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestManagedInterfacesAppId.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,399 @@
+/*
+ * TestManagedInterfacesAppId.java
+ *
+ * Created on October 16, 2006, 4:49 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * 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.kernel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceAppId;
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceEmbed;
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceOwnerAppId;
+import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceSupAppId;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestManagedInterfacesAppId extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestManagedInterfacesAppId
+     */
+    public TestManagedInterfacesAppId(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(ManagedInterfaceSupAppId.class);
+        deleteAll(ManagedInterfaceOwnerAppId.class);
+        deleteAll(RuntimeTest1.class);
+    }
+
+    public void testManagedInterface() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance(
+            (ManagedInterfaceAppId.class));
+        pc.setId1(9);
+        pc.setId2(19);
+        pc.setIntFieldSup(3);
+        pc.setIntField(4);
+
+        pc.setEmbed((ManagedInterfaceEmbed) pm.createInstance
+            (ManagedInterfaceEmbed.class));
+
+        pc.getEmbed().setIntField(5);
+        assertEquals(5, pc.getEmbed().getIntField());
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        assertEquals(9, pc.getId1());
+        assertEquals(19, pc.getId2());
+        assertEquals(3, pc.getIntFieldSup());
+        assertEquals(4, pc.getIntField());
+        assertEquals(5, pc.getEmbed().getIntField());
+        startTx(pm);
+        pc.setIntField(14);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        Object newId = new ManagedInterfaceSupAppId.Id("9,19");
+        pc =
+            (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, newId);
+        assertEquals(9, pc.getId1());
+        assertEquals(19, pc.getId2());
+        assertEquals(3, pc.getIntFieldSup());
+        assertEquals(14, pc.getIntField());
+        assertEquals(5, pc.getEmbed().getIntField());
+        endEm(pm);
+
+        pm = getPM();
+        startTx(pm);
+        OpenJPAQuery query =
+            pm.createNativeQuery("intField==14", ManagedInterfaceAppId.class);
+        Collection c = (Collection) query.getResultList();
+        assertEquals(1, c.size());
+        pc = (ManagedInterfaceAppId) c.iterator().next();
+        assertEquals(14, pc.getIntField());
+        pm.remove(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        try {
+            pm.find(ManagedInterfaceAppId.class, oid);
+            fail();
+        } catch (Exception onfe) {
+        }
+
+        endEm(pm);
+    }
+
+    public void testInterfaceOwner() {
+        OpenJPAEntityManager pm = getPM();
+        ManagedInterfaceOwnerAppId pc = new ManagedInterfaceOwnerAppId();
+        pc.setIFace((ManagedInterfaceSupAppId) pm.createInstance
+            (ManagedInterfaceSupAppId.class));
+        pc.getIFace().setIntFieldSup(3);
+
+        startTx(pm);
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        pc = (ManagedInterfaceOwnerAppId) pm
+            .find(ManagedInterfaceOwnerAppId.class, oid);
+        assertEquals(3, pc.getIFace().getIntFieldSup());
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceOwnerAppId) pm
+            .find(ManagedInterfaceOwnerAppId.class, oid);
+        assertEquals(3, pc.getIFace().getIntFieldSup());
+        endEm(pm);
+
+        pm = getPM();
+        startTx(pm);
+        OpenJPAQuery q = pm.createNativeQuery("iface.intFieldSup==3",
+            ManagedInterfaceOwnerAppId.class);
+        Collection c = (Collection) q.getResultList();
+        pc = (ManagedInterfaceOwnerAppId) c.iterator().next();
+        assertEquals(3, pc.getIFace().getIntFieldSup());
+
+        pc.getIFace().setIntFieldSup(13);
+        assertEquals(13, pc.getIFace().getIntFieldSup());
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceOwnerAppId) pm
+            .find(ManagedInterfaceOwnerAppId.class, oid);
+        assertEquals(13, pc.getIFace().getIntFieldSup());
+        endEm(pm);
+    }
+
+    public void testCollection() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance
+            (ManagedInterfaceAppId.class);
+        Set set = new HashSet();
+        set.add(new Integer(3));
+        set.add(new Integer(4));
+        set.add(new Integer(5));
+        pc.setSetInteger(set);
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetInteger();
+        assertEquals(3, set.size());
+        assertTrue(set.contains(new Integer(3)));
+        assertTrue(set.contains(new Integer(4)));
+        assertTrue(set.contains(new Integer(5)));
+        startTx(pm);
+        set.remove(new Integer(4));
+        set.add(new Integer(14));
+        set.add(new Integer(15));
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetInteger();
+        assertEquals(4, set.size());
+        assertTrue(set.contains(new Integer(3)));
+        assertTrue(set.contains(new Integer(5)));
+        assertTrue(set.contains(new Integer(14)));
+        assertTrue(set.contains(new Integer(15)));
+        startTx(pm);
+        pc.setSetInteger(null);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetInteger();
+        assertTrue(set == null || set.size() == 0);
+        endEm(pm);
+    }
+
+    public void testCollectionPC() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance
+            (ManagedInterfaceAppId.class);
+        Set set = new HashSet();
+        set.add(new RuntimeTest1("a", 3));
+        set.add(new RuntimeTest1("b", 4));
+        set.add(new RuntimeTest1("c", 5));
+        pc.setSetPC(set);
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetPC();
+        assertEquals(3, set.size());
+        Collection seen = new ArrayList();
+        RuntimeTest1 rel;
+        RuntimeTest1 toRem = null;
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (RuntimeTest1) it.next();
+            seen.add(rel.getStringField());
+            if (rel.getIntField() == 4)
+                toRem = rel;
+        }
+        assertEquals(3, seen.size());
+        assertTrue(seen.contains("a"));
+        assertTrue(seen.contains("b"));
+        assertTrue(seen.contains("c"));
+        startTx(pm);
+        assertNotNull(toRem);
+        set.remove(toRem);
+        set.add(new RuntimeTest1("x", 14));
+        set.add(new RuntimeTest1("y", 15));
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetPC();
+        assertEquals(4, set.size());
+        seen.clear();
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (RuntimeTest1) it.next();
+            seen.add(rel.getStringField());
+        }
+        assertEquals(4, seen.size());
+        assertTrue(seen.contains("a"));
+        assertTrue(seen.contains("c"));
+        assertTrue(seen.contains("x"));
+        assertTrue(seen.contains("y"));
+        startTx(pm);
+        pc.setSetPC(null);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetPC();
+        assertTrue(set == null || set.size() == 0);
+        endEm(pm);
+    }
+
+    public void testCollectionInterfaces() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance
+            (ManagedInterfaceAppId.class);
+        Set set = new HashSet();
+        set.add(createInstance(pm, 3));
+        set.add(createInstance(pm, 4));
+        set.add(createInstance(pm, 5));
+        pc.setSetI(set);
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetI();
+        assertEquals(3, set.size());
+        Collection seen = new ArrayList();
+        ManagedInterfaceAppId rel = null;
+        ManagedInterfaceAppId toRem = null;
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (ManagedInterfaceAppId) it.next();
+            seen.add(new Integer(rel.getIntField()));
+            if (rel.getIntField() == 4)
+                toRem = rel;
+        }
+        assertEquals(3, seen.size());
+        assertTrue(seen.contains(new Integer(3)));
+        assertTrue(seen.contains(new Integer(4)));
+        assertTrue(seen.contains(new Integer(5)));
+        startTx(pm);
+        assertNotNull(toRem);
+        set.remove(toRem);
+        set.add(createInstance(pm, 14));
+        set.add(createInstance(pm, 15));
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetI();
+        assertEquals(4, set.size());
+        seen.clear();
+        for (Iterator it = set.iterator(); it.hasNext();) {
+            rel = (ManagedInterfaceAppId) it.next();
+            seen.add(new Integer(rel.getIntField()));
+        }
+        assertEquals(4, seen.size());
+        assertTrue(seen.contains(new Integer(3)));
+        assertTrue(seen.contains(new Integer(5)));
+        assertTrue(seen.contains(new Integer(14)));
+        assertTrue(seen.contains(new Integer(15)));
+        startTx(pm);
+        pc.setSetPC(null);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        set = pc.getSetPC();
+        assertTrue(set == null || set.size() == 0);
+        endEm(pm);
+    }
+
+    public void testUnimplementedThrowsException() {
+        OpenJPAEntityManager pm = getPM();
+        ManagedInterfaceAppId pc = createInstance(pm, 1);
+        try {
+            pc.unimplemented();
+            fail("Exception expected.");
+        } catch (Exception jdoe) {
+        } // good
+        endEm(pm);
+    }
+
+    public void testDetach() {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        ManagedInterfaceAppId pc = createInstance(pm, 4);
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        pc = (ManagedInterfaceAppId) pm.detach(pc);
+        endEm(pm);
+
+        assertTrue(pm.isDetached(pc));
+        pc.setIntField(7);
+
+        pm = getPM();
+        startTx(pm);
+        pm.persist(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
+        assertEquals(7, pc.getIntField());
+        endEm(pm);
+    }
+
+    private ManagedInterfaceAppId createInstance(OpenJPAEntityManager pm,
+        int i) {
+        ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm
+            .createInstance(ManagedInterfaceAppId.class);
+        pc.setId1(i * 10);
+        pc.setId2(i * -10);
+        pc.setIntField(i);
+        return pc;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestMultiThreaded.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestMultiThreaded.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestMultiThreaded.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestMultiThreaded.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,148 @@
+/*
+ * TestMultiThreaded.java
+ *
+ * Created on October 12, 2006, 2:21 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.kernel;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestMultiThreaded extends BaseKernelTest {
+
+    static int serial = 5;
+    static int threads = 5;
+    static int iterations = 5;
+
+    private OpenJPAEntityManager pm;
+    private Object id;
+    private String name;
+
+    /**
+     * Creates a new instance of TestMultiThreaded
+     */
+    public TestMultiThreaded() {
+    }
+
+    public TestMultiThreaded(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+
+        OpenJPAEntityManager pm2 = getPM();
+        startTx(pm2);
+        name = "testMultiThreaded" + Math.random();
+        RuntimeTest1 a = new RuntimeTest1(name,
+            (int) (Math.random() * Integer.MAX_VALUE));
+        pm2.persist(a);
+        id = pm2.getObjectId(a);
+        endTx(pm2);
+
+        Map props = new HashMap();
+        props.put("openjpa.Multithreaded", "true");
+        OpenJPAEntityManagerFactory pmf =
+            (OpenJPAEntityManagerFactory) getEmf(props);
+        pm = pmf.createEntityManager();
+        startTx(pm);
+    }
+
+    public void tearDown()
+        throws Exception {
+        try {
+            rollbackTx(pm);
+            endEm(pm);
+        } catch (Exception e) {
+            // this is not what we are testing
+        }
+        super.tearDown();
+    }
+
+    public void testgetTransaction() {
+        mttest(serial, threads, iterations);
+        pm.getTransaction();
+    }
+
+    public void testGetObjectById() {
+        mttest(serial, threads, iterations);
+        assertNotNull(pm.find(RuntimeTest1.class, id));
+    }
+
+    public void testQueryExecution() {
+        mttest(serial, threads, iterations);
+        OpenJPAQuery q = pm.createQuery("select o from RuntimeTest1 o "
+            + "where o.stringField = '" + name + "'");
+        assertEquals(1, q.getResultList().size());
+    }
+
+    public void testDeletePersistent() {
+        mttest(serial, threads, iterations);
+        pm.removeAll(pm.createQuery("select o from RuntimeTest1 o "
+            + "where o.stringField = '" + name + "'").getResultList());
+    }
+
+    public void testRefreshAll() {
+        mttest(serial, threads, iterations);
+        pm.refreshAll();
+    }
+
+    public void testEvictAll() {
+        mttest(serial, threads, iterations);
+        pm.evictAll();
+    }
+
+    public void testIterateExtent()
+        throws Throwable {
+        if (timeout(120 * 1000)) return;
+
+        mttest(serial, threads, iterations);
+
+        assertTrue("Transaction should have been active",
+            pm.getTransaction().isActive());
+
+        for (int i = 0; i < 3; i++) {
+            pm.persist(new RuntimeTest1("testIterateExtent" + Math.random(),
+                (int) (Math.random() * Integer.MAX_VALUE)));
+        }
+
+        assertTrue("Transaction should have been active",
+            pm.getTransaction().isActive());
+
+        for (Iterator i = pm.createExtent(RuntimeTest1.class, true).iterator();
+            i.hasNext(); i.next())
+            ;
+
+        assertTrue("Transaction should have been active",
+            pm.getTransaction().isActive());
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestNTW.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestNTW.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestNTW.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestNTW.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,110 @@
+/*
+ * TestNTW.java
+ *
+ * Created on October 12, 2006, 2:33 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.kernel;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestNTW extends BaseKernelTest {
+
+    private OpenJPAEntityManagerFactory factory;
+
+    /**
+     * Creates a new instance of TestNTW
+     */
+    public TestNTW() {
+    }
+
+    public TestNTW(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        deleteAll(RuntimeTest1.class);
+
+        OpenJPAEntityManager em = getPM();
+        startTx(em);
+        em.persist(new RuntimeTest1("ntw0", 0));
+        em.persist(new RuntimeTest1("ntw1", 1));
+        em.persist(new RuntimeTest1("ntw2", 2));
+        em.persist(new RuntimeTest1("ntw3", 3));
+        em.persist(new RuntimeTest1("ntw4", 4));
+        endTx(em);
+        endEm(em);
+
+        em = getPM();
+        startTx(em);
+    }
+
+    public void testNonTransactionalWrite() throws Exception {
+        OpenJPAEntityManagerFactory factory = broker();
+        OpenJPAEntityManager em = factory.createEntityManager();
+        OpenJPAQuery q = em.createQuery(
+            "SELECT o FROM RuntimeTest1 o ORDER BY o.stringField ASC");
+        q.setSubclasses(false);
+        Collection c = (Collection) q.getResultList();
+
+        Iterator iter = c.iterator();
+        RuntimeTest1 o;
+        while (iter.hasNext()) {
+            o = (RuntimeTest1) iter.next();
+            o.setStringField(o.getStringField() + " modified");
+        }
+
+        startTx(em);
+        endTx(em);
+
+        q = em.createQuery(
+            "SELECT o FROM RuntimeTest1 o ORDER BY o.stringField ASC");
+        q.setSubclasses(false);
+        Collection results = (Collection) q.getResultList();
+        assertEquals(5, results.size());
+        endEm(em);
+    }
+
+    private OpenJPAEntityManagerFactory broker() {
+        Map map = new HashMap();
+        map.put("OpenJPA.Optimistic", "true");
+        map.put("OpenJPA.NontransactionalRead", "true");
+        map.put("OpenJPA.NontransactionalWrite", "true");
+
+        if (factory == null) {
+            factory = OpenJPAPersistence
+                .createEntityManagerFactory("TestConv", null, map);
+        }
+        return factory;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOpenResultsCommit.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOpenResultsCommit.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOpenResultsCommit.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOpenResultsCommit.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,118 @@
+/*
+ * TestOpenResultsCommit.java
+ *
+ * Created on October 12, 2006, 2:43 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.kernel;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.EnumSet;
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+
+public class TestOpenResultsCommit extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestOpenResultsCommit
+     */
+    public TestOpenResultsCommit() {
+    }
+
+    public TestOpenResultsCommit(String testName) {
+        super(testName);
+    }
+
+    public void setUp()
+        throws Exception {
+        super.setUp();
+
+        deleteAll(RuntimeTest1.class);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        for (int i = 0; i < 50; i++)
+            pm.persist(new RuntimeTest1("open results #" + i, i));
+        endTx(pm);
+        endEm(pm);
+    }
+
+    public void testCommitWithModeTransaction() {
+        try {
+            testCommitWithOpenResults("transaction");
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.EMPRESS), 718, e,
+                "Cannot keep results open across commit");
+        }
+    }
+
+    public void testCommitWithModeOpenJPAEntityManager() {
+        try {
+            testCommitWithOpenResults("persistence-manager");
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.EMPRESS), 718, e,
+                "Cannot keep results open across commit");
+        }
+    }
+
+    public void testCommitWithModeOnDemand() {
+        try {
+            testCommitWithOpenResults("on-demand");
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.EMPRESS), 718, e,
+                "Cannot keep results open across commit");
+        }
+    }
+
+    private void testCommitWithOpenResults(String crm) {
+        Map props = new HashMap();
+        props.put("openjpa.DefaultFetchThreshold", 1 + "");
+        props.put("openjpa.ConnectionRetainMode", crm);
+
+        OpenJPAEntityManagerFactory pmf =
+            (OpenJPAEntityManagerFactory) getEmf(props);
+        OpenJPAEntityManager pm = pmf.createEntityManager();
+
+        startTx(pm);
+        Iterator results =
+            pm.createExtent(RuntimeTest1.class, false).iterator();
+        results.next();
+        ((RuntimeTest1) results.next()).setStringField("changed name");
+        endTx(pm);
+        while (results.hasNext())
+            results.next();
+        endEm(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,358 @@
+/*
+ * TestOptimisticLockGroups.java
+ *
+ * Created on October 12, 2006, 2:57 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.kernel;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.LockGroupPC;
+import org.apache.openjpa.persistence.kernel.common.apps.LockGroupPC2;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestOptimisticLockGroups extends BaseKernelTest {
+
+    private Object oid;
+
+    /**
+     * Creates a new instance of TestOptimisticLockGroups
+     */
+    public TestOptimisticLockGroups() {
+    }
+
+    public TestOptimisticLockGroups(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(LockGroupPC.class);
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+        Object o = new LockGroupPC();
+        pm.persist(o);
+        endTx(pm);
+        oid = pm.getObjectId(o);
+        endEm(pm);
+    }
+
+    public void testDefaultLockGroupFailure1() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setDefaultLockGroupStringField("pm2 value");
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testDefaultLockGroupFailure2() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setExplicitDefaultLockGroupIntField(2);
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testNonDefaultLockGroupFailure1() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setLockGroup0IntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup0IntField(2);
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testNonDefaultLockGroupFailure2() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setLockGroup0IntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup0StringField("pm2");
+
+        endTx(pm1);
+        endEm(pm1);
+
+        try {
+            endTx(pm2);
+            fail("should not be able to commit change to same value");
+        } catch (Exception e) {
+            assertEquals(pc2, getFailedObject(e));
+        }
+        endEm(pm2);
+    }
+
+    public void testMultipleLockGroupSuccess1() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+        pc1.setExplicitDefaultLockGroupIntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup0IntField(2);
+
+        OpenJPAEntityManager pm3 = getPM(false, false);
+        startTx(pm3);
+        LockGroupPC pc3 = (LockGroupPC) pm3.find(LockGroupPC.class, oid);
+        pc3.setLockGroup1RelationField(new RuntimeTest1());
+
+        endTx(pm1);
+        endEm(pm1);
+
+        endTx(pm2);
+        endEm(pm2);
+
+        endTx(pm3);
+        endEm(pm3);
+    }
+
+    public void testMultipleLockGroupSuccess2() {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        startTx(pm1);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        pc1.setDefaultLockGroupStringField("pm1 value");
+        pc1.setLockGroup0IntField(1);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class, oid);
+        pc2.setLockGroup1RelationField(new RuntimeTest1());
+
+        endTx(pm2);
+        endEm(pm2);
+
+        endTx(pm1);
+        endEm(pm1);
+    }
+
+//        FIX ME: aokeke - test is taking so much resource and causing subsequent test to fail
+//        public void testNoLockGroupSuccess() {
+//        OpenJPAEntityManager pm1 = getPM(false, false);
+//        startTx(pm1,());
+//        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class,oid);
+//        pc1.setDefaultLockGroupStringField("pm1 value");
+//        pc1.setLockGroup0IntField(1);
+//        pc1.setUnlockedStringField("pm1 value");
+//        
+//        OpenJPAEntityManager pm2 = getPM(false, false);
+//        startTx(pm2,());
+//        LockGroupPC pc2 = (LockGroupPC) pm2.find(LockGroupPC.class,oid);
+//        pc2.setLockGroup1RelationField(new RuntimeTest1());
+//        pc2.setUnlockedStringField("pm2 value");
+//        
+//        endTx(pm1,());
+//        endEm(pm1);
+//        
+//        endTx(pm2,());
+//        endEm(pm2);
+//    }
+
+    public void testAttachDetachSuccess()
+        throws Exception {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        Object detached = pm1.detach(pc1);
+        startTx(pm1);
+        pc1.setLockGroup0IntField(1);
+        pc1.setUnlockedStringField("pm1 changed value");
+        endTx(pm1);
+        endEm(pm1);
+
+        /*
+         // won't work without non-transient detached state
+         ByteArrayOutputStream baos = new ByteArrayOutputStream ();
+         ObjectOutputStream oos = new ObjectOutputStream (baos);
+         oos.writeObject (detached);
+         oos.close ();
+         baos.close ();
+
+         ByteArrayInputStream bais =
+             new ByteArrayInputStream (baos.toByteArray ());
+         ObjectInputStream ois = new ObjectInputStream (bais);
+         LockGroupPC clone = (LockGroupPC) ois.readObject ();
+        */
+        LockGroupPC clone = (LockGroupPC) detached;
+        clone.setLockGroup1IntField(2);
+        clone.setUnlockedStringField("pm2 value");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        pm2.merge(clone);
+        endTx(pm2);
+        endEm(pm2);
+    }
+
+    public void testAttachDetachFailure()
+        throws Exception {
+        OpenJPAEntityManager pm1 = getPM(false, false);
+        LockGroupPC pc1 = (LockGroupPC) pm1.find(LockGroupPC.class, oid);
+        Object detached = pm1.detach(pc1);
+        startTx(pm1);
+        pc1.setLockGroup0IntField(1);
+        endTx(pm1);
+        endEm(pm1);
+
+        /*
+         // won't work without non-transient detached state
+         ByteArrayOutputStream baos = new ByteArrayOutputStream ();
+         ObjectOutputStream oos = new ObjectOutputStream (baos);
+         oos.writeObject (detached);
+         oos.close ();
+         baos.close ();
+
+         ByteArrayInputStream bais =
+             new ByteArrayInputStream (baos.toByteArray ());
+         ObjectInputStream ois = new ObjectInputStream (bais);
+         LockGroupPC clone = (LockGroupPC) ois.readObject ();
+        */
+        LockGroupPC clone = (LockGroupPC) detached;
+        clone.setLockGroup0IntField(2);
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        startTx(pm2);
+        boolean failed = false;
+        try {
+            pm2.merge(clone);
+        } catch (Exception e) {
+            failed = true;
+        }
+
+        if (failed)
+            rollbackTx(pm2);
+        else {
+            try {
+                endTx(pm2);
+                fail("Allowed conflicting changes");
+            } catch (Exception jve) {
+            }
+        }
+    }
+
+    public void testLockGroupNone() {
+        OpenJPAEntityManager pm = getPM(false, false);
+//        pm.begin();
+        deleteAll(LockGroupPC2.class, pm);
+        startTx(pm);
+        LockGroupPC2 pc = new LockGroupPC2();
+        pc.setName("pc");
+        pm.persist(pc);
+        endTx(pm);
+        Object oid = pm.getObjectId(pc);
+        endEm(pm);
+
+        pm = getPM(false, false);
+        pc = (LockGroupPC2) pm.find(LockGroupPC2.class, oid);
+        startTx(pm);
+        pc.getList().add("foo");
+
+        OpenJPAEntityManager pm2 = getPM(false, false);
+        LockGroupPC2 pc2 = (LockGroupPC2) pm2.find(LockGroupPC2.class, oid);
+        startTx(pm2);
+        pc2.getList().add("bar");
+        endTx(pm2);
+        endEm(pm2);
+
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM(false, false);
+        pc = (LockGroupPC2) pm.find(LockGroupPC2.class, oid);
+        assertEquals(2, pc.getList().size());
+        endEm(pm);
+    }
+
+//    public void testKnownSubclass() {
+//        OpenJPAEntityManager pm = getPM(false, false);
+//        LockGroupPCKnownSubclass pc = new LockGroupPCKnownSubclass();
+//        pc.setDefaultLockGroupStringField("pc");
+//        startTx(pm,());
+//        pm.persist(pc);
+//        endTx(pm,());
+//        
+//        startTx(pm,());
+//        pc.setKnownSubclassStringField("foo");
+//        endTx(pm,());
+//    }
+
+    //FIXME jthomas - what do we need to substitute for JDOException ?
+//    private Object getFailedObject(JDOException e) {
+//        return ((JDOException) e.getNestedExceptions()[0]).getFailedObject();
+//    }
+
+    private Object getFailedObject(Exception e) {
+        return null;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPCClass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPCClass.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPCClass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPCClass.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,156 @@
+/*
+ * TestPCClass.java
+ *
+ * Created on October 12, 2006, 4:27 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.kernel;
+
+import java.io.Serializable;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.PCClassInterface;
+import org.apache.openjpa.persistence.kernel.common.apps.PCClassPC;
+
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.meta.JavaTypes;
+import org.apache.openjpa.meta.MetaDataRepository;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestPCClass extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestPCClass
+     */
+    public TestPCClass() {
+    }
+
+    public TestPCClass(String test) {
+        super(test);
+    }
+
+    public void setUp() {
+        deleteAll(PCClassPC.class);
+    }
+
+    public void testMetaData() {
+
+        MetaDataRepository repos = getConfiguration()
+            .getMetaDataRepositoryInstance();
+        ClassMetaData meta = repos.getMetaData(PCClassPC.class, null, true);
+
+        FieldMetaData fmd = meta.getField("specificPC");
+        assertNotNull("fmd is nulll", fmd);
+        assertEquals("JavaTypes.PC != fmd.getTypeCode()", JavaTypes.PC,
+            fmd.getTypeCode());
+        assertEquals("PCClassPC.class.getName() != fmd.getType().getName()",
+            PCClassPC.class.getName(), fmd.getType().getName());
+        assertEquals(
+            "Object.class.getName() != fmd.getDeclaredType().getName()",
+            Object.class.getName(), fmd.getDeclaredType().getName());
+
+        fmd = meta.getField("genericPC");
+        assertNotNull("fmd is null", fmd);
+        assertEquals("JavaTypes.PC_UNTYPE != fmd.getTypeCode()",
+            JavaTypes.PC_UNTYPED, fmd.getTypeCode());
+        assertEquals(
+            "PersistenceCapable.class.getName() != fmd.getType().getName()",
+            PersistenceCapable.class.getName(), fmd.getType().getName());
+        assertEquals(Object.class.getName(),
+            fmd.getDeclaredType().getName());
+
+        fmd = meta.getField("genericObject");
+        assertNotNull(fmd);
+        assertEquals(JavaTypes.OBJECT, fmd.getTypeCode());
+        assertEquals(Object.class.getName(), fmd.getType().getName());
+        assertEquals(Object.class.getName(),
+            fmd.getDeclaredType().getName());
+
+        fmd = meta.getField("specificInterface");
+        assertNotNull(fmd);
+        assertEquals(JavaTypes.PC, fmd.getTypeCode());
+        assertEquals(PCClassPC.class.getName(), fmd.getType().getName());
+        assertEquals(PCClassInterface.class.getName(),
+            fmd.getDeclaredType().getName());
+
+        fmd = meta.getField("defaultInterface");
+        assertNotNull(fmd);
+        assertEquals(JavaTypes.PC_UNTYPED, fmd.getTypeCode());
+        assertEquals(PCClassInterface.class.getName(),
+            fmd.getType().getName());
+        assertEquals(PCClassInterface.class.getName(),
+            fmd.getDeclaredType().getName());
+
+        fmd = meta.getField("serializableInterface");
+        assertNotNull(fmd);
+        assertEquals(JavaTypes.OBJECT, fmd.getTypeCode());
+        assertEquals(Serializable.class.getName(), fmd.getType().getName());
+        assertEquals(Serializable.class.getName(),
+            fmd.getDeclaredType().getName());
+
+        fmd = meta.getField("genericInterface");
+        assertNotNull(fmd);
+        assertEquals(JavaTypes.OBJECT, fmd.getTypeCode());
+        assertEquals(Object.class.getName(), fmd.getType().getName());
+        assertEquals(PCClassInterface.class.getName(),
+            fmd.getDeclaredType().getName());
+    }
+
+    public void testPersist() {
+        PCClassPC pc = new PCClassPC();
+        pc.setSpecificPC(pc);
+        pc.setGenericPC(pc);
+        pc.setGenericObject(pc);
+        pc.setSpecificInterface(pc);
+        pc.setDefaultInterface(pc);
+        pc.setGenericInterface(pc);
+        pc.setSerializableInterface(pc);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+
+        pc = (PCClassPC) pm.find(PCClassPC.class, oid);
+
+        assertTrue(pc == pc.getSpecificPC());
+        assertTrue(pc == pc.getGenericPC());
+        assertNotNull(pc.getGenericObject());
+        assertTrue(pc == pc.getGenericObject());
+        assertTrue(pc == pc.getSpecificInterface());
+        assertTrue(pc == pc.getDefaultInterface());
+        assertNotNull(pc.getGenericInterface());
+        assertTrue(pc == pc.getGenericInterface());
+        assertNotNull(pc.getSerializableInterface());
+        assertTrue(pc == pc.getSerializableInterface());
+
+        endEm(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPMMemory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPMMemory.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPMMemory.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestPMMemory.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,296 @@
+/*
+ * TestPMMemory.java
+ *
+ * Created on October 13, 2006, 3:28 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.kernel;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.event.AbstractTransactionListener;
+import org.apache.openjpa.event.TransactionEvent;
+import org.apache.openjpa.event.TransactionListener;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestPMMemory extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestPMMemory
+     */
+    public TestPMMemory() {
+    }
+
+    public TestPMMemory(String s) {
+        super(s);
+    }
+
+    public boolean skipTest() {
+        return true;
+    }
+
+    private static final boolean _doPause = false;
+    private static final int NUM_OBJECTS = 2000;
+    private static final int NUM_FLUSHES = 5;
+
+    // Hack to run stand alone.
+    public static void main(String[] args)
+        throws Exception {
+        TestPMMemory testpm = new TestPMMemory("testPMMemory");
+        testpm.setUp();
+        testpm.testMemoryUse();
+    }
+
+    public void setUp() {
+        System.out.println("About to delete all");
+        deleteAllStaged(getPM(), RuntimeTest1.class);
+        // deleteAll (RuntimeTest1.class);
+        System.out.println("Done delete all");
+    }
+
+    public void deleteAllStaged(OpenJPAEntityManager pmArg, Class classType) {
+        /*
+          // create 64000 objects
+          // now call this, WITH the datacache on,
+          // and despite using a fetchBatch size,
+          //		this _will_ run out of memory
+          // props:
+  kodo.DataCache: true(CacheSize=5, SoftReferenceSize=1)
+  kodo.RemoteCommitProvider: sjvm
+          */
+        int delCount = 0;
+        OpenJPAEntityManager pm;
+
+        boolean needToDelete = true;
+        while (needToDelete) {
+            pm = getPM();
+            startTx(pm);
+            //pm.setLargeTransaction(true);
+            pm.setTrackChangesByType(true);
+            String cstrng = classType.getName();
+            OpenJPAQuery kq = pm.createQuery("SELECT o FROM " + cstrng + " o");
+            kq.getFetchPlan().setFetchBatchSize(100);
+            Collection results = (Collection) kq.getResultList();
+            if (results.size() == 0) {
+                needToDelete = false;
+                break;
+            }
+            System.out.println("We need to delete " + results.size());
+            Iterator iter = results.iterator();
+            while (iter.hasNext()) {
+                pm.remove(iter.next());
+                delCount += 1;
+                if ((delCount % 800) == 0) {
+                    pm.flush();
+                    // is the trans cahce now holding
+                    // all these objects?
+                    break;
+                }
+            }
+            System.out.print("deleted 200");
+            endTx(pm);
+            endEm(pm);
+        }
+        System.out.println("Done deleting");
+    }
+
+    private void reportMemory() {
+        reportMemory("Memory used");
+        /*
+      DataCacheImpl dc;
+      dc = (DataCacheImpl) kpm.getConfiguration ().getDataCacheManager ().
+          getDataCache ()
+      CacheMap cacheMap = dc.getCacheMap ();
+      values/keySet
+      */
+    }
+
+    private void reportMemory(String msg) {
+        System.gc();
+        long memUsed = Runtime.getRuntime().totalMemory();
+        long memFree = Runtime.getRuntime().freeMemory();
+        System.out.println("" + msg + " : " + memUsed + ", " +
+            memFree);
+    }
+
+    private void pause(double seconds) {
+        if (!_doPause)
+            return;
+        try {
+            Thread.currentThread().yield();
+            Thread.currentThread().sleep((int) seconds * 1000);
+        } catch (Exception e) {
+        }
+    }
+
+    public void testMemoryUse() throws Exception {
+
+        System.out.println("Baseline, starting memory for N objects of " +
+            NUM_OBJECTS);
+        OpenJPAEntityManagerFactory kpmf =
+            (OpenJPAEntityManagerFactory) getEmf();
+        OpenJPAEntityManager kpm = (OpenJPAEntityManager)
+            kpmf.createEntityManager();
+
+        startTx(kpm);
+        int runningId = performAddsModifiesDeletes(kpm, NUM_OBJECTS, 0);
+        endTx(kpm);
+
+        System.out.println("Baseline, starting memory ");
+        reportMemory();
+
+        TransactionListener l = new AbstractTransactionListener() {
+            public void afterCommit(TransactionEvent ev) {
+                System.out.println(
+                    "My Listener in afterCommit");
+                System.out.println(
+                    "Num objects in transaction "
+                        + ev.getTransactionalObjects().size());
+
+                // send out an email confirming that the
+                // transaction was a success
+            }
+        };
+
+        // kpm.registerListener (l);
+
+        // jprobe, jprofiler.
+        // prefer treeview
+
+        // Run a transaction for a whilw and report memory
+        startTx(kpm);
+        int objCount = 0;
+        for (int i = 0; i < NUM_FLUSHES; i++) {
+            System.out.println();
+            System.out.println("Iteration #" + i + " created " +
+                objCount);
+            reportMemory();
+            //kpm.setLargeTransaction(true);
+            kpm.setTrackChangesByType(true);
+            runningId = performAddsModifiesDeletes(kpm, NUM_OBJECTS, runningId);
+            objCount += NUM_OBJECTS;
+            kpm.flush();
+            grabAllMemory();
+            //    pause(30);
+        }
+
+        System.out.println("Created objects, about to commit ()");
+        pause(90);
+        endTx(kpm);
+        pause(1);
+        System.out.println("Now commit ()");
+        reportMemory();
+        pause(33);
+    }
+
+    protected void grabAllMemory() {
+        // exhaust all memory so that GC is run.
+        int size = 4096;
+        boolean grab = true;
+        int[] glob;
+        while (grab) {
+            try {
+                glob = new int[size];
+                size *= 2;
+            } catch (OutOfMemoryError e) {
+                System.out.println("Mem grabbed " + size);
+                grab = false;
+                glob = null;
+            }
+        }
+        glob = null;
+    }
+
+    protected int performAddsModifiesDeletes(OpenJPAEntityManager pm,
+        int numObjects, int runningId) {
+        // pm should be active. Function does not perform commit.
+
+        // Perform a series of transactions that will trigger adds,
+        // deletes, and udpates
+
+        // create objects
+        RuntimeTest1[] persistables = new RuntimeTest1[numObjects];
+        for (int i = 0; i < persistables.length; i++) {
+            persistables[i] = new RuntimeTest1("foo #" + i, runningId + i);
+        }
+        runningId += persistables.length;
+
+        // add them
+        for (int i = 0; i < persistables.length; i++) {
+            pm.persist(persistables[i]);
+        }
+
+        // modify them
+        for (int i = 0; i < persistables.length; i++) {
+            persistables[i].setIntField1(i + 1);
+        }
+
+/*
+		// delete them
+		for (int i = 0; i < persistables.length; i++)
+		{
+			pm.deletePersistent (persistables [i]);
+		}
+*/
+        return runningId + 1;
+    }
+
+    static int _fetchGroupSerial = 0;
+
+    protected OpenJPAEntityManagerFactory createDistinctFactory(
+        Class providerClass, String classProps1) {
+        Map props = null;
+
+        //FIXME jthomas
+        /*
+        if (providerClass != null) {
+            props = new String[]{
+                "openjpa.RemoteCommitProvider", Configurations.getPlugin(
+                providerClass.getNameclassProps1),
+                // use this property to differentiate the factory
+                "openjpa.FetchGroups", "differentiatingFetchGroup" +
+                _fetchGroupSerial,
+            };
+        } else {
+            // No RCP
+            props = new String[]{
+                // use this property to differentiate the factory
+                "openjpa.RemoteCommitProvider", "sjvm",
+                "openjpa.FetchGroups", "differentiatingFetchGroup" +
+                _fetchGroupSerial,
+            };
+        }
+        _fetchGroupSerial += 1;
+         */
+
+        return (OpenJPAEntityManagerFactory) getEmf(props);
+    }
+}



Mime
View raw message