openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [20/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/jdbc/meta/TestEagerOuterToManyJoins.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestEagerOuterToManyJoins.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestEagerOuterToManyJoins.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestEagerOuterToManyJoins.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,874 @@
+/*
+ * TestEagerOuterToManyJoins.java
+ *
+ * Created on October 3, 2006, 10:53 AM
+ *
+ * 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.kernel.Query;
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.jdbc.common.apps.EagerOuterJoinPC;
+
+
+public class TestEagerOuterToManyJoins extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+    
+    /** Creates a new instance of TestEagerOuterToManyJoins */
+    public TestEagerOuterToManyJoins(String name) {
+    	super(name);
+    }
+    
+    public boolean skipTest() {
+        DBDictionary dict = ((JDBCConfiguration) getConfiguration()).
+                getDBDictionaryInstance();
+        return !dict.supportsSubselect;
+    }
+    
+    public void setUp() {
+        
+       deleteAll(HelperPC.class);
+       deleteAll(EagerOuterJoinPC2.class);
+       deleteAll(EagerOuterJoinPC.class);
+    }
+    
+    
+    public void testStringCollectionById() {
+        stringCollectionByIdTest(false);
+    }
+    
+    public void testEmptyStringCollectionById() {
+        stringCollectionByIdTest(true);
+    }
+    
+    private void stringCollectionByIdTest(boolean empty) {
+        Object oid = insertStringCollection((empty) ? 1 : 0);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
+        assertEquals("1", pc.getName());
+        if (empty)
+            assertEquals(pc.getStringCollection().toString(),
+                    0, pc.getStringCollection().size());
+        else {
+            assertEquals(pc.getStringCollection().toString(),
+                    2, pc.getStringCollection().size());
+            assertTrue(pc.getStringCollection().contains("1.1"));
+            assertTrue(pc.getStringCollection().contains("1.2"));
+        }
+        pm.close();
+    }
+    
+    public void testStringCollectionByQuery() {
+        stringCollectionByQueryTest(0);
+    }
+    
+    public void testEmptyStringCollectionByQuery1() {
+        stringCollectionByQueryTest(1);
+    }
+    
+    public void testEmptyStringCollectionByQuery2() {
+        stringCollectionByQueryTest(2);
+    }
+    
+    public void testEmptyStringCollectionByQuery3() {
+        stringCollectionByQueryTest(3);
+    }
+    
+    private void stringCollectionByQueryTest(int empty) {
+        insertStringCollection(empty);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
+        fetch.setFetchBatchSize(-1);
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        
+        assertEquals(2, results.size());
+        Iterator itr = results.iterator();
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("1", pc.getName());
+        if ((empty & 1) > 0)
+            assertEquals(pc.getStringCollection().toString(),
+                    0, pc.getStringCollection().size());
+        else {
+            assertEquals(pc.getStringCollection().toString(),
+                    2, pc.getStringCollection().size());
+            assertTrue(pc.getStringCollection().contains("1.1"));
+            assertTrue(pc.getStringCollection().contains("1.2"));
+        }
+        
+        pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("2", pc.getName());
+        if ((empty & 2) > 0)
+            assertEquals(pc.getStringCollection().toString(),
+                    0, pc.getStringCollection().size());
+        else {
+            assertEquals(pc.getStringCollection().toString(),
+                    2, pc.getStringCollection().size());
+            assertTrue(pc.getStringCollection().contains("2.1"));
+            assertTrue(pc.getStringCollection().contains("2.2"));
+        }
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    private Object insertStringCollection(int empty) {
+        EagerOuterJoinPC pc1 = new EagerOuterJoinPC();
+        pc1.setName("1");
+        if ((empty & 1) == 0) {
+            pc1.getStringCollection().add("1.1");
+            pc1.getStringCollection().add("1.2");
+        }
+        
+        EagerOuterJoinPC pc2 = new EagerOuterJoinPC();
+        pc2.setName("2");
+        if ((empty & 2) == 0) {
+            pc2.getStringCollection().add("2.1");
+            pc2.getStringCollection().add("2.2");
+        }
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        
+        startTx(pm);;
+        pm.persist(pc1);
+        pm.persist(pc2);
+        endTx(pm);;
+        Object oid = pm.getObjectId(pc1);
+        pm.close();
+        return oid;
+    }
+    
+    public void testStringListById() {
+        Object oid = insertStringList();
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        
+        
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringList");
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getStringList().size());
+        assertEquals("1.1", pc.getStringList().get(0));
+        assertEquals("1.2", pc.getStringList().get(1));
+        pm.close();
+    }
+    
+    public void testStringListByQuery() {
+        insertStringList();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringList");
+        fetch.setFetchBatchSize(-1);
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        
+        assertEquals(2, results.size());
+        Iterator itr = results.iterator();
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getStringList().size());
+        assertEquals("1.1", pc.getStringList().get(0));
+        assertEquals("1.2", pc.getStringList().get(1));
+        pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("2", pc.getName());
+        assertEquals(2, pc.getStringList().size());
+        assertEquals("2.1", pc.getStringList().get(0));
+        assertEquals("2.2", pc.getStringList().get(1));
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    private Object insertStringList() {
+        EagerOuterJoinPC pc1 = new EagerOuterJoinPC();
+        pc1.setName("1");
+        pc1.getStringList().add("1.1");
+        pc1.getStringList().add("1.2");
+        
+        EagerOuterJoinPC pc2 = new EagerOuterJoinPC();
+        pc2.setName("2");
+        pc2.getStringList().add("2.1");
+        pc2.getStringList().add("2.2");
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        pm.persist(pc1);
+        pm.persist(pc2);
+        endTx(pm);;
+        Object oid = pm.getObjectId(pc1);
+        pm.close();
+        return oid;
+    }
+    
+    public void testOneManyCollectionById() {
+        oneManyCollectionByIdTest(false);
+    }
+    
+    public void testEmptyOneManyCollectionById() {
+        oneManyCollectionByIdTest(true);
+    }
+    
+    private void oneManyCollectionByIdTest(boolean empty) {
+        Object oid = insertOneManyCollection((empty) ? 1 : 0);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "oneManyCollection");
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
+        assertEquals("1", pc.getName());
+        if (empty)
+            assertEquals(0, pc.getOneManyCollection().size());
+        else
+            assertEquals(2, pc.getOneManyCollection().size());
+        pm.close();
+    }
+    
+    public void testOneManyCollectionByQuery() {
+        oneManyCollectionByQueryTest(0);
+    }
+    
+    public void testEmptyOneManyCollectionByQuery1() {
+        oneManyCollectionByQueryTest(1);
+    }
+    
+    public void testEmptyOneManyCollectionByQuery2() {
+        oneManyCollectionByQueryTest(2);
+    }
+    
+    public void testEmptyOneManyCollectionByQuery3() {
+        oneManyCollectionByQueryTest(3);
+    }
+    
+    private void oneManyCollectionByQueryTest(int empty) {
+        insertOneManyCollection(empty);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "oneManyCollection");
+        fetch.setFetchBatchSize(-1);
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        
+        assertEquals(2, results.size());
+        Iterator itr = results.iterator();
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("1", pc.getName());
+        if ((empty & 1) > 0)
+            assertEquals(0, pc.getOneManyCollection().size());
+        else
+            assertEquals(2, pc.getOneManyCollection().size());
+        
+        pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("2", pc.getName());
+        if ((empty & 2) > 0)
+            assertEquals(0, pc.getOneManyCollection().size());
+        else
+            assertEquals(2, pc.getOneManyCollection().size());
+        
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    private Object insertOneManyCollection(int empty) {
+        EagerOuterJoinPC pc1 = new EagerOuterJoinPC();
+        pc1.setName("1");
+        EagerOuterJoinPC2 hpc;
+        if ((empty & 1) == 0) {
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("1.1");
+            hpc.setRef(pc1);
+            pc1.getOneManyCollection().add(hpc);
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("1.2");
+            hpc.setRef(pc1);
+            pc1.getOneManyCollection().add(hpc);
+        }
+        
+        EagerOuterJoinPC pc2 = new EagerOuterJoinPC();
+        pc2.setName("2");
+        if ((empty & 2) == 0) {
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("2.1");
+            hpc.setRef(pc2);
+            pc2.getOneManyCollection().add(hpc);
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("2.2");
+            hpc.setRef(pc2);
+            pc2.getOneManyCollection().add(hpc);
+        }
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        pm.persist(pc1);
+        pm.persist(pc2);
+        endTx(pm);
+        Object oid = pm.getObjectId(pc1);
+        pm.close();
+        return oid;
+    }
+    
+    public void testManyManyCollectionById() {
+        Object oid = insertManyManyCollection();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "manyManyCollection");
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getManyManyCollection().size());
+        pm.close();
+    }
+    
+    public void testManyManyCollectionByQuery() {
+        insertManyManyCollection();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "manyManyCollection");
+        fetch.setFetchBatchSize(-1);
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        
+        assertEquals(2, results.size());
+        Iterator itr = results.iterator();
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getManyManyCollection().size());
+        pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("2", pc.getName());
+        assertEquals(2, pc.getManyManyCollection().size());
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    private Object insertManyManyCollection() {
+        EagerOuterJoinPC pc1 = new EagerOuterJoinPC();
+        pc1.setName("1");
+        EagerOuterJoinPC2 hpc = new EagerOuterJoinPC2();
+        hpc.setName("1.1");
+        pc1.getManyManyCollection().add(hpc);
+        hpc = new EagerOuterJoinPC2();
+        hpc.setName("1.2");
+        pc1.getManyManyCollection().add(hpc);
+        
+        EagerOuterJoinPC pc2 = new EagerOuterJoinPC();
+        pc2.setName("2");
+        hpc = new EagerOuterJoinPC2();
+        hpc.setName("2.1");
+        pc2.getManyManyCollection().add(hpc);
+        hpc = new EagerOuterJoinPC2();
+        hpc.setName("2.2");
+        pc2.getManyManyCollection().add(hpc);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        pm.persist(pc1);
+        pm.persist(pc2);
+        endTx(pm);;
+        Object oid = pm.getObjectId(pc1);
+        pm.close();
+        return oid;
+    }
+    
+    public void testManyManyListById() {
+        manyManyListByIdTest(false);
+    }
+    
+    public void testEmptyManyManyListById() {
+        manyManyListByIdTest(true);
+    }
+    
+    private void manyManyListByIdTest(boolean empty) {
+        Object oid = insertManyManyList((empty) ? 1 : 0);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
+        assertEquals("1", pc.getName());
+        if (empty)
+            assertEquals(0, pc.getManyManyList().size());
+        else {
+            assertEquals(2, pc.getManyManyList().size());
+            EagerOuterJoinPC2 hpc = (EagerOuterJoinPC2)
+            pc.getManyManyList().get(0);
+            assertEquals("1.1", hpc.getName());
+            hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+            assertEquals("1.2", hpc.getName());
+        }
+        pm.close();
+    }
+    
+    public void testManyManyListByQuery() {
+        manyManyListByQueryTest(0);
+    }
+    
+    public void testEmptyManyManyListByQuery1() {
+        manyManyListByQueryTest(1);
+    }
+    
+    public void testEmptyManyManyListByQuery2() {
+        manyManyListByQueryTest(2);
+    }
+    
+    public void testEmptyManyManyListByQuery3() {
+        manyManyListByQueryTest(3);
+    }
+    
+    private void manyManyListByQueryTest(int empty) {
+        insertManyManyList(empty);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
+        fetch.setFetchBatchSize(-1);
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        
+        assertEquals(2, results.size());
+        Iterator itr = results.iterator();
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("1", pc.getName());
+        EagerOuterJoinPC2 hpc;
+        if ((empty & 1) > 0)
+            assertEquals(0, pc.getManyManyList().size());
+        else {
+            assertEquals(2, pc.getManyManyList().size());
+            hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(0);
+            assertEquals("1.1", hpc.getName());
+            hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+            assertEquals("1.2", hpc.getName());
+        }
+        
+        pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("2", pc.getName());
+        if ((empty & 2) > 0)
+            assertEquals(0, pc.getManyManyList().size());
+        else {
+            assertEquals(2, pc.getManyManyList().size());
+            hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(0);
+            assertEquals("2.1", hpc.getName());
+            hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+            assertEquals("2.2", hpc.getName());
+        }
+        
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    private Object insertManyManyList(int empty) {
+        EagerOuterJoinPC pc1 = new EagerOuterJoinPC();
+        pc1.setName("1");
+        EagerOuterJoinPC2 hpc;
+        if ((empty & 1) == 0) {
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("1.1");
+            pc1.getManyManyList().add(hpc);
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("1.2");
+            pc1.getManyManyList().add(hpc);
+        }
+        
+        EagerOuterJoinPC pc2 = new EagerOuterJoinPC();
+        pc2.setName("2");
+        if ((empty & 2) == 0) {
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("2.1");
+            pc2.getManyManyList().add(hpc);
+            hpc = new EagerOuterJoinPC2();
+            hpc.setName("2.2");
+            pc2.getManyManyList().add(hpc);
+        }
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        pm.persist(pc1);
+        pm.persist(pc2);
+        endTx(pm);;
+        Object oid = pm.getObjectId(pc1);
+        pm.close();
+        return oid;
+    }
+    
+    public void testTwoCollectionsInFetchGroupsById() {
+        Object oid = insertTwoCollections();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
+        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) pm.getObjectId(oid);
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getStringCollection().size());
+        assertTrue(pc.getStringCollection().contains("1.1"));
+        assertTrue(pc.getStringCollection().contains("1.2"));
+        assertEquals(2, pc.getManyManyList().size());
+        EagerOuterJoinPC2 hpc = (EagerOuterJoinPC2)
+        pc.getManyManyList().get(0);
+        assertEquals("1.1", hpc.getName());
+        hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+        assertEquals("1.2", hpc.getName());
+        pm.close();
+    }
+    
+    public void testTwoCollectionsInFetchGroupsByQuery() {
+        insertTwoCollections();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
+        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
+        fetch.setFetchBatchSize(-1);
+        
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        
+        assertEquals(2, results.size());
+        Iterator itr = results.iterator();
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getStringCollection().size());
+        assertTrue(pc.getStringCollection().contains("1.1"));
+        assertTrue(pc.getStringCollection().contains("1.2"));
+        assertEquals(2, pc.getManyManyList().size());
+        EagerOuterJoinPC2 hpc = (EagerOuterJoinPC2)
+        pc.getManyManyList().get(0);
+        assertEquals("1.1", hpc.getName());
+        hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+        assertEquals("1.2", hpc.getName());
+        
+        pc = (EagerOuterJoinPC) itr.next();
+        assertEquals("2", pc.getName());
+        assertEquals(2, pc.getStringCollection().size());
+        assertTrue(pc.getStringCollection().contains("2.1"));
+        assertTrue(pc.getStringCollection().contains("2.2"));
+        assertEquals(2, pc.getManyManyList().size());
+        hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(0);
+        assertEquals("2.1", hpc.getName());
+        hpc = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+        assertEquals("2.2", hpc.getName());
+        
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    private Object insertTwoCollections() {
+        EagerOuterJoinPC pc1 = new EagerOuterJoinPC();
+        pc1.setName("1");
+        pc1.getStringCollection().add("1.1");
+        pc1.getStringCollection().add("1.2");
+        EagerOuterJoinPC2 hpc = new EagerOuterJoinPC2();
+        hpc.setName("1.1");
+        pc1.getManyManyList().add(hpc);
+        hpc = new EagerOuterJoinPC2();
+        hpc.setName("1.2");
+        pc1.getManyManyList().add(hpc);
+        
+        EagerOuterJoinPC pc2 = new EagerOuterJoinPC();
+        pc2.setName("2");
+        pc2.getStringCollection().add("2.1");
+        pc2.getStringCollection().add("2.2");
+        hpc = new EagerOuterJoinPC2();
+        hpc.setName("2.1");
+        pc2.getManyManyList().add(hpc);
+        hpc = new EagerOuterJoinPC2();
+        hpc.setName("2.2");
+        pc2.getManyManyList().add(hpc);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        pm.persist(pc1);
+        pm.persist(pc2);
+        endTx(pm);;
+        Object oid = pm.getObjectId(pc1);
+        pm.close();
+        return oid;
+    }
+    
+    public void testQueryRandomAccess() {
+        insertManyStringList();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringList");
+        fetch.setFetchBatchSize(3);
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        List results = (List) q.getResultList();
+        assertEquals(10, results.size());
+        
+        for (int i = 5; i < results.size(); i++) {
+            EagerOuterJoinPC pc = (EagerOuterJoinPC) results.get(i);
+            assertEquals(String.valueOf(i), pc.getName());
+            assertEquals(2, pc.getStringList().size());
+            assertEquals(i + ".1", pc.getStringList().get(0));
+            assertEquals(i + ".2", pc.getStringList().get(1));
+        }
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testQueryRange() {
+        insertManyStringList();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "stringList");
+        fetch.setFetchBatchSize(3);
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        //q.setRange(5, 20);
+        
+        List results = (List) q.getResultList();
+        assertEquals(5, results.size());
+        
+        for (int i = 0; i < results.size(); i++) {
+            EagerOuterJoinPC pc = (EagerOuterJoinPC) results.get(i);
+            assertEquals(String.valueOf(i + 5), pc.getName());
+            assertEquals(2, pc.getStringList().size());
+            assertEquals((i + 5) + ".1", pc.getStringList().get(0));
+            assertEquals((i + 5) + ".2", pc.getStringList().get(1));
+        }
+        q.closeAll();
+        pm.close();
+    }
+    
+    private void insertManyStringList() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        for (int i = 0; i < 10; i++) {
+            EagerOuterJoinPC pc = new EagerOuterJoinPC();
+            pc.setName(String.valueOf(i));
+            pc.getStringList().add(i + ".1");
+            pc.getStringList().add(i + ".2");
+            pm.persist(pc);
+        }
+        endTx(pm);;
+        pm.close();
+    }
+    
+    public void testEagerToOneThenEagerToMany() {
+        insertEagers();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC2.class, "ref");
+        fetch.addField(EagerOuterJoinPC.class, "stringCollection");
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC2.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        assertEquals(new ArrayList(results).toString(), 2, results.size());
+        
+        Iterator itr = results.iterator();
+        EagerOuterJoinPC2 ref = (EagerOuterJoinPC2) itr.next();
+        assertEquals("r1", ref.getName());
+        EagerOuterJoinPC pc = ref.getRef();
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getStringCollection().size());
+        assertTrue(pc.getStringCollection().contains("1.1"));
+        assertTrue(pc.getStringCollection().contains("1.2"));
+        
+        ref = (EagerOuterJoinPC2) itr.next();
+        assertEquals("r2", ref.getName());
+        assertTrue(pc == ref.getRef());
+        
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    public void testEagerToManyThenEagerToOne() {
+        insertEagers();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
+        fetch.addField(EagerOuterJoinPC2.class, "helper");
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        assertEquals(1, results.size());
+        
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) results.iterator().next();
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getManyManyList().size());
+        EagerOuterJoinPC2 ref = (EagerOuterJoinPC2)
+        pc.getManyManyList().get(0);
+        assertEquals("r1", ref.getName());
+        assertEquals("h1", ref.getHelper().getStringField());
+        ref = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+        assertEquals("r2", ref.getName());
+        assertEquals("h2", ref.getHelper().getStringField());
+        
+        pm.close();
+    }
+    
+    public void testEagerToManyThenEagerToMany() {
+        insertEagers();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "manyManyList");
+        fetch.addField(EagerOuterJoinPC2.class, "stringCollection");
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        assertEquals(1, results.size());
+        
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) results.iterator().next();
+        assertEquals("1", pc.getName());
+        assertEquals(2, pc.getManyManyList().size());
+        EagerOuterJoinPC2 ref = (EagerOuterJoinPC2)
+        pc.getManyManyList().get(0);
+        assertEquals("r1", ref.getName());
+        assertEquals(2, ref.getStringCollection().size());
+        assertTrue(ref.getStringCollection().contains("r1.1"));
+        assertTrue(ref.getStringCollection().contains("r1.2"));
+        
+        ref = (EagerOuterJoinPC2) pc.getManyManyList().get(1);
+        assertEquals("r2", ref.getName());
+        assertEquals(2, ref.getStringCollection().size());
+        assertTrue(ref.getStringCollection().contains("r2.1"));
+        assertTrue(ref.getStringCollection().contains("r2.2"));
+        
+        pm.close();
+    }
+    
+    public void testEagerToOneAndToManyThenEagerToOne() {
+        Object oid = insertEagers();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        FetchPlan fetch = (FetchPlan) pm.getFetchPlan();
+        fetch.addField(EagerOuterJoinPC.class, "oneManyCollection");
+        fetch.addField(EagerOuterJoinPC.class, "helper");
+        fetch.addField(EagerOuterJoinPC2.class, "helper");
+        OpenJPAQuery q = pm.createNativeQuery("",EagerOuterJoinPC.class);
+        //FIXME jthomas
+        //q.setOrdering("name ascending");
+        Collection results = (Collection) q.getResultList();
+        assertEquals(1, results.size());
+        
+        EagerOuterJoinPC pc = (EagerOuterJoinPC) results.iterator().next();
+        assertEquals("1", pc.getName());
+        assertEquals("h3", pc.getHelper().getStringField());
+        assertEquals(2, pc.getOneManyCollection().size());
+        Iterator itr = pc.getOneManyCollection().iterator();
+        EagerOuterJoinPC2 ref = (EagerOuterJoinPC2) itr.next();
+        if ("r1".equals(ref.getName())) {
+            assertEquals("h1", ref.getHelper().getStringField());
+            ref = (EagerOuterJoinPC2) itr.next();
+            assertEquals("r2", ref.getName());
+            assertEquals("h2", ref.getHelper().getStringField());
+        } else {
+            assertEquals("r2", ref.getName());
+            assertEquals("h2", ref.getHelper().getStringField());
+            ref = (EagerOuterJoinPC2) itr.next();
+            assertEquals("r1", ref.getName());
+            assertEquals("h1", ref.getHelper().getStringField());
+        }
+        assertTrue(!itr.hasNext());
+        pm.close();
+    }
+    
+    private Object insertEagers() {
+        EagerOuterJoinPC pc1 = new EagerOuterJoinPC();
+        pc1.setName("1");
+        pc1.getStringCollection().add("1.1");
+        pc1.getStringCollection().add("1.2");
+        
+        EagerOuterJoinPC2 ref1 = new EagerOuterJoinPC2();
+        ref1.setName("r1");
+        ref1.getStringCollection().add("r1.1");
+        ref1.getStringCollection().add("r1.2");
+        
+        EagerOuterJoinPC2 ref2 = new EagerOuterJoinPC2();
+        ref2.setName("r2");
+        ref2.getStringCollection().add("r2.1");
+        ref2.getStringCollection().add("r2.2");
+        
+        HelperPC hpc1 = new HelperPC();
+        hpc1.setStringField("h1");
+        
+        HelperPC hpc2 = new HelperPC();
+        hpc2.setStringField("h2");
+        
+        HelperPC hpc3 = new HelperPC();
+        hpc3.setStringField("h3");
+        
+        pc1.getManyManyList().add(ref1);
+        pc1.getOneManyCollection().add(ref1);
+        ref1.setRef(pc1);
+        pc1.getManyManyList().add(ref2);
+        pc1.getOneManyCollection().add(ref2);
+        ref2.setRef(pc1);
+        
+        ref1.setHelper(hpc1);
+        ref2.setHelper(hpc2);
+        pc1.setHelper(hpc3);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        pm.persist(pc1);
+        endTx(pm);;
+        Object oid = pm.getObjectId(pc1);
+        pm.close();
+        return oid;
+    }
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIntermediate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIntermediate.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIntermediate.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIntermediate.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,132 @@
+/*
+ * TestIntermediate.java
+ *
+ * Created on October 3, 2006, 12:01 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.BrokerFactory;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestIntermediate extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{
+    
+    private Object _pc;
+    private Object _rel;
+    
+    public TestIntermediate(String test) {
+        super(test);
+    }
+    
+    /** Creates a new instance of TestIntermediate */
+    public TestIntermediate() {
+    }
+    
+    public void setUp() {
+        RuntimeTest1 pc = new RuntimeTest1("pc", 1);
+        RuntimeTest1 rel = new RuntimeTest1("rel", 2);
+        pc.setSelfOneOne(rel);
+        
+        OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
+        Broker broker = JPAFacadeHelper.toBroker(em);
+        broker.begin();
+        broker.persist(pc, null);
+        broker.commit();
+        _pc = broker.getObjectId(pc);
+        _rel = broker.getObjectId(rel);
+        broker.close();
+        em.close();
+    }
+    
+    public void testOneOneSetsIntermediate() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
+        Broker broker = JPAFacadeHelper.toBroker(em);
+        try {
+            oneOneIntermediateTest(broker);
+        } finally {
+            broker.close();
+            em.close();
+        }
+    }
+    
+    public void testDataCacheOneOneSetsIntermediate() {
+        BrokerFactory factory = getBrokerFactory(new String[]{
+            "openjpa.DataCache", "true",
+            "openjpa.RemoteCommitProvider", "sjvm",
+        });
+        
+        // get obj into cache
+        Broker broker = factory.newBroker();
+        try {
+            broker.find(_pc, true, null);
+        } finally {
+            broker.close();
+        }
+        
+        // test from cache
+        broker = factory.newBroker();
+        try {
+            oneOneIntermediateTest(broker);
+        } finally {
+            broker.close();
+            try {
+                factory.close();
+            } catch (Exception e) {
+            }
+        }
+    }
+    
+    /**
+     * Helper method to see that the one to one uses an intermediate values.
+     */
+    private void oneOneIntermediateTest(Broker broker) {
+        RuntimeTest1 pc = (RuntimeTest1) broker.find(_pc, true, null);
+        OpenJPAStateManager sm = broker.getStateManager(pc);
+        assertNotNull(sm);
+        FieldMetaData fmd = sm.getMetaData().getField("selfOneOne");
+        assertNotNull(fmd);
+        assertEquals(_rel, sm.getIntermediate(fmd.getIndex()));
+        assertEquals(_rel, broker.getObjectId(pc.getSelfOneOne()));
+        assertNull(sm.getIntermediate(fmd.getIndex()));
+    }
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIrregularJoins.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIrregularJoins.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIrregularJoins.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestIrregularJoins.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,363 @@
+/*
+ * TestIrregularJoins.java
+ *
+ * Created on October 3, 2006, 12:47 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.jdbc.meta;
+
+import java.util.*;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.jdbc.common.apps.NonPKJoinPC2;
+
+
+
+public class TestIrregularJoins extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+    
+
+    private Object _nonpk = null;
+    private Object _nonpk3 = null;
+    private Object _partial = null;
+    private Object _partial3 = null;
+    private Object _constant2 = null;
+    private Object _constant3 = null;
+
+    public TestIrregularJoins(String test) {
+        super(test);
+    }
+    
+    /** Creates a new instance of TestIrregularJoins */
+    public TestIrregularJoins() {
+    }
+
+    public void setUp()
+        throws Exception {
+        // make sure these classes are registered since we're using metadata
+        // values for the class indicator
+        new ConstantJoinPC();
+        new ConstantJoinPC2();
+        new ConstantJoinPC3();
+
+       deleteAll(PartialJoinPC.class);
+       deleteAll(NonPKJoinPC.class);
+       deleteAll(ConstantJoinPC.class);
+
+        PartialJoinPC partial = new PartialJoinPC();
+        partial.setPk1(1);
+        partial.setPk2(2);
+        PartialJoinPC2 partial2 = new PartialJoinPC2();
+        partial2.setPk1(2);
+        partial2.setPk2(3);
+        PartialJoinPC3 partial3 = new PartialJoinPC3();
+        partial3.setPk1(3);
+        partial3.setPk2(4);
+
+        NonPKJoinPC nonpk = new NonPKJoinPC();
+        nonpk.setId1(1);
+        nonpk.setId2(2);
+        NonPKJoinPC2 nonpk2 = new NonPKJoinPC2();
+        nonpk2.setId1(2);
+        nonpk2.setId2(3);
+        NonPKJoinPC3 nonpk3 = new NonPKJoinPC3();
+        nonpk3.setId1(3);
+        nonpk3.setId2(4);
+
+        partial.setNonPK(nonpk);
+        partial.getNonPKs().add(nonpk);
+        nonpk.setPartial(partial);
+        nonpk.getPartials().add(partial);
+
+        partial3.setNonPK(nonpk);
+        partial3.setNonPK3(nonpk3);
+        partial3.getNonPKs().add(nonpk);
+        partial3.getNonPK2s().add(nonpk2);
+        nonpk3.setPartial(partial);
+        nonpk3.setPartial3(partial3);
+        nonpk3.getPartials().add(partial);
+        nonpk3.getPartial2s().add(partial2);
+
+        ConstantJoinPC2 constant2 = new ConstantJoinPC2();
+        constant2.setPk1(1);
+        constant2.setPk2(2);
+        constant2.setNonPK(nonpk3);
+        constant2.setNonPK2(nonpk3);
+
+        // set the object's inverse on diff objects so we can be sure
+        // that its 1-many includes only the object with the right constant
+        nonpk.setConstant(constant2);
+        nonpk2.setConstant(constant2);
+        nonpk3.setConstant(constant2);
+
+        ConstantJoinPC3 constant3 = new ConstantJoinPC3();
+        constant3.setPk1(1);
+        constant3.setPk2(3);
+
+        OpenJPAEntityManager pm =(OpenJPAEntityManager) currentEntityManager();
+        startTx(pm);
+        
+        pm.persist(partial);
+        pm.persist(partial3);
+        pm.persist(constant2);
+        pm.persist(constant3);
+        endTx(pm);
+        _partial = pm.getObjectId(partial);
+        _partial3 = pm.getObjectId(partial3);
+        _nonpk = pm.getObjectId(nonpk);
+        _nonpk3 = pm.getObjectId(nonpk3);
+        _constant2 = pm.getObjectId(constant2);
+        _constant3 = pm.getObjectId(constant3);
+        pm.close();
+    }
+
+    public void testNonPKOneOne() {
+        
+        nonPKOneOne((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerNonPKOneOne() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("nonPK");
+        nonPKOneOne(pm);
+    }
+
+    private void nonPKOneOne(OpenJPAEntityManager pm) {
+        PartialJoinPC partial = (PartialJoinPC) pm.getObjectId(_partial);
+        NonPKJoinPC nonpk = partial.getNonPK();
+        assertEquals(1, nonpk.getId1());
+        assertEquals(2, nonpk.getId2());
+        pm.close();
+    }
+
+    public void testPartialOneOne() {
+        partialOneOne((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerPartialOneOne() {
+        
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("partial");
+        partialOneOne(pm);
+    }
+
+    private void partialOneOne(OpenJPAEntityManager pm) {
+        NonPKJoinPC nonpk = (NonPKJoinPC) pm.getObjectId(_nonpk);
+        PartialJoinPC partial = nonpk.getPartial();
+        assertEquals(1, partial.getPk1());
+        assertEquals(2, partial.getPk2());
+        pm.close();
+    }
+
+    public void testVerticalNonPKOneOne() {
+        verticalNonPKOneOne((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerVerticalNonPKOneOne() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("nonPK3");
+        verticalNonPKOneOne(pm);
+    }
+
+    private void verticalNonPKOneOne(OpenJPAEntityManager pm) {
+        PartialJoinPC3 partial3 = (PartialJoinPC3) pm.getObjectId(_partial3);
+        NonPKJoinPC nonpk = partial3.getNonPK();
+        assertEquals(1, nonpk.getId1());
+        assertEquals(2, nonpk.getId2());
+        NonPKJoinPC3 nonpk3 = partial3.getNonPK3();
+        assertEquals(3, nonpk3.getId1());
+        assertEquals(4, nonpk3.getId2());
+        pm.close();
+    }
+
+    public void testVerticalPartialOneOne() {
+        verticalPartialOneOne((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerVerticalPartialOneOne() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("partial3");
+        verticalPartialOneOne(pm);
+    }
+
+    private void verticalPartialOneOne(OpenJPAEntityManager pm) {
+        NonPKJoinPC3 nonpk3 = (NonPKJoinPC3) pm.getObjectId(_nonpk3);
+        PartialJoinPC partial = nonpk3.getPartial();
+        assertEquals(1, partial.getPk1());
+        assertEquals(2, partial.getPk2());
+        PartialJoinPC3 partial3 = nonpk3.getPartial3();
+        assertEquals(3, partial3.getPk1());
+        assertEquals(4, partial3.getPk2());
+        pm.close();
+    }
+
+    public void testNonPKManyMany() {
+        nonPKManyMany((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerNonPKManyMany() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("nonPKs");
+        nonPKManyMany(pm);
+    }
+
+    private void nonPKManyMany(OpenJPAEntityManager pm) {
+        PartialJoinPC partial = (PartialJoinPC) pm.getObjectId(_partial);
+        Collection nonpks = partial.getNonPKs();
+        assertEquals(1, nonpks.size());
+        NonPKJoinPC nonpk = (NonPKJoinPC) nonpks.iterator().next();
+        assertEquals(1, nonpk.getId1());
+        assertEquals(2, nonpk.getId2());
+        pm.close();
+    }
+
+    public void testPartialManyMany() {
+        partialManyMany((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerPartialManyMany() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("partials");
+        partialManyMany(pm);
+    }
+
+    private void partialManyMany(OpenJPAEntityManager pm) {
+        NonPKJoinPC nonpk = (NonPKJoinPC) pm.getObjectId(_nonpk);
+        Collection partials = nonpk.getPartials();
+        assertEquals(1, partials.size());
+        PartialJoinPC partial = (PartialJoinPC) partials.iterator().next();
+        assertEquals(1, partial.getPk1());
+        assertEquals(2, partial.getPk2());
+        pm.close();
+    }
+
+    public void testVerticalNonPKManyMany() {
+        verticalNonPKManyMany((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerVerticalNonPKManyMany() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("nonPK2s");
+        verticalNonPKManyMany(pm);
+    }
+
+    private void verticalNonPKManyMany(OpenJPAEntityManager pm) {
+        PartialJoinPC3 partial3 = (PartialJoinPC3) pm.getObjectId(_partial3);
+        Collection nonpks = partial3.getNonPKs();
+        assertEquals(1, nonpks.size());
+        NonPKJoinPC nonpk = (NonPKJoinPC) nonpks.iterator().next();
+        assertEquals(1, nonpk.getId1());
+        assertEquals(2, nonpk.getId2());
+        Collection nonpk2s = partial3.getNonPK2s();
+        assertEquals(1, nonpk2s.size());
+        NonPKJoinPC2 nonpk2 = (NonPKJoinPC2) nonpk2s.iterator().next();
+        assertEquals(2, nonpk2.getId1());
+        assertEquals(3, nonpk2.getId2());
+        pm.close();
+    }
+
+    public void testVerticalPartialManyMany() {
+        verticalPartialManyMany((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerVerticalPartialManyMany() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("partial2s");
+        verticalPartialManyMany(pm);
+    }
+
+    private void verticalPartialManyMany(OpenJPAEntityManager pm) {
+        NonPKJoinPC3 nonpk3 = (NonPKJoinPC3) pm.getObjectId(_nonpk3);
+        Collection partials = nonpk3.getPartials();
+        assertEquals(1, partials.size());
+        PartialJoinPC partial = (PartialJoinPC) partials.iterator().next();
+        assertEquals(1, partial.getPk1());
+        assertEquals(2, partial.getPk2());
+        Collection partial2s = nonpk3.getPartial2s();
+        assertEquals(1, partial2s.size());
+        PartialJoinPC2 partial2 = (PartialJoinPC2) partial2s.iterator().next();
+        assertEquals(2, partial2.getPk1());
+        assertEquals(3, partial2.getPk2());
+        pm.close();
+    }
+
+    public void testVerticalConstant() {
+        
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        ConstantJoinPC2 constant2 = (ConstantJoinPC2) pm.getObjectId(_constant2);
+        assertEquals(1, constant2.getPk1());
+        assertEquals(2, constant2.getPk2());
+        ConstantJoinPC3 constant3 = (ConstantJoinPC3) pm.getObjectId(_constant3);
+        assertEquals(1, constant3.getPk1());
+        assertEquals(3, constant3.getPk2());
+    }
+
+    public void testConstantOneOne() {
+        constantOneOne((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerConstantOneOne() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("nonPK");
+        constantOneOne(pm);
+    }
+
+    private void constantOneOne(OpenJPAEntityManager pm) {
+        ConstantJoinPC2 constant2 = (ConstantJoinPC2) pm.getObjectId(_constant2);
+
+        assertEquals(_nonpk3, pm.getObjectId(constant2.getNonPK()));
+        assertEquals(_nonpk3, pm.getObjectId(constant2.getNonPK2()));
+        pm.close();
+    }
+
+    public void testConstantOneMany() {
+        constantOneMany((OpenJPAEntityManager)currentEntityManager());
+    }
+
+    public void testEagerConstantOneMany() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("nonPKs");
+        constantOneMany(pm);
+    }
+
+    private void constantOneMany(OpenJPAEntityManager pm) {
+        ConstantJoinPC2 constant2 = (ConstantJoinPC2) pm.getObjectId(_constant2);
+
+        Collection nonpks = constant2.getNonPKs();
+        assertEquals(1, nonpks.size());
+        assertEquals(_nonpk, pm.getObjectId
+            (nonpks.iterator().next()));
+        pm.close();
+    }
+    
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJDBCType.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJDBCType.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJDBCType.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJDBCType.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,119 @@
+/*
+ * TestJDBCType.java
+ *
+ * Created on October 3, 2006, 4:11 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.MappingRepository;
+import org.apache.openjpa.jdbc.meta.RefreshStrategyInstaller;
+import org.apache.openjpa.jdbc.meta.strats.BlobValueHandler;
+import org.apache.openjpa.jdbc.meta.strats.ClobValueHandler;
+import org.apache.openjpa.jdbc.meta.strats.MaxEmbeddedClobFieldStrategy;
+import org.apache.openjpa.jdbc.meta.strats.StringFieldStrategy;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.SchemaGroup;
+import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
+import org.apache.openjpa.jdbc.schema.Column;
+
+public class TestJDBCType extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{
+	
+    /** Creates a new instance of TestJDBCType */
+    public TestJDBCType(String name) 
+    {
+    	super(name);
+    }
+    /**
+     * Tests that application identity classes are returned correctly.
+     */
+    public void testSchemaGeneration() {
+        JDBCConfiguration conf = new JDBCConfigurationImpl();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        MappingRepository repos = conf.getMappingRepositoryInstance();
+        repos.setStrategyInstaller(new RefreshStrategyInstaller(repos));
+        ClassMapping mapping = repos.getMapping(Column.class, null, true);
+
+        Class cls;
+        if (dict.getPreferredType(JavaSQLTypes.CLOB) ==  JavaSQLTypes.CLOB) {
+            if (dict.maxEmbeddedClobSize > 0) {
+                cls = mapping.getFieldMapping("toClob").getStrategy().
+                    getClass();
+                assertTrue(cls.getName(),
+                    MaxEmbeddedClobFieldStrategy.class.isAssignableFrom(cls));
+            } else {
+                cls = mapping.getFieldMapping("toClob").getHandler().
+                    getClass();
+                assertTrue(cls.getName(),
+                    ClobValueHandler.class.isAssignableFrom(cls));
+            }
+        } else
+            assertTrue(mapping.getFieldMapping("toClob").getStrategy()
+                instanceof StringFieldStrategy);
+
+        cls = mapping.getFieldMapping("toBlob").getHandler().getClass();
+        assertTrue(cls.getName(),
+            BlobValueHandler.class.isAssignableFrom(cls));
+
+        SchemaGroup schema = repos.getSchemaGroup();
+        Table table = schema.getSchemas()[0].getTables()[0];
+        Column[] cols = table.getColumns();
+        for (int i = 0; i < cols.length; i++) {
+            if (cols[i].getName().equalsIgnoreCase("id")
+                || cols[i].getName().equalsIgnoreCase("versn")
+                || cols[i].getName().equalsIgnoreCase("typ"))
+                continue;
+            if ("longToInt".equalsIgnoreCase(cols[i].getName()))
+                assertEquals(dict.getPreferredType(JavaSQLTypes.INT),
+                    cols[i].getType());
+            else if ("longToSQL".equalsIgnoreCase(cols[i].getName()))
+                assertEquals("varchar", cols[i].getTypeName());
+            else if ("toClob".equalsIgnoreCase(cols[i].getName()))
+                assertEquals(dict.getPreferredType(JavaSQLTypes.CLOB),
+                    cols[i].getType());
+            else if ("toBlob".equalsIgnoreCase(cols[i].getName()))
+                assertEquals(dict.getPreferredType(JavaSQLTypes.BLOB),
+                    cols[i].getType());
+            else
+                fail("Unknown column:" + cols[i].getName());
+        }
+    }    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJoinToBaseClass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJoinToBaseClass.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJoinToBaseClass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestJoinToBaseClass.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,118 @@
+/*
+ * TestJoinToBaseClass.java
+ *
+ * Created on October 3, 2006, 4: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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ForeignKey;
+import org.apache.openjpa.jdbc.schema.Table;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestJoinToBaseClass extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+    
+    
+    
+    /** Creates a new instance of TestJoinToBaseClass */
+    public TestJoinToBaseClass(String name) 
+    {
+    	super(name);
+    }
+    
+    public void testMapping() {
+        ClassMapping mapping = ((JDBCConfiguration) getConfiguration()).
+            getMappingRepositoryInstance().
+            getMapping(MappingTest5.class, null, true);
+
+        Table supTable = mapping.getPCSuperclassMapping().getTable();
+        assertTrue(mapping.getTable() != supTable);
+        FieldMapping field = mapping.getFieldMapping("vertRel");
+        ForeignKey fk = field.getForeignKey();
+        assertEquals(mapping.getTable(), fk.getTable());
+        assertEquals(supTable, fk.getPrimaryKeyTable());
+        Column[] cols = field.getColumns();
+        assertEquals(2, cols.length);
+        assertEquals("V1", cols[0].getName());
+        assertEquals("V2", cols[1].getName());
+    }
+
+    public void testConstraintAnalysis() {
+        //FIXME jthomas
+        //PersistenceManagerFactory factory = getPMFactory(new String[]{
+          //  "openjpa.jdbc.SchemaFactory", "native(ForeignKeys=true)",
+        //});
+        OpenJPAEntityManagerFactory factory=null;
+        OpenJPAEntityManager pm = factory.createEntityManager();
+        startTx(pm);
+        
+       deleteAll( MappingTest1.class,pm);
+       deleteAll( MappingTest2.class,pm);
+        endTx(pm);
+        pm.close();
+
+        pm = factory.createEntityManager();
+        startTx(pm);
+        for (int i = 0; i < 10; i++) {
+            MappingTest5 pc1 = new MappingTest5();
+            pc1.setPk1(i);
+            pc1.setPk2(i + 1);
+            MappingTest5 pc2 = new MappingTest5();
+            pc2.setPk1(i + 10);
+            pc2.setPk2(i + 11);
+            pc1.setVertRel(pc2);
+            pc2.setVertRel(pc1);
+            pm.persist(pc1);
+        }
+        endTx(pm);
+        pm.close();
+
+        assertSizes(20, MappingTest5.class);
+
+        pm = factory.createEntityManager();
+        startTx(pm);
+        deleteAll(MappingTest2.class,pm);
+        endTx(pm);
+        pm.close();
+    }
+
+    private void assertSizes(int size, Class cls) {
+        assertSize(size, currentEntityManager().createExtent(cls, true).list());
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestLRSProxies.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestLRSProxies.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestLRSProxies.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestLRSProxies.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,601 @@
+/*
+ * TestLRSProxies.java
+ *
+ * Created on October 3, 2006, 5:01 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.lib.jdbc.JDBCEvent;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestLRSProxies extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+   
+    private Object _oid = null;
+    private Object _coid = null;
+    
+    public TestLRSProxies(String casename) {
+        super(casename);
+    }
+    
+    
+    /** Creates a new instance of TestLRSProxies */
+    public TestLRSProxies() {
+    }
+    public void setUp() {
+       deleteAll(LRSPC.class);
+       deleteAll(LRSCompoundPC.class);
+        
+        LRSPC pc = new LRSPC("main");
+        
+        pc.getStringSet().add("val1");
+        pc.getStringSet().add("val2");
+        pc.getStringSet().add("val3");
+        
+        pc.getRelSet().add(new LRSPC("set1"));
+        pc.getRelSet().add(new LRSPC("set2"));
+        pc.getRelSet().add(new LRSPC("set3"));
+        
+        pc.getStringCollection().add("val1");
+        pc.getStringCollection().add("val2");
+        pc.getStringCollection().add("val3");
+        
+        pc.getRelCollection().add(new LRSPC("set1"));
+        pc.getRelCollection().add(new LRSPC("set2"));
+        pc.getRelCollection().add(new LRSPC("set3"));
+        
+        pc.getStringMap().put("key1", "1");
+        pc.getStringMap().put("key2", "2");
+        pc.getStringMap().put("key3", "3");
+        
+        pc.getRelMap().put("key1", new LRSPC("map1"));
+        pc.getRelMap().put("key2", new LRSPC("map2"));
+        pc.getRelMap().put("key3", new LRSPC("map3"));
+        
+        LRSCompoundPC cpc = new LRSCompoundPC("main");
+        
+        cpc.getStringSet().add("val1");
+        cpc.getStringSet().add("val2");
+        cpc.getStringSet().add("val3");
+        
+        cpc.getRelSet().add(new LRSCompoundPC("set1"));
+        cpc.getRelSet().add(new LRSCompoundPC("set2"));
+        cpc.getRelSet().add(new LRSCompoundPC("set3"));
+        
+        cpc.getStringCollection().add("val1");
+        cpc.getStringCollection().add("val2");
+        cpc.getStringCollection().add("val3");
+        
+        cpc.getRelCollection().add(new LRSCompoundPC("set1"));
+        cpc.getRelCollection().add(new LRSCompoundPC("set2"));
+        cpc.getRelCollection().add(new LRSCompoundPC("set3"));
+        
+        cpc.getStringMap().put("key1", "1");
+        cpc.getStringMap().put("key2", "2");
+        cpc.getStringMap().put("key3", "3");
+        
+        cpc.getRelMap().put("key1", new LRSCompoundPC("map1"));
+        cpc.getRelMap().put("key2", new LRSCompoundPC("map2"));
+        cpc.getRelMap().put("key3", new LRSCompoundPC("map3"));
+        
+        
+        
+        OpenJPAEntityManager pm = getEm(false, false);
+        
+        startTx(pm);
+        pm.persist(pc);
+        pm.persist(cpc);
+        endTx(pm);
+        _oid = pm.getObjectId(pc);
+        _coid = pm.getObjectId(cpc);
+        pm.close();
+    }
+    
+    public void testStringSet() {
+        stringCollectionTest(_oid, true, true);
+        stringCollectionTest(_coid, true, true);
+    }
+    
+    public void testStringSetRetain() {
+        stringCollectionTest(_oid, false, true);
+        stringCollectionTest(_coid, false, true);
+    }
+    
+    public void testStringCollection() {
+        stringCollectionTest(_oid, true, false);
+        stringCollectionTest(_coid, true, false);
+    }
+    
+    public void testStringCollectionRetain() {
+        stringCollectionTest(_oid, false, false);
+        stringCollectionTest(_coid, false, false);
+    }
+    
+    private void stringCollectionTest(Object oid, boolean close,
+            boolean isSet) {
+        //FIXME jthomas
+        //PersistenceManager pm = getPM(!close, !close);
+        OpenJPAEntityManager pm =null;
+        startTx(pm);
+        
+        LRSPCIntf pc = (LRSPCIntf) pm.getObjectId(oid);
+        
+        // check that orig values are correct
+        Collection set = isSet ? pc.getStringSet() : pc.getStringCollection();
+        assertEquals(3, set.size());
+        assertTrue(set.contains("val1"));
+        assertTrue(set.contains("val2"));
+        assertTrue(set.contains("val3"));
+        if (!isSet) {
+            Iterator itr = set.iterator();
+            assertEquals("val1", itr.next());
+            assertEquals("val2", itr.next());
+            assertEquals("val3", itr.next());
+            //FIXME jthomas
+            //KodoJDOHelper.close(itr);
+        }
+        
+        // do some mods to try to confuse the proxy
+        set.remove("val1");
+        set.remove("val1");
+        set.add("val4");
+        set.remove("val4");
+        set.add("val5");
+        set.add("val6");
+        assertStringCollectionChanged(set, isSet);
+        endTx(pm);
+        if (close) {
+            pm.close();
+            pm = getEm(false, false);
+        }
+        
+        // re-retrieve and check set
+        pc = (LRSPCIntf) pm.getObjectId(oid);
+        set = isSet ? pc.getStringSet() : pc.getStringCollection();
+        assertStringCollectionChanged(set, isSet);
+        pm.close();
+    }
+    
+    private void assertStringCollectionChanged(Collection set, boolean isSet) {
+        assertEquals(4, set.size());
+        assertTrue(!set.contains("val1"));
+        assertTrue(set.contains("val2"));
+        assertTrue(set.contains("val3"));
+        assertTrue(!set.contains("val4"));
+        assertTrue(set.contains("val5"));
+        assertTrue(set.contains("val6"));
+        if (!isSet) {
+            Iterator itr = set.iterator();
+            assertEquals("val2", itr.next());
+            assertEquals("val3", itr.next());
+            assertEquals("val5", itr.next());
+            assertEquals("val6", itr.next());
+            assertTrue(!itr.hasNext());
+            //FIXME jthomas
+            //KodoJDOHelper.close(itr);
+        }
+    }
+    
+    public void testStringMap() {
+        stringMapTest(_oid, true);
+        stringMapTest(_coid, true);
+    }
+    
+    public void testStringMapRetain() {
+        stringMapTest(_oid, false);
+        stringMapTest(_coid, false);
+    }
+    
+    private void stringMapTest(Object oid, boolean close) {
+        OpenJPAEntityManager pm = getEm(!close, !close);
+        startTx(pm);
+        LRSPCIntf pc = (LRSPCIntf) pm.getObjectId(oid);
+        
+        // check that orig values are correct
+        Map map = pc.getStringMap();
+        assertEquals(3, map.size());
+        assertEquals("1", map.get("key1"));
+        assertEquals("2", map.get("key2"));
+        assertEquals("3", map.get("key3"));
+        
+        // do some mods to try to confuse the proxy
+        map.put("key1", "1a");
+        map.put("key1", "1b");
+        map.put("key2", "4");
+        map.remove("key2");
+        map.remove("foo");
+        map.put("key5", "5");
+        assertStringMapChanged(map);
+        endTx(pm);
+        
+        if (close) {
+            pm.close();
+            pm = getEm(false, false);
+        }
+        
+        // re-retrieve and check map
+        pc = (LRSPCIntf) pm.getObjectId(oid);
+        map = pc.getStringMap();
+        assertStringMapChanged(map);
+        pm.close();
+    }
+    
+    private void assertStringMapChanged(Map map) {
+        assertEquals(3, map.size());
+        assertEquals("1b", map.get("key1"));
+        assertEquals("3", map.get("key3"));
+        assertEquals("5", map.get("key5"));
+        assertNull(map.get("key2"));
+        assertTrue(map.containsKey("key1"));
+        assertFalse(map.containsKey("key2"));
+        assertTrue(map.containsValue("5"));
+        assertFalse(map.containsValue("1"));
+        
+        Iterator itr = map.entrySet().iterator();
+        Map.Entry entry;
+        int count = 0;
+        for (; itr.hasNext(); count++) {
+            entry = (Map.Entry) itr.next();
+            if (entry.getKey().equals("key1"))
+                assertEquals("1b", entry.getValue());
+            else if (entry.getKey().equals("key3"))
+                assertEquals("3", entry.getValue());
+            else if (entry.getKey().equals("key5"))
+                assertEquals("5", entry.getValue());
+            else
+                fail("Bad key: " + entry.getKey());
+        }
+        assertEquals(3, count);
+        //FIXME
+        //KodoJDOHelper.close(itr);
+    }
+    
+    public void testRelSet() {
+        relCollectionTest(_oid, true, true);
+        relCollectionTest(_coid, true, true);
+    }
+    
+    public void testRelSetRetain() {
+        relCollectionTest(_oid, false, true);
+        relCollectionTest(_coid, false, true);
+    }
+    
+    public void testRelCollection() {
+        relCollectionTest(_oid, true, false);
+        relCollectionTest(_coid, true, false);
+    }
+    
+    public void testRelCollectionRetain() {
+        relCollectionTest(_oid, false, false);
+        relCollectionTest(_coid, false, false);
+    }
+    
+    private void relCollectionTest(Object oid, boolean close, boolean isSet) {
+        OpenJPAEntityManager pm = getEm(!close, !close);
+        startTx(pm);
+        LRSPCIntf pc = (LRSPCIntf) pm.getObjectId(oid);
+        
+        // check that orig values are correct
+        Collection set = isSet ? pc.getRelSet() : pc.getRelCollection();
+        assertEquals(3, set.size());
+        Collection ordered = new TreeSet();
+        Iterator itr = set.iterator();
+        ordered.add(itr.next());
+        ordered.add(itr.next());
+        ordered.add(itr.next());
+        assertTrue(!itr.hasNext());
+        //FIXME
+        //KodoJDOHelper.close(itr);
+        itr = ordered.iterator();
+        LRSPCIntf set1 = (LRSPCIntf) itr.next();
+        if (!isSet) {
+            LRSPCIntf set2 = (LRSPCIntf) itr.next();
+            LRSPCIntf set3 = (LRSPCIntf) itr.next();
+            assertEquals("set1", set1.getStringField());
+            assertEquals("set2", set2.getStringField());
+            assertEquals("set3", set3.getStringField());
+        }
+        assertTrue(set.contains(set1));
+        assertFalse(set.contains(pc));
+        
+        // do some mods to try to confuse the proxy
+        set.remove(set1);
+        set.remove(set1);
+        LRSPCIntf set4 = pc.newInstance("set4");
+        set.add(set4);
+        set.remove(set4);
+        LRSPCIntf set5 = pc.newInstance("set5");
+        set.add(set5);
+        assertRelCollectionChanged(pc, isSet);
+        endTx(pm);
+        
+        if (close) {
+            pm.close();
+            pm = getEm(false, false);
+        }
+        
+        // re-retrieve and check set
+        pc = (LRSPCIntf) pm.getObjectId(oid);
+        assertRelCollectionChanged(pc, isSet);
+        pm.close();
+    }
+    
+    private void assertRelCollectionChanged(LRSPCIntf pc, boolean isSet) {
+        Collection set = isSet ? pc.getRelSet() : pc.getRelCollection();
+        assertEquals(3, set.size());
+        Collection ordered = new TreeSet();
+        Iterator itr = set.iterator();
+        ordered.add(itr.next());
+        ordered.add(itr.next());
+        ordered.add(itr.next());
+        assertTrue(!itr.hasNext());
+        //FIXME
+        //KodoJDOHelper.close(itr);
+        itr = ordered.iterator();
+        LRSPCIntf set2 = (LRSPCIntf) itr.next();
+        if (!isSet) {
+            LRSPCIntf set3 = (LRSPCIntf) itr.next();
+            LRSPCIntf set5 = (LRSPCIntf) itr.next();
+            assertEquals("set2", set2.getStringField());
+            assertEquals("set3", set3.getStringField());
+            assertEquals("set5", set5.getStringField());
+        }
+        assertTrue(set.contains(set2));
+        assertFalse(set.contains(pc));
+    }
+    
+    public void testRelMap() {
+        relMapTest(_oid, true);
+        relMapTest(_coid, true);
+    }
+    
+    public void testRelMapRetain() {
+        relMapTest(_oid, false);
+        relMapTest(_coid, false);
+    }
+    
+    private void relMapTest(Object oid, boolean close) {
+        OpenJPAEntityManager pm = getEm(!close, !close);
+        startTx(pm);
+        LRSPCIntf pc = (LRSPCIntf) pm.getObjectId(oid);
+        
+        // check that orig values are correct
+        Map map = pc.getRelMap();
+        assertEquals(3, map.size());
+        LRSPCIntf map1 = (LRSPCIntf) map.get("key1");
+        LRSPCIntf map2 = (LRSPCIntf) map.get("key2");
+        LRSPCIntf map3 = (LRSPCIntf) map.get("key3");
+        assertEquals("map1", map1.getStringField());
+        assertEquals("map2", map2.getStringField());
+        assertEquals("map3", map3.getStringField());
+        assertTrue(map.containsKey("key1"));
+        assertFalse(map.containsKey("key4"));
+        assertTrue(map.containsValue(map1));
+        assertFalse(map.containsValue(pc));
+        
+        // do some mods to try to confuse the proxy
+        LRSPCIntf map1a = pc.newInstance("map1a");
+        map.put("key1", map1a);
+        LRSPCIntf map1b = pc.newInstance("map1b");
+        map.put("key1", map1b);
+        map.remove("key2");
+        map.put("key4", pc.newInstance("map4"));
+        map.remove("key4");
+        map.remove("foo");
+        map.put("key5", pc.newInstance("map5"));
+        assertRelMapChanged(pc);
+        endTx(pm);
+        
+        if (close) {
+            pm.close();
+            pm = getEm(false, false);
+        }
+        
+        // re-retrieve and check map
+        pc = (LRSPCIntf) pm.getObjectId(oid);
+        assertRelMapChanged(pc);
+        pm.close();
+    }
+    
+    private void assertRelMapChanged(LRSPCIntf pc) {
+        Map map = pc.getRelMap();
+        assertEquals(3, map.size());
+        LRSPCIntf map1b = (LRSPCIntf) map.get("key1");
+        LRSPCIntf map3 = (LRSPCIntf) map.get("key3");
+        LRSPCIntf map5 = (LRSPCIntf) map.get("key5");
+        assertEquals("map1b", map1b.getStringField());
+        assertEquals("map3", map3.getStringField());
+        assertEquals("map5", map5.getStringField());
+        assertTrue(map.containsKey("key1"));
+        assertFalse(map.containsKey("key2"));
+        assertTrue(map.containsValue(map1b));
+        assertFalse(map.containsValue(pc));
+        
+        Iterator itr = map.entrySet().iterator();
+        Map.Entry entry;
+        int count = 0;
+        for (; itr.hasNext(); count++) {
+            entry = (Map.Entry) itr.next();
+            if (entry.getKey().equals("key1"))
+                assertEquals(map1b, entry.getValue());
+            else if (entry.getKey().equals("key3"))
+                assertEquals(map3, entry.getValue());
+            else if (entry.getKey().equals("key5"))
+                assertEquals(map5, entry.getValue());
+            else
+                fail("Bad key: " + entry.getKey());
+        }
+        assertEquals(3, count);
+        //FIXME
+        //KodoJDOHelper.close(itr);
+    }
+    
+    public void testTransfer() {
+        // cannot transfer an lrs from one field to another
+        
+        OpenJPAEntityManager pm = getEm(true, true);
+        LRSPC pc = (LRSPC) pm.getObjectId(_oid);
+        LRSPC map1 = (LRSPC) pc.getRelMap().get("key1");
+        assertNotNull(map1);
+        
+        startTx(pm);
+        Map map = pc.getRelMap();
+        pc.setRelMap(null);
+        map1.setRelMap(map);
+        
+        try {
+            endTx(pm);
+            fail("Allowed transfer of lrs field");
+        } catch (Exception jue) {
+        }
+        if (pm.getTransaction().isActive())
+            pm.getTransaction().rollback();
+        pm.close();
+    }
+    
+    public void testShare() {
+        OpenJPAEntityManager pm = getEm(true, true);
+        LRSPC pc = (LRSPC) pm.getObjectId(_oid);
+        LRSPC map1 = (LRSPC) pc.getRelMap().get("key1");
+        assertNotNull(map1);
+        
+        startTx(pm);
+        Map map = pc.getRelMap();
+        map1.setRelMap(map);
+        endTx(pm);
+        assertTrue(pc.getRelMap() != map1.getRelMap());
+        assertEquals(3, map1.getRelMap().size());
+        assertTrue(map1.getRelMap().containsValue(map1));
+        pm.close();
+        
+        // make sure it sticks
+        pm = getEm(true, true);
+        pc = (LRSPC) pm.getObjectId(_oid);
+        map1 = (LRSPC) pc.getRelMap().get("key1");
+        assertEquals(map1, map1.getRelMap().get("key1"));
+        pm.close();
+    }
+    
+    public void testRollback() {
+        //FIXME
+        //PersistenceManagerFactory factory = getPMFactory(new String[]{
+        //    "openjpa.RestoreMutableValues", "true",
+        //});
+        OpenJPAEntityManagerFactory factory =null;
+        OpenJPAEntityManager pm = factory.createEntityManager();
+        LRSPC pc = (LRSPC) pm.getObjectId(_oid);
+        startTx(pm);
+        pc.getStringCollection().remove("val2");
+        pc.getStringCollection().add("val4");
+        rollbackTx(pm);
+        assertTrue(pc.getStringCollection().contains("val2"));
+        assertFalse(pc.getStringCollection().contains("val4"));
+        pm.close();
+        factory.close();
+    }
+    
+    public void testReplace() {
+        OpenJPAEntityManager pm = getEm(false, false);
+        startTx(pm);
+        LRSPC pc = (LRSPC) pm.getObjectId(_oid);
+        
+        // totally replace set
+        Collection set = new HashSet();
+        set.add("new");
+        pc.setStringCollection(set);
+        
+        endTx(pm);
+        pm.close();
+        
+        // re-retrieve and check set
+        pm = getEm(false, false);
+        pc = (LRSPC) pm.getObjectId(_oid);
+        
+        set = pc.getStringCollection();
+        assertEquals(1, set.size());
+        assertTrue(set.contains("new"));
+        pm.close();
+    }
+    
+    public void testAdd()
+    throws Exception {
+/*
+        //FIXME
+        //KodoPersistenceManagerFactory pmf = getPMFactory(new String []{
+        //    "openjpa.jdbc.JDBCListeners", Listener.class.getName(),
+        //});
+        OpenJPAEntityManagerFactory pmf =null;
+        JDBCConfiguration conf = (JDBCConfiguration) pmf.getConfiguration();
+        //FIXME need to fix inner class
+        //Listener l = (Listener) conf.getJDBCListenerInstances()[0];
+        OpenJPAEntityManager pm = pmf.createEntityManager();
+        try {
+            startTx(pm);
+            LRSPC pc = (LRSPC) pm.getObjectId(_oid);
+            l.count = 0;
+            pc.getStringCollection().add("testAddStringValue");
+            endTx(pm);
+            assertEquals(3, l.count);
+        } catch (Exception e) {
+            if (pm.getTransaction().isActive())
+                pm.getTransaction().rollback();
+            throw e;
+        } finally {
+            pm.close();
+        }
+ */
+    }
+    
+    private OpenJPAEntityManager getEm(boolean optimistic,boolean retainValues) {
+        OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
+        em.setNontransactionalRead(true);
+        em.setRetainState(retainValues);
+        em.setOptimistic(optimistic);
+        return em;
+    }
+    
+    //FIXME - could not find AbstractJDBCListener because of package imports in source file
+/*
+    public static class Listener extends AbstractJDBCListener {
+ 
+        public int count = 0;
+ 
+        public void afterExecuteStatement(JDBCEvent ev) {
+            count++;
+        }
+    }
+ */
+}



Mime
View raw message