openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [22/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/vertical/TestSubclassJoinExtent.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinExtent.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinExtent.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinExtent.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,287 @@
+/*
+ * TestSubclassJoinExtent.java
+ *
+ * Created on October 5, 2006, 3:41 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.vertical;
+
+import java.util.*;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.Join;
+import org.apache.openjpa.persistence.Extent;
+
+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 TestSubclassJoinExtent
+        extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase{
+   
+    private String _outer = "OUTER";
+    
+    /** Creates a new instance of TestSubclassJoinExtent */
+    public TestSubclassJoinExtent(String name) 
+    {
+    	super(name);
+    }
+    
+    public boolean skipTest() {
+        //FIXME
+        /*
+        return super.skipTest()
+            || ((JDBCConfiguration) getConfiguration()).
+            getDBDictionaryInstance().joinSyntax == Join.SYNTAX_TRADITIONAL;
+         */
+        return false;
+    }
+    
+    public void setUpTestCase() {
+        // make sure all classes are registered
+        Class[] reg = new Class[]{
+            Base.class, BaseSub1.class, BaseSub2.class,
+            BaseSub1Sub1.class, BaseSub1Sub2.class,
+        };
+        
+        if (((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance().
+                joinSyntax == Join.SYNTAX_DATABASE)
+            _outer = "(+)";
+        
+       deleteAll(Base.class);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        Base base = new Base();
+        base.setBaseField(1);
+        pm.persist(base);
+        
+        BaseSub1 sub1 = new BaseSub1();
+        sub1.setBaseField(2);
+        sub1.setBaseSub1Field(3);
+        pm.persist(sub1);
+        
+        BaseSub2 sub2 = new BaseSub2();
+        sub2.setBaseField(3);
+        sub2.setBaseSub2Field(4);
+        pm.persist(sub2);
+        
+        BaseSub1Sub2 sub1sub2 = new BaseSub1Sub2();
+        sub1sub2.setBaseField(4);
+        sub1sub2.setBaseSub1Field(5);
+        sub1sub2.setBaseSub1Sub2Field(6);
+        pm.persist(sub1sub2);
+        
+        endTx(pm);;
+        pm.close();
+    }
+    
+    public void testBaseNoSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(Base.class, false);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        Base pc = (Base) itr.next();
+        assertEquals(1, pc.getBaseField());
+        assertEquals(Base.class, pc.getClass());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testBaseWithSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(Base.class, true);
+        Collection pcs = new TreeSet(((Extent) extent).list());
+        assertEquals(4, pcs.size());
+        Iterator itr = pcs.iterator();
+        for (int i = 0; i < 4; i++) {
+            Base pc = (Base) itr.next();
+            assertEquals(i + 1, pc.getBaseField());
+            switch (i) {
+                case 0:
+                    assertEquals(Base.class, pc.getClass());
+                    break;
+                case 1:
+                    assertEquals(BaseSub1.class, pc.getClass());
+                    break;
+                case 2:
+                    assertEquals(BaseSub2.class, pc.getClass());
+                    break;
+                case 3:
+                    assertEquals(BaseSub1Sub2.class, pc.getClass());
+                    break;
+            }
+        }
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testEmptyNoSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub1Sub1.class, false);
+        Iterator itr = extent.iterator();
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        assertNotSQL(_outer);
+    }
+    
+    public void testEmptyWithSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub1Sub1.class, true);
+        Iterator itr = extent.iterator();
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        assertNotSQL(_outer);
+    }
+    
+    public void testLeafNoSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub1Sub2.class, false);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        BaseSub1Sub2 pc = (BaseSub1Sub2) itr.next();
+        assertEquals(4, pc.getBaseField());
+        assertEquals(5, pc.getBaseSub1Field());
+        assertEquals(6, pc.getBaseSub1Sub2Field());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+    }
+    
+    public void testLeafWithSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub1Sub2.class, true);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        BaseSub1Sub2 pc = (BaseSub1Sub2) itr.next();
+        assertEquals(4, pc.getBaseField());
+        assertEquals(5, pc.getBaseSub1Field());
+        assertEquals(6, pc.getBaseSub1Sub2Field());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+    }
+    
+    public void testLeafNoSubs2()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub2.class, false);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        BaseSub2 pc = (BaseSub2) itr.next();
+        assertEquals(3, pc.getBaseField());
+        assertEquals(4, pc.getBaseSub2Field());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+    }
+    
+    public void testLeafWithSubs2()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub2.class, true);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        BaseSub2 pc = (BaseSub2) itr.next();
+        assertEquals(3, pc.getBaseField());
+        assertEquals(4, pc.getBaseSub2Field());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+    }
+    
+    public void testMidNoSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub1.class, false);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        BaseSub1 pc = (BaseSub1) itr.next();
+        assertEquals(2, pc.getBaseField());
+        assertEquals(3, pc.getBaseSub1Field());
+        assertEquals(BaseSub1.class, pc.getClass());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testMidWithSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(BaseSub1.class, true);
+        Collection pcs = new TreeSet(((Extent) extent).list());
+        assertEquals(2, pcs.size());
+        Iterator itr = pcs.iterator();
+        BaseSub1 pc = (BaseSub1) itr.next();
+        assertEquals(2, pc.getBaseField());
+        assertEquals(3, pc.getBaseSub1Field());
+        assertEquals(BaseSub1.class, pc.getClass());
+        pc = (BaseSub1) itr.next();
+        assertEquals(4, pc.getBaseField());
+        assertEquals(5, pc.getBaseSub1Field());
+        assertEquals(BaseSub1Sub2.class, pc.getClass());
+        assertEquals(6, ((BaseSub1Sub2) pc).getBaseSub1Sub2Field());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinGetObjectById.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinGetObjectById.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinGetObjectById.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinGetObjectById.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,229 @@
+/*
+ * TestSubclassJoinGetObjectById.java
+ *
+ * Created on October 5, 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.meta.vertical;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.Join;
+import org.apache.openjpa.util.Id;
+
+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 TestSubclassJoinGetObjectById
+        extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase{
+    
+
+    private String _outer = "OUTER";
+    
+    /** Creates a new instance of TestSubclassJoinGetObjectById */
+    public TestSubclassJoinGetObjectById(String name) 
+    {
+    	super(name);
+    }
+    
+    
+    public boolean skipTest() {
+        //FIXME
+        /*
+        return super.skipTest()
+            || ((JDBCConfiguration) getConfiguration()).
+            getDBDictionaryInstance().joinSyntax == Join.SYNTAX_TRADITIONAL;
+         */
+        return false;
+    }
+    
+    public void setUpTestCase() {
+        // make sure all classes are registered
+        Class[] reg = new Class[]{
+            Base.class, BaseSub1.class, BaseSub2.class,
+            BaseSub1Sub1.class, BaseSub1Sub2.class,
+        };
+        
+        if (((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance().
+                joinSyntax == Join.SYNTAX_DATABASE)
+            _outer = "(+)";
+        
+       deleteAll(Base.class);
+    }
+    
+    public void testBase()
+    throws Exception {
+        Base pc = new Base();
+        pc.setBaseField(1);
+        Object oid = persist(pc);
+        sql.clear();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        
+        pc = (Base) pm.getObjectId(oid);
+        assertEquals(1, pc.getBaseField());
+        assertEquals(Base.class, pc.getClass());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+        
+        // should outer join with non-exact oid
+        oid = new Id(Base.class, ((Id) oid).getId());
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pc = (Base) pm.getObjectId(oid);
+        assertEquals(1, pc.getBaseField());
+        assertEquals(Base.class, pc.getClass());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testBadId()
+    throws Exception {
+        Base pc = new Base();
+        pc.setBaseField(1);
+        Object oid = persist(pc);
+        sql.clear();
+        
+        Id id = new Id(Base.class, -1);
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        try {
+            pm.getObjectId(id);
+            fail("No exception on bad id.");
+        } catch (Exception jonfe) {
+        }
+        pm.close();
+    }
+    
+    public void testLeaf()
+    throws Exception {
+        BaseSub1Sub2 pc = new BaseSub1Sub2();
+        pc.setBaseField(4);
+        pc.setBaseSub1Field(5);
+        pc.setBaseSub1Sub2Field(6);
+        Object oid = persist(pc);
+        sql.clear();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pc = (BaseSub1Sub2) pm.getObjectId(oid);
+        assertEquals(4, pc.getBaseField());
+        assertEquals(5, pc.getBaseSub1Field());
+        assertEquals(6, pc.getBaseSub1Sub2Field());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+        
+        // should outer join with inexact oid
+        oid = new Id(Base.class, ((Id) oid).getId());
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pc = (BaseSub1Sub2) pm.getObjectId(oid);
+        assertEquals(4, pc.getBaseField());
+        assertEquals(5, pc.getBaseSub1Field());
+        assertEquals(6, pc.getBaseSub1Sub2Field());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testLeaf2()
+    throws Exception {
+        BaseSub2 pc = new BaseSub2();
+        pc.setBaseField(3);
+        pc.setBaseSub2Field(4);
+        Object oid = persist(pc);
+        sql.clear();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pc = (BaseSub2) pm.getObjectId(oid);
+        assertEquals(3, pc.getBaseField());
+        assertEquals(4, pc.getBaseSub2Field());
+        assertEquals(BaseSub2.class, pc.getClass());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+        
+        // should outer join with inexact oid
+        oid = new Id(Base.class, ((Id) oid).getId());
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pc = (BaseSub2) pm.getObjectId(oid);
+        assertEquals(3, pc.getBaseField());
+        assertEquals(4, pc.getBaseSub2Field());
+        assertEquals(BaseSub2.class, pc.getClass());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testMid()
+    throws Exception {
+        BaseSub1 pc = new BaseSub1();
+        pc.setBaseField(2);
+        pc.setBaseSub1Field(3);
+        Object oid = persist(pc);
+        sql.clear();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pc = (BaseSub1) pm.getObjectId(oid);
+        assertEquals(2, pc.getBaseField());
+        assertEquals(3, pc.getBaseSub1Field());
+        assertEquals(BaseSub1.class, pc.getClass());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+        
+        // should outer join with inexact oid
+        oid = new Id(Base.class, ((Id) oid).getId());
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pc = (BaseSub1) pm.getObjectId(oid);
+        assertEquals(2, pc.getBaseField());
+        assertEquals(3, pc.getBaseSub1Field());
+        assertEquals(BaseSub1.class, pc.getClass());
+        pm.close();
+        
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinRelations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinRelations.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinRelations.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestSubclassJoinRelations.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,466 @@
+/*
+ * TestSubclassJoinRelations.java
+ *
+ * Created on October 5, 2006, 4:28 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.jdbc.meta.vertical;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.Join;
+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;
+
+
+public class TestSubclassJoinRelations extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase 
+{
+    private String _outer = "OUTER";
+    private Object _oid = null;
+    
+    /** Creates a new instance of TestSubclassJoinRelations */
+    public TestSubclassJoinRelations(String name) 
+    {
+    	super(name);
+    }
+    
+    public boolean skipTest() {
+        //FIXME 
+        /*
+        return super.skipTest()
+            || ((JDBCConfiguration) getConfiguration()).
+            getDBDictionaryInstance().joinSyntax == Join.SYNTAX_TRADITIONAL;
+         */
+        return false;
+    }
+
+    public void setUpTestCase() {
+        // make sure all classes are registered
+        Class[] reg = new Class[]{
+            Base.class, BaseSub1.class, BaseSub2.class,
+            BaseSub1Sub1.class, BaseSub1Sub2.class,
+        };
+
+        if (((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance().
+            joinSyntax == Join.SYNTAX_DATABASE)
+            _outer = "(+)";
+
+       deleteAll(Relations.class);
+       deleteAll(Base.class);
+
+        Relations rel = new Relations();
+        BaseSub2 sub2 = new BaseSub2();
+        sub2.setBaseField(3);
+        sub2.setBaseSub2Field(4);
+        rel.setBase(sub2);
+
+        BaseSub1 sub1 = new BaseSub1();
+        sub1.setBaseField(2);
+        sub1.setBaseSub1Field(3);
+        rel.setBaseSub1(sub1);
+
+        BaseSub1Sub2 sub1sub2 = new BaseSub1Sub2();
+        sub1sub2.setBaseField(4);
+        sub1sub2.setBaseSub1Field(5);
+        sub1sub2.setBaseSub1Sub2Field(6);
+        rel.setBaseSub1Sub2(sub1sub2);
+
+        Base base = new Base();
+        base.setBaseField(1);
+        rel.getBaseList().add(base);
+        rel.getBaseList().add(sub2);
+
+        rel.getBaseSub1List().add(sub1);
+        rel.getBaseSub1List().add(sub1sub2);
+
+        rel.getBaseSub1Sub2List().add(sub1sub2);
+
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        pm.persist(rel);
+        endTx(pm);;
+        _oid = pm.getObjectId(rel);
+        pm.close();
+    }
+
+    public void testNullOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        assertNull(rel.getNullBase());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testEagerNullOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("nullBase");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+        sql.clear();
+
+        assertNull(rel.getNullBase());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testEmptyBaseList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        assertEquals(0, rel.getEmptyBaseList().size());
+        pm.close();
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+
+    public void testEagerEmptyBaseList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("emptyBaseList");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+        sql.clear();
+
+        assertEquals(0, rel.getEmptyBaseList().size());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testBaseOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        BaseSub2 sub2 = (BaseSub2) rel.getBase();
+        assertEquals(3, sub2.getBaseField());
+        assertEquals(4, sub2.getBaseSub2Field());
+        assertEquals(BaseSub2.class, sub2.getClass());
+        pm.close();
+
+        assertEquals(sql.toString(), 1, sql.size());
+        assertSQL(_outer);
+    }
+
+    public void testEagerBaseOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("base");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+        sql.clear();
+
+        BaseSub2 sub2 = (BaseSub2) rel.getBase();
+        assertEquals(3, sub2.getBaseField());
+        assertEquals(4, sub2.getBaseSub2Field());
+        assertEquals(BaseSub2.class, sub2.getClass());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testLeafOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        BaseSub1Sub2 sub1sub2 = (BaseSub1Sub2) rel.getBaseSub1Sub2();
+        assertEquals(4, sub1sub2.getBaseField());
+        assertEquals(5, sub1sub2.getBaseSub1Field());
+        assertEquals(6, sub1sub2.getBaseSub1Sub2Field());
+        pm.close();
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+    }
+
+    public void testEagerLeafOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("baseSub1Sub2");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+        sql.clear();
+
+        BaseSub1Sub2 sub1sub2 = (BaseSub1Sub2) rel.getBaseSub1Sub2();
+        assertEquals(4, sub1sub2.getBaseField());
+        assertEquals(5, sub1sub2.getBaseSub1Field());
+        assertEquals(6, sub1sub2.getBaseSub1Sub2Field());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testMidOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        BaseSub1 sub1 = (BaseSub1) rel.getBaseSub1();
+        assertEquals(2, sub1.getBaseField());
+        assertEquals(3, sub1.getBaseSub1Field());
+        assertEquals(BaseSub1.class, sub1.getClass());
+        pm.close();
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+
+    public void testEagerMidOneOne()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("baseSub1");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+        sql.clear();
+
+        BaseSub1 sub1 = (BaseSub1) rel.getBaseSub1();
+        assertEquals(2, sub1.getBaseField());
+        assertEquals(3, sub1.getBaseSub1Field());
+        assertEquals(BaseSub1.class, sub1.getClass());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testBaseList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        List list = rel.getBaseList();
+        assertEquals(2, list.size());
+        Base base = (Base) list.get(0);
+        assertEquals(1, base.getBaseField());
+        assertEquals(Base.class, base.getClass());
+        BaseSub2 sub2 = (BaseSub2) list.get(1);
+        assertEquals(3, sub2.getBaseField());
+        assertEquals(4, sub2.getBaseSub2Field());
+        assertEquals(BaseSub2.class, sub2.getClass());
+        pm.close();
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+
+    public void testEagerBaseList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("baseList");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+        sql.clear();
+
+        List list = rel.getBaseList();
+        assertEquals(2, list.size());
+        Base base = (Base) list.get(0);
+        assertEquals(1, base.getBaseField());
+        assertEquals(Base.class, base.getClass());
+        BaseSub2 sub2 = (BaseSub2) list.get(1);
+        assertEquals(3, sub2.getBaseField());
+        assertEquals(4, sub2.getBaseSub2Field());
+        assertEquals(BaseSub2.class, sub2.getClass());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testLeafList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        List list = rel.getBaseSub1Sub2List();
+        assertEquals(1, list.size());
+        BaseSub1Sub2 sub1sub2 = (BaseSub1Sub2) list.get(0);
+        assertEquals(4, sub1sub2.getBaseField());
+        assertEquals(5, sub1sub2.getBaseSub1Field());
+        assertEquals(6, sub1sub2.getBaseSub1Sub2Field());
+        pm.close();
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+    }
+
+    public void testEagerLeafList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("baseSub1Sub2List");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(2, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        List list = rel.getBaseSub1Sub2List();
+        assertEquals(1, list.size());
+        BaseSub1Sub2 sub1sub2 = (BaseSub1Sub2) list.get(0);
+        assertEquals(4, sub1sub2.getBaseField());
+        assertEquals(5, sub1sub2.getBaseSub1Field());
+        assertEquals(6, sub1sub2.getBaseSub1Sub2Field());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testMidList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+
+        List list = rel.getBaseSub1List();
+        assertEquals(2, list.size());
+        BaseSub1 sub1 = (BaseSub1) list.get(0);
+        assertEquals(2, sub1.getBaseField());
+        assertEquals(3, sub1.getBaseSub1Field());
+        assertEquals(BaseSub1.class, sub1.getClass());
+        BaseSub1Sub2 sub1sub2 = (BaseSub1Sub2) list.get(1);
+        assertEquals(4, sub1sub2.getBaseField());
+        assertEquals(5, sub1sub2.getBaseSub1Field());
+        assertEquals(6, sub1sub2.getBaseSub1Sub2Field());
+        pm.close();
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }
+
+    public void testEagerMidList()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getFetchPlan().addFetchGroup("baseSub1List");
+        Relations rel = (Relations) pm.getObjectId(_oid);
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+        sql.clear();
+
+        List list = rel.getBaseSub1List();
+        assertEquals(2, list.size());
+        BaseSub1 sub1 = (BaseSub1) list.get(0);
+        assertEquals(2, sub1.getBaseField());
+        assertEquals(3, sub1.getBaseSub1Field());
+        assertEquals(BaseSub1.class, sub1.getClass());
+        BaseSub1Sub2 sub1sub2 = (BaseSub1Sub2) list.get(1);
+        assertEquals(4, sub1sub2.getBaseField());
+        assertEquals(5, sub1sub2.getBaseSub1Field());
+        assertEquals(6, sub1sub2.getBaseSub1Sub2Field());
+        pm.close();
+
+        assertEquals(0, sql.size());
+    }
+
+    public void testProjections()
+        throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createNativeQuery("",Relations.class);
+        //FIXME jthomas
+        /*
+        q.setResult("base, baseSub1, baseSub1Sub2");
+        q.setUnique(true);
+        Object[] res = (Object[]) q.execute();
+         */
+        Object[] res=null;
+        assertNotNull(res);
+        assertEquals(3, res.length);
+
+        BaseSub2 sub2 = (BaseSub2) res[0];
+        assertEquals(3, sub2.getBaseField());
+        assertEquals(4, sub2.getBaseSub2Field());
+        assertEquals(BaseSub2.class, sub2.getClass());
+
+        BaseSub1 sub1 = (BaseSub1) res[1];
+        assertEquals(2, sub1.getBaseField());
+        assertEquals(3, sub1.getBaseSub1Field());
+        assertEquals(BaseSub1.class, sub1.getClass());
+
+        BaseSub1Sub2 sub1sub2 = (BaseSub1Sub2) res[2];
+        assertEquals(4, sub1sub2.getBaseField());
+        assertEquals(5, sub1sub2.getBaseSub1Field());
+        assertEquals(6, sub1sub2.getBaseSub1Sub2Field());
+        pm.close();
+
+        assertEquals(1, sql.size());
+        assertSQL(_outer);
+    }    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/JDBCTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/JDBCTestCase.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/JDBCTestCase.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/JDBCTestCase.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,78 @@
+/*
+ * JDBCTestCase.java
+ *
+ * Created on October 6, 2006, 10:34 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.query;
+
+import java.util.*;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+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.meta.strats.VerticalClassStrategy;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+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 abstract class JDBCTestCase extends AbstractTestCase {
+    
+    /** Creates a new instance of JDBCTestCase */
+    public JDBCTestCase() {
+    }
+    
+    
+    public JDBCTestCase(String name) {
+        super(name);
+    }
+    
+    public Class getDefaultInheritanceStrategy() {
+        return getClassMapping(RuntimeTest2.class).getStrategy().getClass();
+    }
+    
+    public ClassMapping getClassMapping(Class c) {
+        OpenJPAConfiguration jdoConf = getConfiguration();
+        return ((JDBCConfiguration) jdoConf).getMappingRepositoryInstance().
+                getMapping(c, getClass().getClassLoader(), true);
+    }
+    
+    public FieldMapping getFieldMapping(Class c, String field) {
+        return getClassMapping(c).getFieldMapping(field);
+    }
+    
+    public boolean isInheritanceStrategyVertical() {
+        return VerticalClassStrategy.class.
+                isAssignableFrom(getDefaultInheritanceStrategy());
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestEJBQLSelectNPlusOne.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestEJBQLSelectNPlusOne.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestEJBQLSelectNPlusOne.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestEJBQLSelectNPlusOne.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.query;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import junit.framework.*;
+
+public class TestEJBQLSelectNPlusOne extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{
+	public TestEJBQLSelectNPlusOne(String name)
+	{
+		super(name);
+	}
+
+	public void setUp()
+	{
+		deleteAll (RuntimeTest1.class);
+		EntityManager pm = currentEntityManager();
+		pm.getTransaction ().begin ();
+		pm.persist(new RuntimeTest1("foo", 3));
+		endTx(pm);
+		endEm(pm);
+	}
+
+	public void testSimpleEJBQLQuery() throws Exception
+	{
+		EntityManager pm = currentEntityManager();
+		// run a JDOQL query first to take care of any class-loading issues
+		List l = pm.createQuery("select object(o) from " + RuntimeTest1.class.getSimpleName()+" o").getResultList();
+
+		// now run the actual test.
+		assertEquals(1, l.size());
+		endEm(pm);
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNamedSQLQueries.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNamedSQLQueries.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNamedSQLQueries.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestNamedSQLQueries.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,110 @@
+/*
+ * TestNamedSQLQueries.java
+ *
+ * Created on October 5, 2006, 5:26 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.query;
+
+import java.util.*;
+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;
+
+
+public class TestNamedSQLQueries extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+     
+    
+    /** Creates a new instance of TestNamedSQLQueries */
+    public TestNamedSQLQueries() {
+    }
+    
+    public TestNamedSQLQueries(String test) {
+        super(test);
+    }
+
+    public void setUp() {
+       deleteAll(NamedSQL.class);
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        NamedSQL pc;
+        for (int i = 0; i < 10; i++) {
+            pc = new NamedSQL();
+            if (i < 5)
+                pc.setNum(4);
+            else
+                pc.setNum(i + 10);
+            pm.persist(pc);
+        }
+        endTx(pm);;
+        pm.close();
+    }
+
+    public void testNamedQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createNativeQuery("cls",NamedSQL.class);
+
+        assertEquals("javax.jdo.query.SQL", ((OpenJPAQuery) q).getLanguage());
+        Collection results = (Collection) q.getCandidateCollection();
+        for (Iterator i = results.iterator(); i.hasNext();)
+            assertEquals(4, ((NamedSQL) i.next()).getNum());
+        assertEquals(5, results.size());
+        q.closeAll();
+        pm.close();
+    }
+
+    public void testSystem() {
+        // test top-level package.jdoquery
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        //FIXME jthomas
+        /*
+        OpenJPAQuery query = pm.newNamedQuery(null, "system2");
+        query.setUnique(true);
+        query.setResultClass(int.class);
+        Integer count = (Integer) query.execute();
+        assertEquals(20, count.intValue());
+        query.closeAll();
+
+        // test sql query in local package.jdoquery
+        query = pm.newNamedQuery(NamedSQL.class, "cls");
+        query.closeAll(); // force parsing of package query file
+        query = pm.newNamedQuery(null, "system");
+        query.setUnique(true);
+        query.setResultClass(int.class);
+        count = (Integer) query.execute();
+        assertEquals(20, count.intValue());
+        query.closeAll();
+        pm.close();
+         */
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestSQLQueries.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestSQLQueries.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestSQLQueries.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestSQLQueries.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,464 @@
+/*
+ * TestSQLQueries.java
+ *
+ * Created on October 5, 2006, 4:59 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.query;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.MappingRepository;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+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.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+
+public class TestSQLQueries extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+     
+    
+    /** Creates a new instance of TestSQLQueries */
+    public TestSQLQueries(String name) 
+    {
+    	super(name);
+    }
+    
+    public TestSQLQueries() 
+    {}
+    
+    private String _tableName = null;
+    private String _fullTableName = null;
+    private String _pkColName = null;
+    private String _intColName = null;
+    private String _stringColName = null;
+    private String _relColName = null;
+    
+    public void setUp() {
+       deleteAll(RuntimeTest1.class);
+        
+        RuntimeTest1 pc1 = new RuntimeTest1("1", 1);
+        RuntimeTest1 pc2 = new RuntimeTest1("2", 2);
+        pc1.setSelfOneOne(pc2);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        pm.persist(pc1);
+        endTx(pm);;
+        
+        JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactorySPI) pm).getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        MappingRepository repos = conf.getMappingRepositoryInstance();
+        ClassMapping mapping = repos.getMapping(RuntimeTest1.class,
+                pm.getClassLoader(), true);
+        
+        _tableName = mapping.getTable().getName();
+        _fullTableName = dict.getFullName(mapping.getTable(), false);
+        _pkColName = mapping.getTable().getPrimaryKey().
+                getColumns()[0].getName();
+        _intColName = mapping.getFieldMapping("intField").
+                getColumns()[0].getName();
+        _stringColName = mapping.getFieldMapping("stringField").
+                getColumns()[0].getName();
+        _relColName = mapping.getFieldMapping("selfOneOne").
+                getColumns()[0].getName();
+        
+        pm.close();
+    }
+    
+    public void testStarQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select * from " + _fullTableName + " order by " + _intColName);
+        q.setResultClass(RuntimeTest1.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("1", ((RuntimeTest1) itr.next()).getStringField());
+        assertTrue(itr.hasNext());
+        assertEquals("2", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testCompiledQuery()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select * from " + _fullTableName + " order by " + _intColName);
+        q.setResultClass(RuntimeTest1.class);
+        
+        //FIXME jthomas
+        //q = pm.createQuery(roundtrips(q, false));
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("1", ((RuntimeTest1) itr.next()).getStringField());
+        assertTrue(itr.hasNext());
+        assertEquals("2", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testCompiledLanguageQuery()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select * from " + _fullTableName + " order by " + _intColName);
+        q.setResultClass(RuntimeTest1.class);
+        
+        //FIXME jthomas
+        //q = pm.createQuery("javax.jdo.query.SQL", roundtrips(q, false));
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("1", ((RuntimeTest1) itr.next()).getStringField());
+        assertTrue(itr.hasNext());
+        assertEquals("2", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testTableStarQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select " + _tableName + ".* from " + _fullTableName + " order by "
+                + _intColName);
+        q.setResultClass(RuntimeTest1.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("1", ((RuntimeTest1) itr.next()).getStringField());
+        assertTrue(itr.hasNext());
+        assertEquals("2", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testColumnQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select " + _pkColName + ", " + _intColName + ", " + _stringColName
+                + " from " + _fullTableName + " order by " + _intColName);
+        q.setResultClass(RuntimeTest1.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("1", ((RuntimeTest1) itr.next()).getStringField());
+        assertTrue(itr.hasNext());
+        assertEquals("2", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testJoinQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select t0.* from " + _fullTableName + " t0, "
+                + _fullTableName + " t1 where t0." + _relColName + " = t1."
+                + _pkColName + " and t1." + _intColName + " = 2");
+        q.setResultClass(RuntimeTest1.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("1", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testParameters() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select * from " + _fullTableName + " where 'foo' = ? and "
+                + _intColName + " = ?");
+        q.setResultClass(RuntimeTest1.class);
+        //FIXME jthomas
+        /*Iterator itr = ((Collection) q.execute("foo", new Integer(2))).
+                iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("2", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+         */
+        q.closeAll();
+        
+        Map params = new HashMap();
+        params.put(new Integer(1), "foo");
+        params.put(new Integer(2), new Integer(2));
+        //FIXME jthomas
+        /*itr = ((Collection) q.executeWithMap(params)).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("2", ((RuntimeTest1) itr.next()).getStringField());
+        assertFalse(itr.hasNext());
+         */
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testOnlySelectedFieldsLoaded() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select " + _pkColName + ", " + _intColName + ", " + _stringColName
+                + " from " + _fullTableName + " order by " + _intColName);
+        q.setResultClass(RuntimeTest1.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        RuntimeTest1 pc = (RuntimeTest1) itr.next();
+        OpenJPAStateManager sm = getStateManager(pc, pm);
+        assertTrue(sm.getLoaded().get(sm.getMetaData().
+                getField("intField").getIndex()));
+        assertTrue(sm.getLoaded().get(sm.getMetaData().
+                getField("stringField").getIndex()));
+        assertFalse(sm.getLoaded().get(sm.getMetaData().
+                getField("longField").getIndex()));
+        assertEquals("1", pc.getStringField());
+        assertFalse(sm.getLoaded().get(sm.getMetaData().
+                getField("longField").getIndex()));
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testSingleColumnClasslessQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select " + _stringColName + " from " + _fullTableName
+                + " order by " + _stringColName);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        assertEquals("1", itr.next());
+        assertTrue(itr.hasNext());
+        assertEquals("2", itr.next());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        
+        q.setResultClass(Object[].class);
+        itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        Object[] vals = (Object[]) itr.next();
+        assertEquals(1, vals.length);
+        assertEquals("1", vals[0]);
+        assertTrue(itr.hasNext());
+        vals = (Object[]) itr.next();
+        assertEquals(1, vals.length);
+        assertEquals("2", vals[0]);
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        
+        pm.close();
+    }
+    
+    public void testMultiColumnClasslessQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select " + _intColName + ", " + _stringColName + " from "
+                + _fullTableName + " order by " + _stringColName);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        Object[] vals = (Object[]) itr.next();
+        assertEquals(2, vals.length);
+        assertEquals(1, ((Number) vals[0]).intValue());
+        assertEquals("1", vals[1]);
+        assertTrue(itr.hasNext());
+        vals = (Object[]) itr.next();
+        assertEquals(2, vals.length);
+        assertEquals(2, ((Number) vals[0]).intValue());
+        assertEquals("2", vals[1]);
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testResultClass() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select * from " + _fullTableName + " order by " + _intColName);
+        q.setResultClass(RuntimeTest1.class);
+        q.setResultClass(Holder.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        Holder holder = (Holder) itr.next();
+        assertEquals(0, holder.I);
+        assertNull(holder.S);
+        assertNotNull(holder.pc);
+        assertEquals("1", holder.pc.getStringField());
+        assertTrue(itr.hasNext());
+        holder = (Holder) itr.next();
+        assertEquals(0, holder.I);
+        assertNull(holder.S);
+        assertNotNull(holder.pc);
+        assertEquals("2", holder.pc.getStringField());
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    public void testClasslessProjection() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select " + _intColName + " as I, " + _stringColName + " as S from "
+                + _fullTableName + " order by " + _intColName);
+        q.setResultClass(Holder.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        Holder holder = (Holder) itr.next();
+        assertNull(holder.pc);
+        assertEquals(1, holder.I);
+        assertEquals("1", holder.S);
+        assertTrue(itr.hasNext());
+        holder = (Holder) itr.next();
+        assertNull(holder.pc);
+        assertEquals(2, holder.I);
+        assertEquals("2", holder.S);
+        assertFalse(itr.hasNext());
+        q.closeAll();
+        pm.close();
+    }
+    
+    /**
+     * Manual test to see if a relation will be eagerly loaded when SQL
+     * containing enough information is run. This is not run as part of
+     * the unit tests since we don't know if this behavior should be
+     * really expected to work or not.
+     */
+    public void relationLoadedTest() {
+       deleteAll(AttachD.class);
+       deleteAll(AttachA.class);
+        
+        AttachD d = new AttachD();
+        AttachA a = new AttachA();
+        d.setA(a);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getTransaction().begin();
+        pm.persist(d);
+        pm.getTransaction().commit();
+        pm.close();
+        
+        JDBCConfiguration conf = (JDBCConfiguration) ((OpenJPAEntityManagerFactorySPI) pm).getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        MappingRepository repos = conf.getMappingRepositoryInstance();
+        
+        ClassMapping mappingA = repos.getMapping(AttachD.class,
+                pm.getClassLoader(), true);
+        String tableNameA = mappingA.getTable().getName();
+        String fullTableNameA = dict.getFullName(mappingA.getTable(), false);
+        String relColNameA = mappingA.getFieldMapping("a").
+                getColumns()[0].getName();
+        
+        ClassMapping mappingD = repos.getMapping(AttachA.class,
+                pm.getClassLoader(), true);
+        String tableNameD = mappingD.getTable().getName();
+        String fullTableNameD = dict.getFullName(mappingD.getTable(), false);
+        String pkColNameD = mappingD.getTable().getPrimaryKey().
+                getColumns()[0].getName();
+        
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createQuery("javax.jdo.query.SQL",
+                "select t0.*, t1.* from "
+                + fullTableNameA + " t0, "
+                + fullTableNameD + " t1 "
+                + "where t0." + relColNameA + " = t1." + pkColNameD);
+        
+        // even the exact same SQL that Kodo generates will not
+        // eagerly load the relation
+        /*
+          q = pm.newQuery ("javax.jdo.query.SQL",
+              "SELECT t1.ID, t1.TYP, t1.VERSN, t1.ADBL, t1.AINT, "
+              + "t1.ASTR, t1.BDBL, t1.BINT, t1.BSTR, t1.CDBL, t1.CINT, "
+              + "t1.CSTR, t0.DDBL, t0.DINT, t0.DSTR "
+              + "FROM ATTACHD t0 LEFT OUTER JOIN ATTACHA t1 ON t0.A = t1.ID");
+         */
+        
+        q.setResultClass(AttachD.class);
+        Iterator itr = ((Collection) q.getCandidateCollection()).iterator();
+        assertTrue(itr.hasNext());
+        
+        d = (AttachD) itr.next();
+        // d.getDstr ();
+        
+        OpenJPAStateManager sm = getStateManager(d, pm);
+        assertTrue(sm.getLoaded().
+                get(sm.getMetaData().getField("a").getIndex()));
+        assertNotNull(d.getA());
+        assertFalse(itr.hasNext());
+        
+        q.closeAll();
+        pm.close();
+    }
+    
+    public static class Holder {
+        
+        public RuntimeTest1 pc;
+        public int I;
+        public String S;
+        
+        public void setRuntimeTest1(RuntimeTest1 pc) {
+            this.pc = pc;
+        }
+    }
+    
+    public static void main(String[] args)
+    throws Exception {
+        // main ();
+        
+        new TestSQLQueries().relationLoadedTest();
+    }
+    
+    private static Object roundtrips(Object orig, boolean validateEquality)
+    throws IOException, ClassNotFoundException {
+        assertNotNull(orig);
+        
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream(bout);
+        out.writeObject(orig);
+        ByteArrayInputStream bin = new ByteArrayInputStream(
+                bout.toByteArray());
+        ObjectInputStream in = new ObjectInputStream(bin);
+        Object result = in.readObject();
+        
+        if (validateEquality) {
+            assertEquals(orig.hashCode(), result.hashCode());
+            assertEquals(orig, result);
+        }
+        
+        return result;
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestStringFunctions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestStringFunctions.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestStringFunctions.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/query/TestStringFunctions.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,125 @@
+/*
+ * TestStringFunctions.java
+ *
+ * Created on October 5, 2006, 5:20 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.query;
+
+import java.util.*;
+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;
+
+
+public class TestStringFunctions extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{
+    private OpenJPAEntityManager _pm = null;
+    private QueryTest1 _match = null;
+    
+    /** Creates a new instance of TestStringFunctions */
+    public TestStringFunctions(String name) 
+    {
+    	super(name);
+    }
+    
+    public void setUp() {
+       deleteAll(QueryTest1.class);
+
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getTransaction().begin();
+        QueryTest1 match = new QueryTest1();
+        match.setString("foobarbiz");
+        pm.persist(match);
+        QueryTest1 fail = new QueryTest1();
+        fail.setString("barbizraz");
+        pm.persist(fail);
+        pm.getTransaction().commit();
+        Object oid = pm.getObjectId(match);
+        pm.close();
+
+        _pm = (OpenJPAEntityManager)currentEntityManager();
+        _match = (QueryTest1) _pm.getObjectId(oid);
+    }
+
+    public void tearDown()
+        throws Exception {
+        if (_pm != null)
+            _pm.close();
+
+        super.tearDown();
+    }
+
+    public void testSubstring() {
+        assertMatch("string.substring (3) == 'barbiz'");
+        assertMatch("string.substring (3, 6) == 'bar'");
+    }
+
+    public void testIndexOf() {
+        assertMatch("string.indexOf ('bar') == 3");
+        assertMatch("string.indexOf (\"b\", 4) == 6");
+        assertMatch("string.indexOf ('b', 4) == 6");
+    }
+
+    public void testToLowerCase() {
+        assertMatch("string.toLowerCase () == 'foobarbiz'");
+        assertMatch("'FOOBARBIZ'.toLowerCase () == string");
+    }
+
+    public void testToUpperCase() {
+        assertMatch("string.toUpperCase () == 'FOOBARBIZ'");
+    }
+
+    public void testStartsWith() {
+        assertMatch("string.startsWith ('foobar')");
+        assertMatch("'foobarbizbaz'.startsWith (string)");
+    }
+
+    public void testEndsWith() {
+        assertMatch("string.endsWith ('barbiz')");
+        assertMatch("'bazfoobarbiz'.endsWith (string)");
+    }
+
+    public void testMatches() {
+        assertMatch("string.matches ('.oobar.*')");
+        assertMatch("string.matches ('FOO.AR.IZ(?i)')");
+    }
+
+    private void assertMatch(String filter) {
+        OpenJPAQuery q = _pm.createNativeQuery(filter,QueryTest1.class);
+        Collection res = (Collection) q.getCandidateCollection();
+        assertEquals(1, res.size());
+        assertEquals(_match, res.iterator().next());
+        q.closeAll();
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassDBSequenceFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassDBSequenceFactory.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassDBSequenceFactory.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassDBSequenceFactory.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,237 @@
+/*
+ * TestClassDBSequenceFactory.java
+ *
+ * Created on October 6, 2006, 11:29 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.schema;
+
+import java.util.*;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.schema.Sequence;
+import org.apache.openjpa.kernel.Broker;
+
+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 TestClassDBSequenceFactory extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+    
+    
+    /** Creates a new instance of TestClassDBSequenceFactory */
+    public TestClassDBSequenceFactory() {
+    }
+    
+    public TestClassDBSequenceFactory(String test) {
+        super(test);
+    }
+    
+    public void setUp() {
+       deleteAll(SeqE.class);
+    }
+    
+    boolean supportsPessimisticLocking() {
+        OpenJPAConfiguration conf = getConfiguration();
+        return conf instanceof JDBCConfiguration
+                && ((JDBCConfiguration) conf).getDBDictionaryInstance().
+                supportsSelectForUpdate;
+    }
+    
+    public void testVirtualSuperclass() {
+        
+        OpenJPAEntityManagerFactory pmf =(OpenJPAEntityManagerFactory)
+                getEmf(getProps());
+        OpenJPAEntityManager pm = (OpenJPAEntityManager) pmf.createEntityManager();
+        //FIXME jthomas
+        //Sequence gen = pm.getIdentitySequence(SeqF.class);
+        Sequence gen=null;
+        long next = ((Number) gen.getIncrement()).longValue();
+        //FIXME jthomas
+        //gen = pm.getIdentitySequence(SeqG.class);
+        assertEquals(next + 1, ((Number) gen.getIncrement()).longValue());
+        pm.close();
+        pmf.close();
+    }
+    
+    public void testIgnoreVirtualSuperclass() {
+        
+        Map props=new HashMap();
+        props.put("TableName", "JDO_CLASS_SEQUENCE");
+        props.put("IgnoreVirtual", "true");
+        OpenJPAEntityManagerFactory pmf =(OpenJPAEntityManagerFactory)
+                getEmf(props);
+        OpenJPAEntityManager pm = pmf.createEntityManager();
+        //FIXME jthomas
+        //Sequence gen = pm.getIdentitySequence(SeqF.class);
+        Sequence gen =null;
+        long next = ((Number) gen.getIncrement()).longValue();
+        //FIXME jthomas
+        //Sequence gen2 = pm.getIdentitySequence(SeqG.class);
+        Sequence gen2 =null;
+        long next2 = ((Number) gen2.getIncrement()).longValue();
+        if (next2 != next + 1)
+            return; // valid.
+        assertTrue(((Number) gen.getIncrement()).longValue() != next2 + 1);
+        
+        pm.close();
+        pmf.close();
+    }
+    
+    /**
+     * Based on reported bug case.
+     */
+    public void testNoSequenceHolesOnAttach() {
+        PerClassTestObject3 pc = new PerClassTestObject3();
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        pm.persist(pc);
+        endTx(pm);;
+        long id1 = pc.getId();
+        
+        pc = new PerClassTestObject3();
+        startTx(pm);;
+        pm.persist(pc);
+        long id2 = pc.getId();
+        endTx(pm);;
+        pm.close();
+        
+        pc = new PerClassTestObject3();
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        pm.persist(pc);
+        endTx(pm);;
+        long id3 = pc.getId();
+        pm.close();
+        
+        assertEquals(id1 + 1, id2);
+        assertEquals(id2 + 1, id3);
+    }
+    
+    /**
+     * Tests that all sequence numbers are unique and in order.
+     * Will fail for dbs without pessimistic locking.
+     */
+    public void testSequence()
+    throws Exception {
+        if (!(supportsPessimisticLocking()))
+            return;
+        
+        Set set = new HashSet();
+        JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
+        Broker broker = getBrokerFactory().newBroker();
+        
+        
+        UpdateThread t1 = new UpdateThread(set, broker);
+        UpdateThread t2 = new UpdateThread(set, broker);
+        
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+        
+        if (t1.error != null)
+            throw t1.error;
+        if (t2.error != null)
+            throw t2.error;
+        
+        assertEquals(102, set.size());
+    }
+    
+    public void testSequenceGenerator() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        
+        // make sure the sequence generator creates separate
+        // instances.
+        for (int i = 0; i < 100; i++) {
+            //FIXME jthomas
+            /*assertEquals(((Number) pm.getIdentitySequence(SeqD.class).
+                    next()).longValue() + 1,
+                    ((Number) pm.getIdentitySequence(SeqD.class).
+                    getIncrement()).longValue());
+             
+             */
+        }
+        // make sure the sequence generate is not the same as is
+        // used elsewhere
+        
+        for (int j = 0; j < 100; j++) {
+            //FIXME
+            /*
+            assertNotEquals(new Long(((Number) pm.getIdentitySequence
+                    (SeqA.class).getIncrement()).longValue() + 1),
+                    pm.getIdentitySequence(SeqD.class).next());
+             */
+        }
+    }
+    
+    public static void main(String[] args) {
+        //main();
+    }
+    private Map getProps() {
+        Map props=new HashMap();
+        props.put("openjpa.Sequence", "db-class(TableName=JDO_CLASS_SEQUENCE");
+        return props;
+    }
+    
+    
+    
+    private static class UpdateThread
+            extends Thread {
+        
+        private Set _set = null;
+        private Broker _broker = null;
+        public Exception error = null;
+        
+        public UpdateThread(Set set, Broker broker) {
+            _set = set;
+            _broker = broker;
+        }
+        
+        public void run() {
+            try {
+                ClassMapping mapping =
+                        ((JDBCConfiguration) _broker.getConfiguration()).
+                        getMappingRepositoryInstance().
+                        getMapping(SeqD.class, null, true);
+                ClassTableJDBCSeq seq = (ClassTableJDBCSeq)
+                _broker.getIdentitySequence(mapping);
+                for (int i = 0; i < 51; i++)
+                    _set.add(seq.next(_broker, mapping));
+            } catch (Exception e) {
+                error = e;
+            }
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassSequenceFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassSequenceFactory.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassSequenceFactory.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestClassSequenceFactory.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,208 @@
+/*
+ * TestClassSequenceFactory.java
+ *
+ * Created on October 6, 2006, 12:21 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.jdbc.schema;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.*;
+import javax.sql.DataSource;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.kernel.Seq;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.lib.conf.Configurations;
+
+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.kernel.BaseJDBCTest;
+
+
+public class TestClassSequenceFactory extends BaseJDBCTest{
+    
+
+    private static Map _sysprops = new HashMap();
+    
+    Broker _broker;
+    
+    /** Creates a new instance of TestClassSequenceFactory */
+    public TestClassSequenceFactory() {
+    }
+    public TestClassSequenceFactory(String test) {
+        super(test);
+    }
+    
+    public void setUp()
+    throws Exception {
+        JDBCConfiguration conf = new JDBCConfigurationImpl();
+        conf.fromProperties(getProperties());
+        if (!adjustConfiguration(conf))
+            return;
+        
+        String driver = conf.getConnectionDriverName().toLowerCase();
+        String [] sql = null;
+        
+        if (driver.indexOf("oracle") >= 0) {
+            sql = new String []{
+                "create sequence seqa_seq",
+                "create sequence seqb_seq"
+            };
+        }
+        
+        if (sql == null)
+            return;
+        
+        DataSource ds = conf.getDataSource2(null);
+        Connection c = ds.getConnection();
+        Statement s = null;
+        try {
+            s = c.createStatement();
+            for (int i = 0; i < sql.length; i++) {
+                try {
+                    s.execute(sql[i]);
+                } catch (SQLException sqe) {
+                }
+            }
+        } finally {
+            if (s != null)
+                try {
+                    s.close();
+                } catch (Exception e) {
+                }
+        }
+        
+        _broker = getBrokerFactory().newBroker();
+    }
+    
+    /**
+     * Tests that all sequence numbers are unique and in order.
+     */
+    public void testSequence()
+    throws Exception {
+        Set set = new HashSet();
+        
+        JDBCConfiguration conf = new JDBCConfigurationImpl();
+        conf.fromProperties(getProperties());
+        if (!adjustConfiguration(conf))
+            return;
+        Thread t1 = new UpdateThread(set, conf);
+        Thread t2 = new UpdateThread(set, conf);
+        
+        t1.start();
+        t2.start();
+        t1.join();
+        t2.join();
+        
+        assertEquals(102, set.size());
+    }
+    
+    public void testExtensions()
+    throws Exception {
+        JDBCConfiguration conf = new JDBCConfigurationImpl();
+        conf.fromProperties(getProperties());
+        if (!adjustConfiguration(conf))
+            return;
+        
+        ClassMapping aMapping = conf.getMappingRepositoryInstance().
+                getMapping(SeqA.class, null, true);
+        ClassMapping bMapping = conf.getMappingRepositoryInstance().
+                getMapping(SeqB.class, null, true);
+        ClassMapping cMapping = conf.getMappingRepositoryInstance().
+                getMapping(SeqC.class, null, true);
+        DataSource ds = conf.getDataSource2(null);
+        
+        // hold a and c and start b
+        
+        Seq seq = conf.getSequenceInstance();
+        long aid = ((Long) seq.next(_broker, aMapping)).longValue();
+        for (int i = 0; i < 5; i++)
+            seq.next(_broker, bMapping);
+        
+        assertEquals(new Long(aid + 1), seq.next(_broker, aMapping));
+        assertEquals(new Long(aid + 2), seq.next(_broker, cMapping));
+    }
+    
+    /**
+     * Pass in a mutable configuration
+     * <p/>
+     * return true if useable.
+     */
+    private boolean adjustConfiguration(JDBCConfiguration conf) {
+        String driver = conf.getConnectionDriverName();
+        if (driver == null)
+            return false;
+        driver = driver.toLowerCase();
+        if (driver.indexOf("oracle") >= 0) {
+            conf.setSequence(ClassTableJDBCSeq.class.getName());
+            return true;
+        }
+        
+        return false;
+    }
+    
+    public static void main(String[] args) {
+//        main();
+    }
+    
+    
+    private class UpdateThread
+            extends Thread {
+        
+        private JDBCConfiguration _conf;
+        private Set _set = null;
+        
+        public UpdateThread(Set set, JDBCConfiguration conf) {
+            _set = set;
+            _conf = conf;
+        }
+        
+        public void run() {
+            DataSource ds = _conf.getDataSource2(null);
+            try {
+                Seq seq = _conf.getSequenceInstance();
+                ClassMapping mapping = _conf.getMappingRepositoryInstance().
+                        getMapping(SeqA.class, null, true);
+                for (int i = 0; i < 51; i++)
+                    _set.add(seq.next(_broker, mapping));
+            } catch (Exception e) {
+                throw new RuntimeException(e.getMessage());
+            }
+        }
+    }
+    
+}



Mime
View raw message