openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [18/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/kernel/TestEJBAutoIncrement.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEJBAutoIncrement.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEJBAutoIncrement.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEJBAutoIncrement.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,238 @@
+/*
+ * 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.kernel;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.AutoIncrementPC1;
+import org.apache.openjpa.persistence.jdbc.common.apps.AutoIncrementPC2;
+import org.apache.openjpa.persistence.jdbc.common.apps.AutoIncrementPC3;
+import org.apache.openjpa.persistence.jdbc.common.apps.AutoIncrementPC3Id;
+
+import junit.framework.*;
+
+public class TestEJBAutoIncrement extends BaseJDBCTest
+{
+
+//	private boolean  = Boolean.valueOf(bool);
+
+	private int oid2;
+	private long oid3;
+	private long oid4, oid2a, oid2b, oid3b;
+	private long oid3a;
+
+	public TestEJBAutoIncrement(String name)
+	{
+		super(name);
+	}
+
+	public void setUp()
+	{
+		deleteAll(AutoIncrementPC1.class);
+		deleteAll(AutoIncrementPC2.class);
+		deleteAll(AutoIncrementPC3.class);
+	}
+
+	@SuppressWarnings("unchecked")
+	public void testInsert ()
+	{
+		AutoIncrementPC2 pc1 = new AutoIncrementPC2 (1);
+		pc1.setStringField ("pc1");
+		pc1.setIntField (1);
+		pc1.getSetField ().add ("string1");
+		pc1.getSetField ().add ("string2");
+
+		AutoIncrementPC2 pc2 = new AutoIncrementPC2 (2);
+		pc2.setStringField ("pc2");
+		pc2.setIntField (2);
+		pc2.getSetField ().add ("string3");
+		pc2.getSetField ().add ("string4");
+
+		AutoIncrementPC3 pc3 = new AutoIncrementPC3 (3);
+		pc3.setStringField ("pc3");
+		pc3.getSetField ().add ("string5");
+		pc3.getSetField ().add ("string6");
+
+		AutoIncrementPC3 pc4 = new AutoIncrementPC3 (4);
+		pc4.setStringField ("pc4");
+		pc4.getSetField ().add ("string7");
+		pc4.getSetField ().add ("string8");
+
+		EntityManager em = currentEntityManager();
+		startTx(em);
+		em.persist(pc1);
+		em.persist(pc2);
+		em.persist(pc3);
+		em.persist(pc4);
+		oid2 = pc2.getId();
+		oid4 = pc4.getId();
+
+		assertEquals (pc2, em.find(AutoIncrementPC2.class, oid2));
+		assertEquals (pc4, em.find(AutoIncrementPC3.class, oid4));
+		endTx(em);
+		endEm(em);
+
+		em = currentEntityManager();
+		startTx(em);
+		pc2 = em.find(AutoIncrementPC2.class, 2);
+		pc4 = em.find(AutoIncrementPC3.class, 4);
+		assertEquals ("pc2", pc2.getStringField ());
+		assertEquals (2, pc2.getIntField ());
+		assertEquals ("pc4", pc4.getStringField ());
+		endTx(em);
+		endEm(em);
+	}
+
+	public void testUpdate ()
+	{
+		AutoIncrementPC2 pc2 = new AutoIncrementPC2 (1);
+		pc2.setStringField ("pc2");
+		pc2.setIntField (2);
+		AutoIncrementPC3 pc3 = new AutoIncrementPC3 (2);
+		pc3.setStringField ("pc3");
+
+		EntityManager em = currentEntityManager();
+		startTx(em);
+		em.persist (pc2);
+		em.persist (pc3);
+		endTx(em);
+
+		oid2 = pc2.getId();
+		oid3 = pc3.getId();
+		endEm(em);
+
+		em = currentEntityManager();
+		startTx(em);
+		pc2 = em.find(AutoIncrementPC2.class, oid2);
+		pc3 = em.find(AutoIncrementPC3.class, oid3);
+		assertEquals ("pc2", pc2.getStringField ());
+		assertEquals (2, pc2.getIntField ());
+		assertEquals ("pc3", pc3.getStringField ());
+		pc2.setStringField ("pc2a");
+		pc2.setIntField (3);
+		pc3.setStringField ("pc3a");
+		endTx(em);
+		endEm(em);
+
+		em = currentEntityManager();
+		startTx(em);
+		pc2 = em.find(AutoIncrementPC2.class, oid2);
+		pc3 = em.find(AutoIncrementPC3.class, oid3);
+		assertEquals ("pc2a", pc2.getStringField ());
+		assertEquals (3, pc2.getIntField ());
+		assertEquals ("pc3a", pc3.getStringField ());
+		endTx(em);
+		endEm(em);
+	}
+
+	public void testCircularReferences ()
+	{
+		AutoIncrementPC2 pc2a = new AutoIncrementPC2 (1);
+		pc2a.setStringField ("pc2a");
+		pc2a.setIntField (1);
+		AutoIncrementPC2 pc2b = new AutoIncrementPC2 (2);
+		pc2b.setStringField ("pc2b");
+		pc2b.setIntField (2);
+		AutoIncrementPC3 pc3 = new AutoIncrementPC3 (3);
+		pc3.setStringField ("pc3");
+
+		pc2a.setOneOne (pc2b);
+		pc2b.setOneOne (pc2a);
+		pc3.setOneOne (pc3);
+
+		EntityManager em = currentEntityManager();
+		startTx(em);
+		em.persist (pc2a);
+		em.persist (pc2b);
+		em.persist (pc3);
+		endTx(em);
+		oid2a = pc2a.getId();
+		oid2b = pc2b.getId();
+	    oid3 = pc3.getId();
+		endEm(em);
+
+		em = currentEntityManager();
+		startTx(em);
+		pc2a = em.find(AutoIncrementPC2.class, oid2a);
+		pc2b = em.find(AutoIncrementPC2.class, oid2b);
+		pc3 = em.find(AutoIncrementPC3.class, oid3);
+		assertEquals ("pc2a", pc2a.getStringField ());
+		assertEquals (1, pc2a.getIntField ());
+		assertEquals ("pc2b", pc2b.getStringField ());
+		assertEquals (2, pc2b.getIntField ());
+		assertEquals ("pc3", pc3.getStringField ());
+		assertEquals (pc2b, pc2a.getOneOne ());
+		assertEquals (pc2a, pc2b.getOneOne ());
+		assertEquals (pc3, pc3.getOneOne ());
+		endTx(em);
+		endEm(em);
+	}
+
+	public void testMultipleFlushes ()
+	{
+		AutoIncrementPC2 pc2 = new AutoIncrementPC2 (1);
+		pc2.setStringField ("pc2");
+		pc2.setIntField (2);
+		AutoIncrementPC3 pc3 = new AutoIncrementPC3 (2);
+		pc3.setStringField ("pc3");
+
+		EntityManager em = currentEntityManager();
+		startTx(em);
+		em.persist (pc2);
+		em.persist (pc3);
+		oid2 = pc2.getId();
+		oid3 = pc3.getId();
+		em.flush ();
+
+	    oid2a = pc2.getId();
+		oid3a = pc3.getId();
+		assertEquals (oid2, oid2a);
+		assertEquals (oid3, oid3a);
+		long id = pc3.getId ();
+		assertEquals (pc2, em.find(AutoIncrementPC2.class, oid2a));
+		assertEquals (pc3, em.find(AutoIncrementPC3.class, oid3a));
+		pc2.setStringField ("pc2a");
+		pc2.setIntField (3);
+		pc3.setStringField ("pc3a");
+		em.flush ();
+
+		oid2b = pc2.getId();
+		oid3b = pc3.getId();
+		assertEquals (oid2, oid2b);
+		assertEquals (oid3, oid3b);
+		assertEquals (id, pc3.getId ());
+		assertEquals (pc2, em.find(AutoIncrementPC2.class, oid2b));
+		assertEquals (pc3, em.find(AutoIncrementPC3.class, oid3b));
+		endTx(em);
+		endEm(em);
+
+		em = currentEntityManager();
+		startTx(em);
+		pc2 = em.find(AutoIncrementPC2.class, oid2b);
+		pc3 = em.find(AutoIncrementPC3.class, oid3b);
+		assertEquals ("pc2a", pc2.getStringField ());
+		assertEquals (3, pc2.getIntField ());
+		assertEquals ("pc3a", pc3.getStringField ());
+		assertEquals (id, pc3.getId ());
+		endTx(em);
+		endEm(em);
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEfficientAttach.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEfficientAttach.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEfficientAttach.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEfficientAttach.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,121 @@
+/*
+ * TestEfficientAttach.java
+ *
+ * Created on September 29, 2006, 6:00 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.kernel;
+
+
+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.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.meta.MetaDataRepository;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.meta.ClassMetaData;
+
+public class TestEfficientAttach extends TestSQLListenerTestCase {
+
+
+//    private boolean  = true;//Boolean.valueOf(bool);
+    
+    /** Creates a new instance of TestEfficientAttach */
+    public TestEfficientAttach(String name) 
+    {
+    	super(name);
+    }
+    
+    public void testAttachWithDetachedStateManager() {
+        Class[] clss = new Class[]{
+            AttachA.class, AttachB.class, AttachC.class, AttachD.class,
+            AttachE.class, AttachF.class,
+        };
+        String[] detachedStateFields = new String[clss.length];
+
+        // null any declared detached state fields so we know we're using
+        // synthetic state managers
+        EntityManager em= currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
+        JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerSPI) kem).getConfiguration();
+
+        MetaDataRepository repos = conf.getMappingRepositoryInstance();
+        ClassMetaData meta;
+        for (int i = 0; i < clss.length; i++) {
+            meta = repos.getMetaData(clss[i], null, true);
+            detachedStateFields[i] = meta.getDetachedState();
+            meta.setDetachedState(null);
+
+           deleteAll(clss[i]);
+        }
+
+        try {
+            attachTest();
+        } finally {
+            // set detached state back
+            for (int i = 0; i < clss.length; i++)
+                repos.getMetaData(clss[i], null, true).setDetachedState
+                    (detachedStateFields[i]);
+        }
+    }
+
+    private void attachTest() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager) currentEntityManager();
+        startTx(pm);;
+        AttachE e = new AttachE();
+        e.setB(new AttachB());
+        pm.persist(e);
+        endTx(pm);;
+        //FIXME jthomas - could not find equivalent for detachCopy() attachCopy() etc
+/*      
+        e = (AttachE) pm.detachCopy(e);
+        pm.close();
+
+        pm = getPM();
+        pm.begin();
+        sql.clear();
+        e = (AttachE) pm.attachCopy(e, false);
+        assertNotNull(e);
+        assertNotNull(e.getB());
+        assertSize(0, sql);
+        pm.commit();
+        assertSize(2, sql);
+        pm.close();
+ */
+    }
+
+
+    public static void main(String[] args) {
+        //main();
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEmbeddedPessimisticLocking.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEmbeddedPessimisticLocking.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEmbeddedPessimisticLocking.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestEmbeddedPessimisticLocking.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,285 @@
+/*
+ * 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.kernel;
+
+
+import java.util.*;
+import org.apache.openjpa.kernel.*;
+import org.apache.openjpa.jdbc.conf.*;
+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.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase; 
+
+
+/**
+ * Test various bits of embedded-field functionality.
+ * <p/>
+ * ##### this should test embedded-element collections, maps, at least to ensure
+ * ##### that the state managers of values in embedded collections, maps do not
+ * ##### have owners. Not relevant in 3.x; will be important in 4.0.
+ */
+public class TestEmbeddedPessimisticLocking
+    extends TestSQLListenerTestCase {
+
+
+    private boolean supportsLocking;
+    private Object oid;
+    private OpenJPAEntityManagerFactory emf;
+    
+    public TestEmbeddedPessimisticLocking(String name)
+    {
+    	super(name);
+    }
+
+	public void setUp() throws Exception{
+		super.setUp();
+		emf = (OpenJPAEntityManagerFactory)getEmf(getProps());
+	}
+
+
+
+    public void setUpTestCase() {
+
+		JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf)).getConfiguration();
+
+        supportsLocking = conf.getDBDictionaryInstance().supportsSelectForUpdate;
+
+       deleteAll(EmbeddedOwnerPC.class);
+
+        OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
+        startTx(em);
+        EmbeddedOwnerPC owner = new EmbeddedOwnerPC(10, 20);
+        em.persist(owner);
+
+        EmbeddedPC embedded = new EmbeddedPC();
+        embedded.setIntField(4);
+        embedded.setStringField("foo");
+        owner.setEmbedded(embedded);
+
+        EmbeddedPC embedded2 = new EmbeddedPC();
+        embedded2.setIntField(8);
+        embedded2.setStringField("bar");
+        ComplexEmbeddedPC complex = new ComplexEmbeddedPC();
+        complex.setStringField("complex");
+        complex.setEmbedded(embedded2);
+        owner.setComplexEmbedded(complex);
+
+        endTx(em);
+
+        oid = em.getObjectId(owner);
+        em.close();
+    }
+
+    private void prepareEMF(OpenJPAEntityManagerFactory emf) {
+        // do this to ensure that the SELECT DISTINCT gets performed here.
+        OpenJPAEntityManager em = emf.createEntityManager();
+
+        //FIXME jthomas commenting this since setOptimistic is not available for userTx
+        //em.getTransaction().setOptimistic(false);
+        startTx(em);
+
+        try {
+            EmbeddedOwnerPC pc = (EmbeddedOwnerPC) em.getObjectId(oid);
+        } finally {
+            rollbackTx(em);
+            em.close();
+        }
+    }
+
+    public void testEmbeddedFieldsWithLockedParent() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
+        prepareEMF(em.getEntityManagerFactory());
+        ((FetchPlan) em.getFetchPlan()).addField(EmbeddedOwnerPC.class, "embedded");
+//FIXME jthomas commenting this since setOptimistic is not available for userTx
+//        pm.currentTransaction().setOptimistic(false);
+        startTx(em);
+        try {
+            sql.clear();
+            EmbeddedOwnerPC pc = (EmbeddedOwnerPC) em.getObjectId(oid);
+            assertEquals(1, sql.size());
+
+            pc.getEmbedded().setStringField
+                (pc.getEmbedded().getStringField() + "bar");
+            // should not go to the db for another lock; we use <=, since
+            // some databases (like HSQL) don't support locking at all
+            assertTrue(sql.size() <= 1);
+        } finally {
+            rollbackTx(em);
+            em.close();
+        }
+    }
+
+    public void testEmbeddedFieldsWithUnlockedParent() {
+		OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
+		prepareEMF(em.getEntityManagerFactory());
+		((FetchPlan) em.getFetchPlan()).addField(EmbeddedOwnerPC.class, "embedded");
+
+
+//FIXME jthomas commenting this since setOptimistic is not available for userTx
+//        pm.currentTransaction().setOptimistic(false);
+        startTx(em);
+
+        try {
+
+            //FIXME jthomas - no equivalent found for LockLevels.LOCK_NONE
+            //((FetchPlan) pm.getFetchPlan()).setReadLockMode(LockLevels.LOCK_NONE);
+
+            sql.clear();
+            EmbeddedOwnerPC pc = (EmbeddedOwnerPC) em.getObjectId(oid);
+            EmbeddedPC embedded = pc.getEmbedded();
+
+            assertNull(getStateManager(pc, em).getLock());
+            assertNull(getStateManager(embedded, em).getLock());
+            assertEquals(1, sql.size());
+            sql.clear();
+
+            embedded.setStringField(embedded.getStringField() + "bar");
+            // should not go to the db for another lock -- should have gotten
+            // one along with the embedded field's lock
+            assertTrue(sql.size() <= 1);
+            assertNotNull(getStateManager(pc, em).getLock());
+
+            // embeddeds don't get locks at all.
+            assertNull(getStateManager(embedded, em).getLock());
+
+            // owner is dirtied when embedded record is changed
+            assertTrue(getStateManager(pc, em).isDirty());
+            assertTrue(getStateManager(embedded, em).isDirty());
+
+            pc.setStringField(pc.getStringField() + "bar");
+            // should not go to the db for another lock.
+            assertTrue(sql.size() <= 1);
+        } finally {
+            rollbackTx(em);
+            em.close();
+        }
+    }
+
+    public void testComplexEmbeddedFieldsWithLockedParent() {
+
+		OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
+		prepareEMF(em.getEntityManagerFactory());
+		em.getFetchPlan().setMaxFetchDepth(-1);
+		((FetchPlan) em.getFetchPlan()).addField(EmbeddedOwnerPC.class, "complexEmbedded");
+		((FetchPlan) em.getFetchPlan()).addField(RecursivelyEmbeddedPC.class, "embedded");
+
+//FIXME jthomas commenting this since setOptimistic is not available for userTx
+//        pm.currentTransaction().setOptimistic(false);
+        startTx(em);
+        try {
+            sql.clear();
+            EmbeddedOwnerPC pc = (EmbeddedOwnerPC) em.getObjectId(oid);
+            assertEquals(1, sql.size());
+
+            pc.getComplexEmbedded().getEmbedded().setStringField
+                (pc.getComplexEmbedded().getEmbedded().getStringField() +
+                    "bar");
+            // should not go to the db for another lock.
+            assertTrue(sql.size() <= 1);
+        } finally {
+            rollbackTx(em);
+            em.close();
+        }
+    }
+
+    public void testComplexEmbeddedFieldsWithUnlockedParent() {
+        // doing this because setting the read lock level
+        // does not seem to be disabling FOR UPDATE.
+
+
+		OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
+		prepareEMF(em.getEntityManagerFactory());
+		em.getFetchPlan().setMaxFetchDepth(-1);
+		((FetchPlan) em.getFetchPlan()).addField(EmbeddedOwnerPC.class, "complexEmbedded");
+		((FetchPlan) em.getFetchPlan()).addField(RecursivelyEmbeddedPC.class, "embedded");
+
+
+
+//FIXME jthomas commenting this since setOptimistic is not available for userTx
+//        pm.currentTransaction().setOptimistic(false);
+        startTx(em);
+
+        try {
+            //FIXME jthomas FetchPlan.LOCK_NONE??
+            //((FetchPlan) em.getFetchPlan()).setReadLockLevel
+            //    (FetchPlan.LOCK_NONE);
+
+            sql.clear();
+            EmbeddedOwnerPC pc = (EmbeddedOwnerPC) em.getObjectId(oid);
+            ComplexEmbeddedPC complex = pc.getComplexEmbedded();
+            EmbeddedPC embedded = complex.getEmbedded();
+
+            assertNull(getStateManager(pc, em).getLock());
+            assertNull(getStateManager(complex, em).getLock());
+            assertNull(getStateManager(embedded, em).getLock());
+            assertEquals(1, sql.size());
+            sql.clear();
+
+            embedded.setStringField(embedded.getStringField() + "bar");
+            // should not go to the db for another lock -- should have gotten
+            // one along with the embedded field's lock
+            assertTrue(sql.size() <= 1);
+            assertNotNull(getStateManager(pc, em).getLock());
+
+            // embeddeds don't get locks at all.
+            assertNull(getStateManager(complex, em).getLock());
+            assertNull(getStateManager(embedded, em).getLock());
+
+            // owner is dirtied when embedded record is changed
+            assertTrue(getStateManager(pc, em).isDirty());
+            assertTrue(getStateManager(complex, em).isDirty());
+            assertTrue(getStateManager(embedded, em).isDirty());
+
+            complex.setStringField(complex.getStringField() + "bar");
+            // should not go to the db for another lock.
+            assertTrue(sql.size() <= 1);
+
+            pc.setStringField(pc.getStringField() + "bar");
+            // should not go to the db for another lock.
+            assertTrue(sql.size() <= 1);
+        } finally {
+            rollbackTx(em);
+            em.close();
+        }
+    }
+
+	private Map getProps() {
+		Map props=new HashMap();
+		props.put("openjpa.DataCache", "true");
+		props.put("openjpa.RemoteCommitProvider", "sjvm");
+		props.put("openjpa.FlushBeforeQueries", "true");
+		props.put("javax.jdo.option.IgnoreCache", "false");
+		//propsMap.put("openjpa.BrokerImpl", "kodo.datacache.CacheTestBroker");//CacheTestBroker.class.getName ());
+		return props;
+	}
+
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestIncrementalJDBCFlushes.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestIncrementalJDBCFlushes.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestIncrementalJDBCFlushes.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestIncrementalJDBCFlushes.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,112 @@
+/*
+ * 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.kernel;
+
+import java.sql.*;
+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 javax.persistence.Persistence;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.kernel.StoreManager;
+import org.apache.openjpa.kernel.DelegatingStoreManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+
+public class TestIncrementalJDBCFlushes
+        extends BaseJDBCTest {
+    
+    private EntityManagerFactory emf;
+    
+
+//    private boolean  = true;
+//    
+    
+    public TestIncrementalJDBCFlushes(String str) {
+        super(str);
+    }
+    
+    
+    public void setUp() {
+        emf = getEmf(getProps());
+        
+        EntityManager em =emf.createEntityManager();
+       deleteAll(RuntimeTest1.class,em);
+        
+    }
+    
+    
+    public void testFlushHappened() throws java.sql.SQLException{
+        
+        
+        
+        EntityManager em =emf.createEntityManager();
+        startTx(em);
+        RuntimeTest1 a = new RuntimeTest1("a-name", 10);
+        em.persist(a);
+        em.flush();
+        JDBCStore store = (JDBCStore) getStoreManager(em, true);
+        Connection conn = store.getConnection();
+        ClassMapping mapping = store.getConfiguration().
+                getMappingRepositoryInstance().getMapping(RuntimeTest1.class,
+                null, true);
+        FieldMapping fm = mapping.getFieldMapping("stringField");
+        String tableName = store.getConfiguration().getDBDictionaryInstance().getFullName(fm.getTable(), false);
+        String colName = fm.getColumns()[0].getName();
+        Statement st = conn.createStatement();
+        ResultSet rs = st.executeQuery("SELECT " + colName + " FROM "
+                + tableName + " WHERE " + colName + " = 'a-name'");
+        int count = 0;
+        while (rs.next())
+            count++;
+        assertEquals(1, count);
+        rollbackTx(em);
+        endEm(em);
+        
+        
+    }
+    
+    private StoreManager getStoreManager(EntityManager em, boolean innermost) {
+        DelegatingStoreManager mgr = JPAFacadeHelper.toBroker(em).getStoreManager();
+        if (innermost)
+            return mgr.getInnermostDelegate();
+        return mgr;
+    }
+    
+    private Map getProps() {
+        Map props=new HashMap();
+        props.put("openjpa.DataCache", "true");
+        props.put("openjpa.RemoteCommitProvider", "sjvm");
+        props.put("openjpa.FlushBeforeQueries", "true");
+        props.put("javax.jdo.option.IgnoreCache", "false");
+        //propsMap.put("openjpa.BrokerImpl", "kodo.datacache.CacheTestBroker");//CacheTestBroker.class.getName ());
+        return props;
+    }
+    
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestOperationOrderUpdateManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestOperationOrderUpdateManager.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestOperationOrderUpdateManager.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestOperationOrderUpdateManager.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,319 @@
+/*
+ * 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.kernel;
+
+
+
+import java.util.*;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+import org.apache.openjpa.persistence.common.utils.*;
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+
+
+public class TestOperationOrderUpdateManager
+    extends AbstractTestCase {
+
+
+//	private boolean  = true;//Boolean.valueOf(bool);
+
+
+    private static boolean _mapped = false;
+
+    private EntityManagerFactory emf;
+
+    /*protected boolean skipTest() {
+        if (!getName().startsWith("testAuto"))
+            return false;
+
+		emf = getEmf();
+
+		JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf)).getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        return !dict.supportsAutoAssign;
+    }
+*/
+    public TestOperationOrderUpdateManager(String name)
+    {
+    	super(name);
+    }
+
+    private void insertTest(boolean autoAssign) {
+        OpOrder oid = (autoAssign) ? insertAutoAssign() : insert();
+
+        EntityManager em = currentEntityManager();
+
+        OpOrder pc = (OpOrder) em.find(OpOrder.class,oid.getId());
+        assertEquals("pc", pc.getSecondary());
+        assertEquals("pcsub", pc.getSub());
+        assertNotNull(pc.getRel());
+        assertEquals("rel", pc.getRel().getSecondary());
+        assertEquals(2, pc.getRelList().size());
+        assertTrue(((OpOrder) pc.getRelList().iterator().next()).
+            getSecondary().startsWith("child"));
+        assertEquals(2, pc.getMappedRelList().size());
+        assertTrue(((OpOrder) pc.getMappedRelList().iterator().next()).
+            getSecondary().startsWith("mapped"));
+        assertEquals(2, pc.getInverseKeyRelList().size());
+        assertTrue(((OpOrder) pc.getInverseKeyRelList().iterator().
+            next()).getSecondary().startsWith("inverse"));
+        em.close();
+    }
+
+
+
+    private OpOrder insert() {
+        OpOrderPCSub pc = new OpOrderPCSub();
+        pc.setSecondary("pc");
+        pc.setSub("pcsub");
+        OpOrderPCSub rel = new OpOrderPCSub();
+        rel.setSecondary("rel");
+        pc.setRel(rel);
+        for (int i = 0; i < 2; i++) {
+            OpOrderPCSub child = new OpOrderPCSub();
+            child.setSecondary("child" + i);
+            pc.getRelList().add(child);
+
+            OpOrderPCSub mapped = new OpOrderPCSub();
+            mapped.setSecondary("mapped" + i);
+            mapped.setOwner(pc);
+            pc.getMappedRelList().add(mapped);
+
+            OpOrderPCSub inverse = new OpOrderPCSub();
+            inverse.setSecondary("inverse" + i);
+            pc.getInverseKeyRelList().add(inverse);
+        }
+
+        EntityManager em = currentEntityManager();
+		startTx(em);
+        em.persist(rel);
+        persistAll(em,pc.getInverseKeyRelList());
+        em.persist(pc);
+        endTx(em);
+        OpOrder oid = em.find(OpOrder.class,pc.getId());
+        //em.getObjectId(pc);
+        em.close();
+        return oid;
+    }
+
+    private OpOrder insertAutoAssign() {
+        AutoIncrementOpOrderPCSub pc = new AutoIncrementOpOrderPCSub();
+        pc.setSecondary("pc");
+        pc.setSub("pcsub");
+        AutoIncrementOpOrderPCSub rel = new AutoIncrementOpOrderPCSub();
+        rel.setSecondary("rel");
+        pc.setRel(rel);
+        for (int i = 0; i < 2; i++) {
+            AutoIncrementOpOrderPCSub child = new AutoIncrementOpOrderPCSub();
+            child.setSecondary("child" + i);
+            pc.getRelList().add(child);
+
+            AutoIncrementOpOrderPCSub mapped = new AutoIncrementOpOrderPCSub();
+            mapped.setSecondary("mapped" + i);
+            mapped.setOwner(pc);
+            pc.getMappedRelList().add(mapped);
+
+            AutoIncrementOpOrderPCSub inverse = new AutoIncrementOpOrderPCSub();
+            inverse.setSecondary("inverse" + i);
+            pc.getInverseKeyRelList().add(inverse);
+        }
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+        em.persist(rel);
+        persistAll(em,pc.getInverseKeyRelList());
+        em.persist(pc);
+        endTx(em);
+        OpOrder oid = em.find(AutoIncrementOpOrderPCSub.class,pc.getId());
+        em.close();
+        return oid;
+    }
+
+
+    private void insertCircularConstraintTest(boolean autoAssign) {
+        OpOrder oid = (autoAssign) ? insertCircularAutoAssign()
+            : insertCircular();
+
+        EntityManager em = currentEntityManager();
+        OpOrder pc1 = (OpOrder) em.find(OpOrder.class,oid.getId());
+        assertEquals("pc1", pc1.getSecondary());
+        assertNotNull(pc1.getRel());
+        assertEquals("pc2", pc1.getRel().getSecondary());
+        assertNotNull(pc1.getRel().getRel());
+        assertEquals(pc1, pc1.getRel().getRel());
+        em.close();
+    }
+
+    private OpOrder insertCircular() {
+        OpOrderPCSub pc1 = new OpOrderPCSub();
+        pc1.setSecondary("pc1");
+        pc1.setSub("pcsub");
+        OpOrderPCSub pc2 = new OpOrderPCSub();
+        pc2.setSecondary("pc2");
+        pc1.setRel(pc2);
+        pc2.setRel(pc1);
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+        em.persist(pc1);
+        em.persist(pc2);
+        endTx(em);
+        OpOrder oid = em.find(OpOrder.class,pc1.getId());
+        em.close();
+        return oid;
+    }
+
+    private OpOrder insertCircularAutoAssign() {
+        AutoIncrementOpOrderPCSub pc1 = new AutoIncrementOpOrderPCSub();
+        pc1.setSecondary("pc1");
+        pc1.setSub("pcsub");
+        AutoIncrementOpOrderPCSub pc2 = new AutoIncrementOpOrderPCSub();
+        pc2.setSecondary("pc2");
+        pc1.setRel(pc2);
+        pc2.setRel(pc1);
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+        em.persist(pc1);
+        em.persist(pc2);
+        endTx(em);
+        OpOrder oid = em.find(OpOrder.class,pc1.getId());
+        em.close();
+        return oid;
+    }
+
+
+    private void deleteCircularTest(boolean autoAssign) {
+        OpOrder oid = (autoAssign) ? insertCircularAutoAssign()
+            : insertCircular();
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+        OpOrder pc1 = (OpOrder) em.find(OpOrder.class,oid.getId());
+        em.remove(pc1.getRel());
+        em.remove(pc1);
+        endTx(em);
+        em.close();
+
+/*        pm = _pmf.getPersistenceManager();
+        if (autoAssign)
+            assertEquals(0, ((KodoExtent) pm.getExtent
+                (AutoIncrementOpOrderPCSub.class, true)).list().size());
+        else
+            assertEquals(0, ((KodoExtent) pm.getExtent(OpOrderPC.class,
+                true)).list().size());
+        pm.close();
+*/
+    }
+
+    private void deleteTest(boolean autoAssign) {
+        OpOrder oid = (autoAssign) ? insertAutoAssign() : insert();
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+        OpOrder pc = (OpOrder) em.find(OpOrder.class,oid.getId());
+        removeAll(em,pc.getMappedRelList());
+        removeAll(em,pc.getInverseKeyRelList());
+        removeAll(em,pc.getRelList());
+        em.remove(pc.getRel());
+        em.remove(pc);
+        endTx(em);
+        em.close();
+/*
+        pm = _pmf.getPersistenceManager();
+        if (autoAssign)
+            assertEquals(0, ((KodoExtent) pm.getExtent
+                (AutoIncrementOpOrderPCSub.class, true)).list().size());
+        else
+            assertEquals(0, ((KodoExtent) pm.getExtent(OpOrderPC.class,
+                true)).list().size());
+        pm.close();
+*/
+    }
+
+
+    public void testInsert() {
+        insertTest(false);
+    }
+
+    public void testAutoAssignInsert() {
+        insertTest(true);
+    }
+
+
+    public void testDeleteCircular() {
+        deleteCircularTest(false);
+    }
+
+    public void testAutoAssignDeleteCircular() {
+        deleteCircularTest(true);
+    }
+
+    public void testDelete() {
+        deleteTest(false);
+    }
+
+    public void testAutoAssignDelete() {
+        deleteTest(true);
+    }
+
+
+    public void testInsertCircularConstraint() {
+        insertCircularConstraintTest(false);
+    }
+
+    public void testAutoAssignInsertCircularConstraint() {
+        insertCircularConstraintTest(true);
+    }
+
+
+
+    private void persistAll(EntityManager em, List list) {
+
+		Iterator i = list.iterator();
+		while(i.hasNext()) {
+			Object o = i.next();
+			em.persist(o);
+		}
+	}
+
+
+	private void removeAll(EntityManager em, List list) {
+
+		Iterator i = list.iterator();
+		while(i.hasNext()) {
+			Object o = i.next();
+			em.remove(o);
+		}
+	}
+
+
+
+
+
+
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestPagingResultObjectProvider.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestPagingResultObjectProvider.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestPagingResultObjectProvider.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestPagingResultObjectProvider.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,656 @@
+/*
+ * 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.kernel;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.*;
+import org.apache.openjpa.jdbc.meta.*;
+import org.apache.openjpa.jdbc.sql.*;
+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.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+//import org.apache.openjpa.kernel.Extent;
+import org.apache.openjpa.persistence.Extent;
+
+/**
+ * <p>Test large result, to-many eager paging.</p>
+ *
+ */
+public class TestPagingResultObjectProvider
+    extends TestSQLListenerTestCase {
+
+	private OpenJPAEntityManagerFactory emf;
+
+	public TestPagingResultObjectProvider(String name)
+	{
+		super(name);
+	}
+
+    public void setUp() throws Exception{
+		super.setUp();
+		emf = getEmf(getProps());
+    	EntityManager em =currentEntityManager();
+    }
+
+
+
+    public boolean skipTest() {
+        JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactorySPI) OpenJPAPersistence.cast(emf)).getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        if (dict.joinSyntax == Join.SYNTAX_TRADITIONAL)
+            return true;
+
+        // skip test case that requires subselect for DBs that don't support it
+        if ("testPagingRangeQuery".equals(getName())
+            || "testNonPagingRangeQuery".equals(getName())) {
+            if (!conf.getDBDictionaryInstance().supportsSubselect)
+                return true;
+        }
+
+        return false;
+    }
+
+
+    public void testNonPagingExtent() {
+        initializePagingPCs();
+
+        EntityManager em= currentEntityManager();
+        //EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
+        Extent extent = kem.createExtent(PagingPC.class, true);
+
+        extent.getFetchPlan().setFetchBatchSize(0);
+        extent.getFetchPlan().addFetchGroup("rel");
+
+        // if we only access the rel field, we should only have used 1 select
+        List list = extent.list();
+        assertEquals(4, list.size());
+        assertRel(list, 4);
+        assertEquals(sql.toString(), 1, sql.size());
+        sql.clear();
+
+        // now accessing the rels collection should add selects
+        assertRels(list, 4);
+        assertEquals(sql.toString(), 4, sql.size());
+        sql.clear();
+
+        em.close();
+    }
+
+    public void testNonPagingQuery()
+        throws Exception {
+        initializePagingPCs();
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
+
+		String theQuery="select a FROM "+PagingPC.class.getSimpleName()+" a where a.intField >= 0";
+
+        //OpenJPAQuery q = kem.createQuery(PagingPC.class.getSimpleName(), "intField >= 0");
+        OpenJPAQuery q = kem.createQuery(theQuery);
+
+        q.getFetchPlan().setFetchBatchSize(0);
+        q.getFetchPlan().addFetchGroups("rel");
+
+        // if we only access the rel field, we should only have used two
+        // selects: one for the query and one for the size
+        List list = (List) q.getResultList();
+        assertEquals(4, list.size());
+        assertRel(list, 4);
+        assertEquals(sql.toString(), 2, sql.size());
+        assertTrue((String) sql.get(0),
+            matches(" >= ", (String) sql.get(0)));
+        assertTrue((String) sql.get(1),
+            matches(" COUNT", (String) sql.get(1)));
+        sql.clear();
+
+        // now accessing the rels collection should add selects
+        assertRels(list, 4);
+        assertEquals(sql.toString(), 4, sql.size());
+        sql.clear();
+
+        em.close();
+    }
+
+    /**
+     * Check that the rel field was retrieved correctly.
+     */
+   private void assertRel(List pcs, int size) {
+        PagingPC pc;
+        for (int i = 0; i < size; i++) {
+            pc = (PagingPC) pcs.get(i);
+            assertNotNull(pc.getRel());
+            assertEquals(pc.getIntField() + 1, pc.getRel().getIntField());
+        }
+        try {
+            pcs.get(size + 1);
+            fail("Retrieved past end of list");
+        } catch (Exception e) {
+        }
+    }
+
+    /**
+     * Check that the rels field was retrieved correctly.
+     */
+    private void assertRels(List pcs, int size) {
+        PagingPC pc;
+        for (int i = 0; i < size; i++) {
+            pc = (PagingPC) pcs.get(i);
+            assertEquals(2, pc.getRels().size());
+            assertEquals(pc.getIntField() + 1, ((PagingHelperPC)
+                pc.getRels().get(0)).getIntField());
+            assertEquals(pc.getIntField() + 2, ((PagingHelperPC)
+                pc.getRels().get(1)).getIntField());
+        }
+        try {
+            pcs.get(size + 1);
+            fail("Retrieved past end of list");
+        } catch (Exception e) {
+        }
+    }
+
+    public void testPagingExtent()
+        throws Exception {
+        initializePagingPCs();
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
+        Extent extent = kem.createExtent(PagingPC.class, true);
+        extent.getFetchPlan().setFetchBatchSize(0);
+        extent.getFetchPlan().addFetchGroup("rel");
+        extent.getFetchPlan().addFetchGroup("rels");
+
+
+        // we should get two selects: the initial select and the IN eager stmnt
+        List list = extent.list();
+        assertEquals(4, list.size());
+        assertRel(list, 4);
+        assertRels(list, 4);
+        assertEquals(sql.toString(), 2, sql.size());
+        assertTrue((String) sql.get(1),
+            matches(" IN ", (String) sql.get(1)));
+        sql.clear();
+
+        em.close();
+    }
+
+    public void testPagingQuery()
+        throws Exception {
+        initializePagingPCs();
+
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
+
+		String theQuery="select a FROM "+PagingPC.class.getSimpleName()+" a where a.intField >= 0";
+        OpenJPAQuery q = kem.createQuery(theQuery);
+        q.getFetchPlan().setFetchBatchSize(0);
+        q.getFetchPlan().addFetchGroups("rel");
+        q.getFetchPlan().addFetchGroups("rels");
+
+
+        // we should get three selects: the initial select, the COUNT for the
+        // size, and the IN eager stmnt
+        List list = (List) q.getResultList();
+        assertEquals(4, list.size());
+        assertRel(list, 4);
+        assertRels(list, 4);
+        assertEquals(sql.toString(), 3, sql.size());
+        assertTrue((String) sql.get(0),
+            matches(" >= ", (String) sql.get(0)));
+        assertTrue((String) sql.get(1),
+            matches(" COUNT", (String) sql.get(1)));
+        assertTrue((String) sql.get(2),
+            matches(" IN ", (String) sql.get(2)));
+        assertFalse((String) sql.get(2),
+            matches(" >= ", (String) sql.get(2)));
+        sql.clear();
+
+        // if we execute and traverse a result before getting the size, we
+        // should only get 2 selects, since the caching of the page should
+        // reach the end of the list and therefore know the total size
+        list = (List) q.getResultList();
+        list.get(0);
+        assertEquals(4, list.size());
+        assertRel(list, 4);
+        assertRels(list, 4);
+        assertEquals(sql.toString(), 2, sql.size());
+        assertTrue((String) sql.get(1),
+            matches(" IN ", (String) sql.get(1)));
+        sql.clear();
+
+        em.close();
+    }
+
+    public void testPagingAppIdExtent()
+        throws Exception {
+        initializePagingAppIdPCs();
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
+        Extent extent = kem.createExtent(PagingAppIdPC.class, true);
+
+        extent.getFetchPlan().setFetchBatchSize(0);
+        extent.getFetchPlan().addFetchGroup("rel");
+        extent.getFetchPlan().addFetchGroup("rels");
+
+        // we should get two selects: the initial select and the IN eager stmnt
+        List list = extent.list();
+        assertEquals(4, list.size());
+        assertAppIdRel(list, 4);
+        assertAppIdRels(list, 4);
+        assertEquals(sql.toString(), 2, sql.size());
+        assertTrue((String) sql.get(1),
+            matches(" OR ", (String) sql.get(1)));
+        sql.clear();
+
+        em.close();
+    }
+
+    public void testPagingAppIdQuery()
+        throws Exception {
+        initializePagingAppIdPCs();
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
+
+		String theQuery="select a FROM "+PagingAppIdPC.class.getSimpleName()+" a where a.intField >= 0";
+        OpenJPAQuery q = kem.createQuery(theQuery);
+
+
+        q.getFetchPlan().setFetchBatchSize(0);
+        q.getFetchPlan().addFetchGroups("rel");
+        q.getFetchPlan().addFetchGroups("rels");
+
+        // we should get three selects: the initial select, the COUNT for the
+        // size, and the OR eager stmnt
+        List list = (List) q.getResultList();
+        assertEquals(4, list.size());
+        assertAppIdRel(list, 4);
+        assertAppIdRels(list, 4);
+        assertEquals(sql.toString(), 3, sql.size());
+        assertTrue((String) sql.get(0),
+            matches(" >= ", (String) sql.get(0)));
+        assertTrue((String) sql.get(1),
+            matches(" COUNT", (String) sql.get(1)));
+        assertTrue((String) sql.get(2),
+            matches(" OR ", (String) sql.get(2)));
+        assertFalse((String) sql.get(2),
+            matches(" >= ", (String) sql.get(2)));
+        sql.clear();
+
+        em.close();
+    }
+
+    /**
+     * Check that the rel field was retrieved correctly.
+     */
+    private void assertAppIdRel(List pcs, int size) {
+        PagingAppIdPC pc;
+        for (int i = 0; i < size; i++) {
+            pc = (PagingAppIdPC) pcs.get(i);
+            assertNotNull(pc.getRel());
+            assertEquals(pc.getIntField() + 1, pc.getRel().getIntField());
+        }
+        try {
+            pcs.get(size + 1);
+            fail("Retrieved past end of list");
+        } catch (Exception e) {
+        }
+    }
+
+    /**
+     * Check that the rels field was retrieved correctly.
+     */
+    private void assertAppIdRels(List pcs, int size) {
+        PagingAppIdPC pc;
+        for (int i = 0; i < size; i++) {
+            pc = (PagingAppIdPC) pcs.get(i);
+            assertEquals(2, pc.getRels().size());
+            assertEquals(pc.getIntField() + 1, ((PagingHelperPC)
+                pc.getRels().get(0)).getIntField());
+            assertEquals(pc.getIntField() + 2, ((PagingHelperPC)
+                pc.getRels().get(1)).getIntField());
+        }
+        try {
+            pcs.get(size + 1);
+            fail("Retrieved past end of list");
+        } catch (Exception e) {
+        }
+    }
+
+    public void testMultiPageExtent()
+        throws Exception {
+        initializePagingPCs();
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
+        Extent extent = kem.createExtent(PagingPC.class, true);
+
+        extent.getFetchPlan().setFetchBatchSize(2);    // 2 pages of 2
+        extent.getFetchPlan().addFetchGroup("rel");
+        extent.getFetchPlan().addFetchGroup("rels");
+
+        // we should get two selects: the initial select and the IN eager stmnt
+        List list = extent.list();
+        assertEquals(list.toString(), 4, list.size());
+        assertRel(list, 4);
+        assertRels(list, 4);
+        assertEquals(sql.toString(), 3, sql.size());
+        assertTrue((String) sql.get(1),
+            matches(" IN ", (String) sql.get(1)));
+        assertTrue((String) sql.get(2),
+            matches(" IN ", (String) sql.get(2)));
+        sql.clear();
+
+        em.close();
+    }
+
+    public void testMultiPageQuery()
+        throws Exception {
+        initializePagingPCs();
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
+
+		String theQuery="select a FROM "+PagingPC.class.getSimpleName()+" a where a.intField >= 0";
+        OpenJPAQuery q = kem.createQuery(theQuery);
+
+
+		//FIXME jthomas commenting till we find how ordering can be done
+        //q.setOrdering("intField ascending");
+        q.getFetchPlan().setFetchBatchSize(2);    // 2 pages of 2
+        q.getFetchPlan().addFetchGroup("rel");
+        q.getFetchPlan().addFetchGroup("rels");
+
+        // we should get four selects: the initial select, the count, and the
+        // two IN eager stmnts
+        List list = (List) q.getResultList();
+        assertEquals(list.toString(), 4, list.size());
+        // so we don't have to re-execute to move back to beginning
+        list = new ArrayList(list);
+        assertRel(list, 4);
+        assertRels(list, 4);
+
+        assertEquals(sql.toString(), 4, sql.size());
+        assertTrue((String) sql.get(1),
+            matches(" COUNT", (String) sql.get(1)));
+        assertTrue((String) sql.get(2),
+            matches(" IN ", (String) sql.get(2)));
+        assertTrue((String) sql.get(3),
+            matches(" IN ", (String) sql.get(3)));
+        sql.clear();
+
+        // if we access a result object on the second page, we should get only
+        // three selects: the initial select, the count, and the IN eager stmnt
+        // for page 2
+        list = (List) q.getResultList();
+        assertEquals(list.toString(), 4, list.size());
+        PagingPC pc = (PagingPC) list.get(2);
+        assertEquals(2, pc.getIntField());
+        assertEquals(sql.toString(), 3, sql.size());
+        assertTrue((String) sql.get(2),
+            matches(" IN", (String) sql.get(2)));
+
+        assertRel(list, 4);
+        assertRels(list, 4);
+        sql.clear();
+
+        em.close();
+    }
+
+    public void testLastPageQuery()
+        throws Exception {
+        initializePagingPCs();
+
+        EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
+
+		String theQuery="select a FROM "+PagingPC.class.getSimpleName()+" a where a.intField >= 0";
+        OpenJPAQuery q = kem.createQuery(theQuery);
+
+
+        //FIXME jthomas commenting till we find how ordering can be done
+        //q.setOrdering("intField ascending");
+        q.getFetchPlan().setFetchBatchSize(3);    // 1 on page 2
+        q.getFetchPlan().addFetchGroups("rel");
+        q.getFetchPlan().addFetchGroups("rels");
+
+        // if we access a result object on the second page, we should get only
+        // two selects: the initial select and the eager stmnt for page
+        List list = (List) q.getResultList();
+        PagingPC pc = (PagingPC) list.get(3);
+        assertEquals(3, pc.getIntField());
+        assertEquals(list.toString(), 4, list.size());
+        assertEquals(sql.toString(), 2, sql.size());
+        // for single result, should use standard select, not IN
+        assertFalse((String) sql.get(1),
+            matches(" IN ", (String) sql.get(1)));
+        sql.clear();
+
+        em.close();
+    }
+
+    public void testSingleResultPage()
+        throws Exception {
+        initializePagingPCs();
+
+	    EntityManager em =currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
+        Extent extent = kem.createExtent(PagingPC.class, true);
+        extent.getFetchPlan().setFetchBatchSize(3);    // 1 on page 2
+        extent.getFetchPlan().addFetchGroup("rel");
+        extent.getFetchPlan().addFetchGroup("rels");
+
+        // we should get two selects: the initial select and the IN eager stmnt
+        List list = extent.list();
+        assertEquals(list.toString(), 4, list.size());
+        assertRel(list, 4);
+        assertRels(list, 4);
+        assertEquals(sql.toString(), 3, sql.size());
+        assertTrue((String) sql.get(1),
+            matches(" IN ", (String) sql.get(1)));
+        assertFalse((String) sql.get(2),
+            matches(" IN ", (String) sql.get(2)));
+        sql.clear();
+
+        em.close();
+    }
+
+  /*  public void testNonPagingRangeQuery()
+        throws Exception {
+        initializePagingPCs();
+
+        EntityManager em =currentEntityManager();
+        Query q = em.newQuery(PagingPC.class, "intField >= 0");
+
+        //FIXME jthomas commenting till we find how ordering can be done
+        //q.setOrdering("intField ascending");
+        q.setRange(1, 3);
+        q.getFetchPlan().setFetchSize(0);
+        q.getFetchPlan().addGroup("rel");
+
+        // if we only access the rel field, we should only have used one
+        // select; there won't be a size select since the range will be
+        // greedily consumed as it's so small
+        List list = (List) q.execute();
+        assertEquals(2, list.size());
+        assertRel(list, 2);
+        assertEquals(sql.toString(), 1, sql.size());
+        assertTrue((String) sql.get(0),
+            matches(" >= ", (String) sql.get(0)));
+        sql.clear();
+
+        // now accessing the rels collection should add selects
+        assertRels(list, 2);
+        assertEquals(sql.toString(), 2, sql.size());
+        sql.clear();
+
+        // now execute with a big range and small fetch size and bigger range
+        // and this time we should get a select for the size too
+        q.getFetchPlan().setFetchSize(2);
+        q.setRange(1, 4);
+        list = (List) q.execute();
+        assertEquals(3, list.size());
+        // so we don't have to re-execute to move back to beginning
+        list = new ArrayList(list);
+        assertRel(list, 3);
+        assertEquals(sql.toString(), 2, sql.size());
+        assertTrue((String) sql.get(0),
+            matches(" >= ", (String) sql.get(0)));
+        assertTrue((String) sql.get(1),
+            matches(" COUNT", (String) sql.get(1)));
+        sql.clear();
+
+        em.close();
+    }
+/*
+    public void testPagingRangeQuery()
+        throws Exception {
+        initializePagingPCs();
+
+        EntityManager em =currentEntityManager();
+        Query q = em.newQuery(PagingPC.class, "intField >= 0");
+
+        //FIXME jthomas commenting till we find how ordering can be done
+        //q.setOrdering("intField ascending");
+        q.setRange(1, 3);
+        q.getFetchPlan().setFetchSize(0);
+        q.getFetchPlan().addGroup("rel");
+        q.getFetchPlan().addGroup("rels");
+
+        // expect two selects: the primary select and the IN select; no size
+        // select expected because the range will be consumed greedily since
+        // it's so small
+        List list = (List) q.execute();
+        assertEquals(2, list.size());
+        assertRel(list, 2);
+        assertRels(list, 2);
+        assertEquals(sql.toString(), 2, sql.size());
+        assertTrue((String) sql.get(0),
+            matches(" >= ", (String) sql.get(0)));
+        assertTrue(sql + "",
+            matches(" IN ", (String) sql.get(1)));
+        sql.clear();
+
+        // now execute with a big range and small fetch size and bigger range
+        // and this time we should get a select for the size too
+        q.getFetchPlan().setFetchSize(2);
+        q.setRange(1, 4);
+        list = (List) q.execute();
+        assertEquals(3, list.size());
+        // so we don't have to re-execute to move back to beginning
+        list = new ArrayList(list);
+        assertRel(list, 3);
+        assertRels(list, 3);
+        assertEquals(sql.toString(), 4, sql.size());
+        assertTrue((String) sql.get(0),
+            matches(" >= ", (String) sql.get(0)));
+        assertTrue((String) sql.get(1),
+            matches(" COUNT", (String) sql.get(1)));
+        assertTrue((String) sql.get(2),
+            matches(" IN ", (String) sql.get(2)));
+        assertFalse((String) sql.get(3),
+            matches(" IN ", (String) sql.get(3)));
+        sql.clear();
+
+        em.close();
+    }
+*/
+    private void initializePagingPCs() {
+        EntityManager em =currentEntityManager();
+        startTx(em);
+
+       deleteAll(PagingPC.class,em);
+       deleteAll(PagingHelperPC.class,em);
+
+        endTx(em);
+
+        startTx(em);
+        PagingPC pc;
+        PagingHelperPC rel;
+        for (int i = 0; i < 4; i++) {
+            pc = new PagingPC();
+            pc.setIntField(i);
+            rel = new PagingHelperPC();
+            rel.setIntField(i + 1);
+            pc.setRel(rel);
+            pc.getRels().add(rel);
+            rel = new PagingHelperPC();
+            rel.setIntField(i + 2);
+            pc.getRels().add(rel);
+            em.persist(pc);
+        }
+
+        endTx(em);
+        em.close();
+        sql.clear();
+    }
+
+    private void initializePagingAppIdPCs() {
+        EntityManager em =currentEntityManager();
+        startTx(em);
+       deleteAll(PagingAppIdPC.class,em);
+       deleteAll(PagingHelperPC.class,em);
+        startTx(em);
+
+        startTx(em);
+        PagingAppIdPC pc;
+        PagingHelperPC rel;
+        for (int i = 0; i < 4; i++) {
+            pc = new PagingAppIdPC();
+            pc.setIntField(i);
+            pc.setLongField(i + 100);
+            rel = new PagingHelperPC();
+            rel.setIntField(i + 1);
+            pc.setRel(rel);
+            pc.getRels().add(rel);
+            rel = new PagingHelperPC();
+            rel.setIntField(i + 2);
+            pc.getRels().add(rel);
+            em.persist(pc);
+        }
+
+        endTx(em);
+     	em.close();
+        sql.clear ();
+	}
+
+	private Map getProps() {
+		Map props=new HashMap();
+		props.put("openjpa.DataCache", "true");
+		props.put("openjpa.RemoteCommitProvider", "sjvm");
+		props.put("openjpa.FlushBeforeQueries", "true");
+		props.put("javax.jdo.option.IgnoreCache", "false");
+		//propsMap.put("openjpa.BrokerImpl", "kodo.datacache.CacheTestBroker");//CacheTestBroker.class.getName ());
+		return props;
+	}
+
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestRawSQL.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestRawSQL.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestRawSQL.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestRawSQL.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,180 @@
+
+/*
+ * 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.kernel;
+
+
+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 java.sql.*;
+import java.util.*;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.jdbc.kernel.JDBCStore;
+import org.apache.openjpa.jdbc.sql.ResultSetResult;
+import org.apache.openjpa.lib.rop.ResultObjectProvider;
+import org.apache.openjpa.jdbc.kernel.GenericResultObjectProvider;
+import org.apache.openjpa.lib.rop.ResultList;
+import org.apache.openjpa.lib.rop.EagerResultList;
+import org.apache.openjpa.lib.rop.ResultObjectProvider;
+import org.apache.openjpa.kernel.AbstractPCResultObjectProvider;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.kernel.FetchConfiguration;
+/**
+ *
+ */
+
+
+public class TestRawSQL extends BaseJDBCTest {
+    
+    /** Creates a new instance of TestRawSQL */
+    private Object[] _oids = new Object[3];
+    private String[] _strings = new String[]{ "a", "b", "c" };
+    private int[] _ints = new int[]{ 1, 2, 3 };
+
+    public TestRawSQL(String test) {
+        super(test);
+    }
+
+    public void setUp() {
+       deleteAll(RawSQL.class);
+        EntityManager em = currentEntityManager();
+        Broker broker = JPAFacadeHelper.toBroker(em);
+
+        broker.begin();
+        RawSQL raw;
+        for (int i = 0; i < _oids.length; i++) {
+            raw = new RawSQL(_strings[i], _ints[i]);
+            broker.persist(raw, null);
+            _oids[i] = broker.getUserObject(raw);
+        }
+        broker.commit();
+        broker.close();
+        em.close();
+    }
+
+    public void testLoadWithResult()
+        throws Exception {
+        
+        EntityManager em = currentEntityManager();
+        Broker broker = JPAFacadeHelper.toBroker(em);
+       
+        JDBCStore store = (JDBCStore)broker.getStoreManager();
+
+        Connection conn = store.getConnection();
+        Statement stmnt = conn.createStatement();
+        ResultSet rs = stmnt.executeQuery("SELECT * FROM RAWSQL "
+        + "ORDER BY INTFIELD");
+        ResultSetResult res = new ResultSetResult(rs,
+        store.getConfiguration().getDBDictionaryInstance());
+        ResultObjectProvider rop = new GenericResultObjectProvider
+        (RawSQL.class, store, null, res);
+        ResultList rl = new EagerResultList(rop);
+        check(rl, broker);
+        rl.close();
+        broker.close();
+        em.close();
+    }
+
+        public void testLoadWithPCROP()
+        throws Exception {
+            
+        EntityManager em = currentEntityManager();    
+        Broker broker = JPAFacadeHelper.toBroker(em);
+        ResultObjectProvider rop = new AbstractPCResultObjectProvider(broker) {
+            private int _row = -1;
+
+            public boolean supportsRandomAccess() {
+                return true;
+            }
+
+            public boolean next() {
+                return ++_row < _oids.length;
+            }
+
+            public boolean absolute(int pos) {
+                _row = pos;
+                return _row < _oids.length;
+            }
+
+            public int size() {
+                return _oids.length;
+            }
+
+            public void close() {
+            }
+
+            public void handleCheckedException(Exception e) {
+                throw new RuntimeException(e.toString());
+            }
+
+            protected Object getObjectId(ClassMetaData meta) {
+                return _oids[_row];
+            }
+
+            protected Class getPCType() {
+                return RawSQL.class;
+            }
+
+            protected void load(OpenJPAStateManager sm, 
+                FetchConfiguration fetch) {
+                ClassMetaData meta = sm.getMetaData();
+                sm.storeStringField(meta.getField("stringField").getIndex(),
+                    _strings[_row]);
+                sm.storeIntField(meta.getField("intField").getIndex(),
+                    _ints[_row]);
+
+                // note that we're not loading version info here, so the system
+                // will go out and get it after this intial load; kinda neat
+            }
+        };
+        ResultList rl = new EagerResultList(rop);
+        check(rl, broker);
+        rl.close();
+        broker.close();
+    }
+
+    
+    
+    private void check(ResultList rl, Broker broker) {
+        RawSQL raw;
+        int i = 0;
+        for (Iterator itr = rl.iterator(); itr.hasNext(); i++) {
+            raw = (RawSQL) itr.next();
+            assertTrue(broker.getStateManager(raw).getLoaded().get(0));
+            assertTrue(broker.getStateManager(raw).getLoaded().get(1));
+            if (i < _oids.length) {
+                assertEquals(_strings[i], raw.getStringField());
+                assertEquals(_ints[i], raw.getIntField());
+            }
+        }
+        assertEquals(_oids.length, i);
+        assertEquals(_oids.length, rl.size());
+    }
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestSQLListenerTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestSQLListenerTestCase.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestSQLListenerTestCase.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestSQLListenerTestCase.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,176 @@
+/*
+ * 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.kernel;
+
+import java.util.*;
+
+
+import org.apache.openjpa.kernel.*;
+
+
+
+import org.apache.openjpa.lib.jdbc.*;
+
+/**
+ * Test case that provides access to all the SQL that is executed.
+ *
+ */
+public abstract class TestSQLListenerTestCase
+    extends BaseJDBCTest {
+
+    protected static final Collection brokers = new HashSet();
+    public static List sql = new ArrayList();
+
+    public TestSQLListenerTestCase() {
+    }
+
+    public TestSQLListenerTestCase(String name) {
+        super(name);
+    }
+
+    public void setUp()
+        throws Exception {
+        super.setUp();
+        setUpTestCase();
+        sql.clear();
+    }
+
+    /**
+     * Override for setUp() behavior.
+     */
+    public void setUpTestCase() {
+    }
+
+    public final void tearDown()
+        throws Exception {
+        super.tearDown();
+        tearDownTestCase();
+        sql.clear();
+    }
+
+    /**
+     * Override for tearDown() behavior.
+     */
+    public void tearDownTestCase() {
+    }
+
+    /**
+     * Confirm that the specified SQL has been executed.
+     *
+     * @param sqlExp the SQL expression. E.g., "SELECT FOO .*"
+     */
+    public void assertSQL(String sqlExp)
+        throws Exception {
+        for (Iterator i = sql.iterator(); i.hasNext();) {
+            String statement = (String) i.next();
+            if (matches(sqlExp, statement))
+                return;
+        }
+
+        fail("Expected regular expression <" + sqlExp + "> to have"
+            + " existed in SQL statements: " + sql);
+    }
+
+    /**
+     * Confirm that the specified SQL has not been executed.
+     *
+     * @param sqlExp the SQL expression. E.g., "SELECT BADCOLUMN .*"
+     */
+    public void assertNotSQL(String sqlExp)
+        throws Exception {
+        boolean failed = false;
+
+        for (Iterator i = sql.iterator(); i.hasNext();) {
+            String statement = (String) i.next();
+            if (matches(sqlExp, statement))
+                failed = true;
+        }
+
+        if (failed)
+            fail("Regular expression <" + sqlExp + ">"
+                + " should not have been executed in SQL statements: " + sql);
+    }
+/*
+
+    public KodoPersistenceManager getPM() {
+        KodoPersistenceManager pm = (KodoPersistenceManager) getPMFactory().
+            getPersistenceManager();
+        brokers.add(KodoJDOHelper.toBroker(pm));
+        return pm;
+    }
+
+    public KodoPersistenceManagerFactory getPMFactory() {
+        return getPMFactory(null);
+    }
+    public BrokerFactory getBrokerFactory(String[] props) {
+        String[] builtin = new String[]{
+            "openjpa.jdbc.JDBCListeners", Listener.class.getName()
+        };
+
+        if (props == null)
+            props = builtin;
+        else {
+            String[] tmp = new String[props.length + builtin.length];
+            System.arraycopy(props, 0, tmp, 0, props.length);
+            System.arraycopy(builtin, 0, tmp, props.length, builtin.length);
+            props = tmp;
+        }
+
+        return super.getBrokerFactory(props);
+    }
+    public KodoPersistenceManagerFactory getPMFactory(String[] props) {
+        String[] builtin = new String[]{
+            "openjpa.jdbc.JDBCListeners", Listener.class.getName()
+        };
+
+        if (props == null)
+            props = builtin;
+        else {
+            String[] tmp = new String[props.length + builtin.length];
+            System.arraycopy(props, 0, tmp, 0, props.length);
+            System.arraycopy(builtin, 0, tmp, props.length, builtin.length);
+            props = tmp;
+        }
+
+        return super.getPMFactory(props);
+    }
+
+    public Broker getBroker() {
+        Broker broker = getBrokerFactory().newBroker();
+        brokers.add(broker);
+        return broker;
+    }
+
+    public BrokerFactory getBrokerFactory() {
+        return getBrokerFactory(null);
+    }
+
+*/
+
+
+
+    public static class Listener
+        extends AbstractJDBCListener {
+
+        public void beforeExecuteStatement(JDBCEvent event) {
+            if (event.getSQL() != null)
+                sql.add(event.getSQL());
+		}
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestUnknownSubclass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestUnknownSubclass.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestUnknownSubclass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestUnknownSubclass.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,138 @@
+/*
+ * TestUnknownSubclass.java
+ *
+ * Created on September 29, 2006, 3:55 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.kernel;
+
+
+import java.sql.*;
+import javax.sql.*;
+import org.apache.openjpa.jdbc.conf.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+
+public class TestUnknownSubclass  extends JDBCTestCase {
+
+    private String parentName =
+        "openjpa.jdbc.kernel.UnknownSubclassParent";
+    private String childName =
+        "openjpa.jdbc.kernel.UnknownSubclassChild";
+
+    /** Creates a new instance of TestUnknownSubclass */
+    public TestUnknownSubclass() {
+    }
+ 
+    public TestUnknownSubclass(String name) {
+        super(name);
+    }
+    public void setUp()
+        throws Exception {
+        // pcl: in the new (registration-less) system, this should not
+        // matter.
+        //assertNotRegistered (parentName);
+        //assertNotRegistered (childName);
+
+        EntityManager em= currentEntityManager();
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast (em);
+        
+        
+        JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerSPI) kem).getConfiguration();
+        boolean flat = !isInheritanceStrategyVertical();
+
+        DataSource ds = (DataSource) conf.getConnectionFactory();
+        Connection c = ds.getConnection(conf.getConnectionUserName(),
+            conf.getConnectionPassword());
+        if (c.getAutoCommit())
+            c.setAutoCommit(false);
+
+        c.createStatement()
+            .executeUpdate("DELETE FROM UNKNOWNSUBCLASSPARENT");
+        if (!flat)
+            c.createStatement()
+                .executeUpdate("DELETE FROM UNKNOWNSUBCLASSCHILD");
+
+        String insert = "INSERT INTO UNKNOWNSUBCLASSPARENT"
+            + "(TYP, ID, VERSN) VALUES (";
+
+        c.createStatement().executeUpdate(insert
+            + "'" + parentName + "', 1, 1)");
+        c.createStatement().executeUpdate(insert
+            + "'" + childName + "', 2, 1)");
+
+        if (!flat) {
+            insert = "INSERT INTO UNKNOWNSUBCLASSCHILD (ID) VALUES (";
+            c.createStatement().executeUpdate(insert + "1)");
+            c.createStatement().executeUpdate(insert + "2)");
+        }
+
+        c.commit();
+        em.close();
+        kem.close();
+    }
+
+        public void testUnknownSubclass()
+        throws Exception {
+        // assertNotRegistered (parentName);
+        // assertNotRegistered (childName);
+
+        Class c = UnknownSubclassParent.class;
+
+        // assertNotRegistered (childName);
+
+        EntityManager em= currentEntityManager();            
+        OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
+
+        
+        startTx(em);
+        // c = UnknownSubclassChild.class;
+
+        //FIXME jthomas conversion incomplete 
+        /*
+        assertSize(1, kem.createExtent(UnknownSubclassParent.class, false));
+        assertSize(1, kem.newQuery(
+            kem.createExtent(UnknownSubclassParent.class, false), ""));
+
+        assertSize(2, kem.createExtent(UnknownSubclassParent.class, true));
+        assertSize(2, kem.createQuery(kem.createExtent(UnknownSubclassParent.class, true), ""));
+        */
+        endTx(em);
+        
+        em.close();
+        kem.close();
+    }
+    
+    
+}



Mime
View raw message