openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r757670 [2/2] - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps: m2mmapex0/ m2mmapex1/ m2mmapex10/ m2mmapex2/ m2mmapex3/ m2mmapex4/ m2mmapex5/ m2mmapex6/ m2mmapex7/ m2mmapex8/ m2mmapex9/ spe...
Date Tue, 24 Mar 2009 05:55:15 GMT
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex2/TestSpec10_1_26_Ex2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex2/TestSpec10_1_26_Ex2.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex2/TestSpec10_1_26_Ex2.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex2/TestSpec10_1_26_Ex2.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_26_ex2;
 
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -31,57 +30,78 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_26_Ex2 extends SingleEMFTestCase {
+public class TestSpec10_1_26_Ex2 extends SQLListenerTestCase {
     public int numDepartments = 2;
     public int numEmployeesPerDept = 2;
-    public List<String> namedQueries = new ArrayList<String>();
-
     public int deptId = 1;
     public int empId = 1;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllDepartments = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Department.class,
             Employee.class,
-            EmployeePK.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { 
-            this.new Listener() 
-        });
+            EmployeePK.class);
         createObj(emf);
+        rsAllDepartments = getAll(Department.class);
+    }
+
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
+    public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Department.class)
+            qi.setCandidateCollection(rsAllDepartments);
     }
 
-    public void testQualifiedId() throws Exception {
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e), KEY(e).name from Department d, " +
             " in (d.empMap) e where d.deptId = 1";
-        List rs = em.createQuery(query).getResultList(); 
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        List rs = q.getResultList();
         EmployeePK d = (EmployeePK) ((Object[]) rs.get(0))[0];
         String name = (String) ((Object[]) rs.get(0))[1];
         assertEquals(d.getName(), name);
 
         em.clear();
-        String query4 = "select ENTRY(e) from Department d, " +
+        query = "select ENTRY(e) from Department d, " +
             " in (d.empMap) e  where d.deptId = 1";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
         // test GROUP BY qualified path
         sql.clear();
-        String query5 = "select count(KEY(e).bDay) from Department d " +
+        query = "select count(KEY(e).bDay) from Department d " +
             " left join d.empMap e GROUP BY KEY(e).bDay";
-        List rs5 = em.createQuery(query5).getResultList();
-        assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        rs = q.getResultList();
+        if (!inMemory)
+            assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
 
         em.close();
     }
@@ -90,14 +110,6 @@
         queryObj(emf);
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj(EntityManagerFactory emf) {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -222,14 +234,4 @@
         EmployeePK pk = e.getEmpPK();
         Department d = e.getDepartment();
     }
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java Tue Mar 24 05:55:13 2009
@@ -30,12 +30,11 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_26_Ex3 extends SingleEMFTestCase {
+public class TestSpec10_1_26_Ex3 extends SQLListenerTestCase {
 
     public int numDepartments = 2;
     public int numEmployeesPerDept = 2;
@@ -43,41 +42,64 @@
     
     public int deptId = 1;
     public int empId = 1;
+    public List rsAllDepartments = null;
     
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
-
     public void setUp() {
         super.setUp(DROP_TABLES,
             Department.class,
             Employee.class,
-            EmployeeName.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { 
-            this.new Listener() 
-        });
+            EmployeeName.class);
         createObj(emf);
+        rsAllDepartments = getAll(Department.class);
+    }
+
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
+    public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Department.class)
+            qi.setCandidateCollection(rsAllDepartments);
     }
 
-    public void testQualifiedId() throws Exception {
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from Department d, " +
             " in (d.emps) e order by d.deptId, e.empId";
-        List rs = em.createQuery(query).getResultList(); 
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        List rs = q.getResultList();
         EmployeeName d = (EmployeeName) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from Department d, " +
+        query = "select ENTRY(e) from Department d, " +
             " in (d.emps) e order by d.deptId, e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
         
         // test ORDER BY qualified path
         query = "select KEY(e), KEY(e).fName from Department d, " +
             " in (d.emps) e order by KEY(e).fName";
-        rs = em.createQuery(query).getResultList(); 
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        rs = q.getResultList();
         d = (EmployeeName) ((Object[]) rs.get(0))[0];
         String fname = (String) ((Object[]) rs.get(0))[1];
 
@@ -87,8 +109,12 @@
         sql.clear();
         query = "select COUNT(KEY(e).fName) from Department d " +
             " left join d.emps e GROUP BY KEY(e).fName";
-        rs = em.createQuery(query).getResultList(); 
-        assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        rs = q.getResultList();
+        if (!inMemory)
+            assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
 
         em.close();
     }
@@ -97,14 +123,6 @@
         queryObj(emf);
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj(EntityManagerFactory emf) {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -225,15 +243,5 @@
         Department d = e.getDepartment();
         assertDepartment(d);
     }
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_27_ex0;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -29,12 +28,11 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_27 extends SingleEMFTestCase {
+public class TestSpec10_1_27 extends SQLListenerTestCase {
     public int numItems = 2;
     public int numImagesPerItem = 3;
     public int numCompany = 2;
@@ -43,47 +41,78 @@
     public int compId = 1;
     public int divId = 1;
     public int vpId = 1;
-
-    public List<String> namedQueries = new ArrayList<String>();
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllCompny1 = null;
+    public List rsAllCompny2 = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
                 Compny1.class, Compny2.class,
                 Item1.class, Item2.class,
-                Division.class, VicePresident.class,
-                "openjpa.jdbc.JDBCListeners", 
-                new JDBCListener[] { this.new Listener() });
+                Division.class, VicePresident.class);
         createObj(emf);
+        rsAllCompny1 = getAll(Compny1.class);
+        rsAllCompny2 = getAll(Compny2.class);
     }
 
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
     public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Compny1.class)
+            qi.setCandidateCollection(rsAllCompny1);
+        else if (clz == Compny2.class)
+            qi.setCandidateCollection(rsAllCompny2);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         String query = "select KEY(e) from Compny1 c, " +
             " in (c.orgs) e order by c.id";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Compny1.class);
+        List rs = q.getResultList();
         Division d = (Division) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from Compny1 c, " +
+        query = "select ENTRY(e) from Compny1 c, " +
         " in (c.orgs) e order by c.id";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Compny1.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
         query = "select KEY(e) from Compny2 c, " +
             " in (c.orgs) e order by c.id";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Compny2.class);
+        rs = q.getResultList();
         d = (Division) rs.get(0);
 
         em.clear();
-        query4 = "select ENTRY(e) from Compny2 c, " +
+        query = "select ENTRY(e) from Compny2 c, " +
             " in (c.orgs) e order by c.id";
-        rs4 = em.createQuery(query4).getResultList();
-        me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Compny2.class);
+        rs = q.getResultList();
+        me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -94,14 +123,6 @@
         queryObj(emf);
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj(EntityManagerFactory emf) {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -302,14 +323,4 @@
         tran.commit();
         em.close();
     }    
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }
\ No newline at end of file

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java Tue Mar 24 05:55:13 2009
@@ -30,12 +30,11 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_27_Ex3 extends SingleEMFTestCase {
+public class TestSpec10_1_27_Ex3 extends SQLListenerTestCase {
     public int numCompany = 2;
     public int numDivisionsPerCo = 2;
     public List<String> namedQueries = new ArrayList<String>();
@@ -45,65 +44,85 @@
     public int vpId = 1;
     public int newDivId = 100;
     public int newVpId = 100;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllCompany = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Company.class,
             Division.class,
-            VicePresident.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { this.new Listener() });
+            VicePresident.class);
         createObj(emf);
+        rsAllCompany = getAll(Company.class);
     }
 
     public void testQueryObj() throws Exception {
         queryObj(emf);
     }
 
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
     public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Company.class)
+            qi.setCandidateCollection(rsAllCompany);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         String query = "select KEY(e) from Company c, " +
             " in (c.orgs) e order by c.id";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        List rs = q.getResultList();
         Division d = (Division) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from Company c, " +
+        query = "select ENTRY(e) from Company c, " +
             " in (c.orgs) e order by c.id";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
         em.clear();
         query = "select KEY(e) from Company c " +
             " left join c.orgs e order by c.id";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
         d = (Division) rs.get(0);
 
         em.clear();
-        query4 = "select ENTRY(e) from Company c " +
+        query = "select ENTRY(e) from Company c " +
             " left join c.orgs e order by c.id";
-        rs4 = em.createQuery(query4).getResultList();
-        me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
         em.close();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj(EntityManagerFactory emf) {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -273,14 +292,4 @@
         tran.commit();
         em.close();
     }
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_27_ex4;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -30,80 +29,96 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_27_Ex4 extends SingleEMFTestCase {
+public class TestSpec10_1_27_Ex4 extends SQLListenerTestCase {
     public int numCompany = 2;
     public int numDivisionsPerCo = 2;
-    public List<String> namedQueries = new ArrayList<String>();
 
     public int compId = 1;
     public int divId = 1;
     public int vpId = 1;
     public int newDivId = 100;
     public int newVpId = 100;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllCompany = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Company.class,
             Division.class,
-            VicePresident.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { this.new Listener() });
+            VicePresident.class);
         createObj(emf);
+        rsAllCompany = getAll(Company.class);
     }
 
     public void testQueryObj() throws Exception {
         queryObj(emf);
     }
 
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
     public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Company.class)
+            qi.setCandidateCollection(rsAllCompany);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         String query = "select KEY(e) from Company c, " +
             " in (c.organization) e order by c.id";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        List rs = q.getResultList();
         Division d = (Division) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from Company c, " +
+        query = "select ENTRY(e) from Company c, " +
             " in (c.organization) e order by c.id";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
         assertTrue(d.equals(me.getKey()));
 
         em.clear();
         query = "select KEY(e) from Company c " +
             " left join c.organization e order by c.id";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
         d = (Division) rs.get(0);
 
         em.clear();
-        query4 = "select ENTRY(e) from Company c " +
+        query = "select ENTRY(e) from Company c " +
             " left join c.organization e order by c.id";
-        rs4 = em.createQuery(query4).getResultList();
-        me = (Map.Entry) rs4.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        me = (Map.Entry) rs.get(0);
         assertTrue(d.equals(me.getKey()));
 
         em.close();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj(EntityManagerFactory emf) {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -272,14 +287,4 @@
         tran.commit();
         em.close();
     }
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java Tue Mar 24 05:55:13 2009
@@ -30,12 +30,11 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_27_Ex5 extends SingleEMFTestCase {
+public class TestSpec10_1_27_Ex5 extends SQLListenerTestCase {
     public int numCompany = 2;
     public int numDivisionsPerCo = 2;
     public List<String> namedQueries = new ArrayList<String>();
@@ -45,65 +44,84 @@
     public int vpId = 1;
     public int newDivId = 100;
     public int newVpId = 100;
-    
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllCompany = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Company.class,
             Division.class,
-            VicePresident.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { this.new Listener() });
+            VicePresident.class);
         createObj(emf);
+        rsAllCompany = getAll(Company.class);
     }
 
     public void testQueryObj() throws Exception {
         queryObj(emf);
     }
 
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
     public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Company.class)
+            qi.setCandidateCollection(rsAllCompany);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         String query = "select KEY(e) from Company c, " +
             " in (c.orgs) e order by c.id";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        List rs = q.getResultList();
         Division d = (Division) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from Company c, " +
+        query = "select ENTRY(e) from Company c, " +
             " in (c.orgs) e order by c.id";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
         em.clear();
         query = "select KEY(e) from Company c " +
             " left join c.orgs e order by c.id";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
         d = (Division) rs.get(0);
 
         em.clear();
-        query4 = "select ENTRY(e) from Company c " +
+        query = "select ENTRY(e) from Company c " +
             " left join c.orgs e order by c.id";
-        rs4 = em.createQuery(query4).getResultList();
-        me = (Map.Entry) rs4.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        me = (Map.Entry) rs.get(0);
         assertTrue(d.equals(me.getKey()));
 
         em.close();
     }
     
-	public List<String> getSql() {
-	    return sql;
-	}
-	
-	public int getSqlCount() {
-	    return sqlCount;
-	}
-	
 	public void createObj(EntityManagerFactory emf) {
 		EntityManager em = emf.createEntityManager();
 		EntityTransaction tran = em.getTransaction();
@@ -313,15 +331,5 @@
         tran.commit();
         em.close();
     }
-	
-	public class Listener extends AbstractJDBCListener {
-	    @Override
-	    public void beforeExecuteStatement(JDBCEvent event) {
-	        if (event.getSQL() != null && sql != null) {
-	            sql.add(event.getSQL());
-	            sqlCount++;
-	        }
-	    }
-	}
 }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/TestSpec10_1_27_Ex8.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/TestSpec10_1_27_Ex8.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/TestSpec10_1_27_Ex8.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/TestSpec10_1_27_Ex8.java Tue Mar 24 05:55:13 2009
@@ -30,13 +30,12 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
 
-public class TestSpec10_1_27_Ex8 extends SingleEMFTestCase {
+public class TestSpec10_1_27_Ex8 extends SQLListenerTestCase {
     public int numCompany = 2;
     public int numDivisionsPerCo = 2;
     public List<String> namedQueries = new ArrayList<String>();
@@ -47,69 +46,87 @@
 
     public int newDivId = 100;
     public int newVpId = 100;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllCompany = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Company.class,
             FileName.class,
-            VicePresident.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { this.new Listener() });
+            VicePresident.class);
         createObj(emf);
+        rsAllCompany = getAll(Company.class);
     }
 
     public void testQueryObj() throws Exception {
         queryObj(emf);
     }
 
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
     public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Company.class)
+            qi.setCandidateCollection(rsAllCompany);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         String query = "select KEY(e), e from Company c, " +
             " in (c.orgs) e order by c.id";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        List rs = q.getResultList();
         FileName d = (FileName) ((Object[]) rs.get(0))[0];
         VicePresident v = (VicePresident) ((Object[]) rs.get(0))[1];
 
         em.clear();
-        String query4 = "select ENTRY(e) from Company c, " +
+        query = "select ENTRY(e) from Company c, " +
             " in (c.orgs) e order by c.id";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
         assertTrue(d.equals(me.getKey()));
         assertEquals(v.getId(), ((VicePresident) me.getValue()).getId());
 
         em.clear();
         query = "select KEY(e), e from Company c " +
             " left join c.orgs e order by c.id";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
         d = (FileName) ((Object[]) rs.get(0))[0];
         v = (VicePresident) ((Object[]) rs.get(0))[1];
 
         em.clear();
-        query4 = "select ENTRY(e) from Company c " +
+        query = "select ENTRY(e) from Company c " +
             " left join c.orgs e order by c.id";
-        rs4 = em.createQuery(query4).getResultList();
-        me = (Map.Entry) rs4.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        me = (Map.Entry) rs.get(0);
         assertTrue(d.equals(me.getKey()));
         assertEquals(v.getId(), ((VicePresident) me.getValue()).getId());
 
         em.close();
     }
     
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj(EntityManagerFactory emf) {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -247,15 +264,5 @@
         tran.commit();
         em.close();
     }
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/TestSpec10_1_29_Ex1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/TestSpec10_1_29_Ex1.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/TestSpec10_1_29_Ex1.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/TestSpec10_1_29_Ex1.java Tue Mar 24 05:55:13 2009
@@ -29,64 +29,92 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_29_Ex1 extends SingleEMFTestCase {
+public class TestSpec10_1_29_Ex1 extends SQLListenerTestCase {
     public int numCompany = 2;
     public int numDivisionsPerCo = 2;
-    public List<String> namedQueries = new ArrayList<String>();
+    public List rsAllCompany = null;
     
     public int compId = 1;
     public int divId = 1;
     public int vpId = 1;
+    
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Company.class,
             Division.class,
-            VicePresident.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { this.new Listener() });
+            VicePresident.class);
         createObj(emf);
+        rsAllCompany = getAll(Company.class);
     }
 
     public void testQueryObj() throws Exception {
         queryObj(emf);
     }
 
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
     public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Company.class)
+            qi.setCandidateCollection(rsAllCompany);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         String query = "select KEY(e), e from Company c, " +
             " in (c.organization) e order by c.id";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        List rs = q.getResultList();
         Division d = (Division) ((Object[]) rs.get(0))[0];
         VicePresident v = (VicePresident) ((Object[]) rs.get(0))[1];
 
         em.clear();
-        String query4 = "select ENTRY(e) from Company c, " +
+        query = "select ENTRY(e) from Company c, " +
             " in (c.organization) e order by c.id";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
         assertTrue(d.equals(me.getKey()));
         assertEquals(v.getId(), ((VicePresident) me.getValue()).getId());
 
         em.clear();
         query = "select KEY(e), e from Company c " +
             " left join c.organization e order by c.id";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
         d = (Division) ((Object[]) rs.get(0))[0];
         v = (VicePresident) ((Object[]) rs.get(0))[1];
 
         em.clear();
-        query4 = "select ENTRY(e) from Company c " +
+        query = "select ENTRY(e) from Company c " +
             " left join c.organization e order by c.id";
-        rs4 = em.createQuery(query4).getResultList();
-        me = (Map.Entry) rs4.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Company.class);
+        rs = q.getResultList();
+        me = (Map.Entry) rs.get(0);
         assertTrue(d.equals(me.getKey()));
         assertEquals(v.getId(), ((VicePresident) me.getValue()).getId());
 
@@ -217,14 +245,4 @@
         tran.commit();
         em.close();
     }
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/TestSpec10_1_29_Ex3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/TestSpec10_1_29_Ex3.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/TestSpec10_1_29_Ex3.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/TestSpec10_1_29_Ex3.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.spec_10_1_29_ex3;
 
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -29,51 +28,71 @@
 
 import junit.framework.Assert;
 
-import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
-import org.apache.openjpa.lib.jdbc.JDBCEvent;
-import org.apache.openjpa.lib.jdbc.JDBCListener;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.kernel.QueryImpl;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-public class TestSpec10_1_29_Ex3 extends SingleEMFTestCase {
+public class TestSpec10_1_29_Ex3 extends SQLListenerTestCase {
     public int numStudents = 2;
     public int numCoursesPerStudent = 2;
-    public List<String> namedQueries = new ArrayList<String>();
 
     public int studentId = 1;
     public int courseId = 1;
     public int semesterId = 1;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllStudents = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Course.class,
             Semester.class,
-            Student.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { this.new Listener() });
+            Student.class);
         createObj(emf);
+        rsAllStudents = getAll(Student.class);
     }
 
     public void testQueryObj() throws Exception {
         queryObj(emf);
     }
 
+    @AllowFailure
+    public void testQueryInMemoryQualifiedId() throws Exception {
+        queryQualifiedId(true);
+    }
+    
     public void testQueryQualifiedId() throws Exception {
+        queryQualifiedId(false);
+    }
+
+    public void setCandidate(Query q, Class clz) 
+        throws Exception {
+        org.apache.openjpa.persistence.QueryImpl q1 = 
+            (org.apache.openjpa.persistence.QueryImpl) q;
+        org.apache.openjpa.kernel.Query q2 = q1.getDelegate();
+        org.apache.openjpa.kernel.QueryImpl qi = (QueryImpl) q2;
+        if (clz == Student.class)
+            qi.setCandidateCollection(rsAllStudents);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         String query = "select KEY(e), e from Student s, " +
             " in (s.enrollment) e order by s.id";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Student.class);
+        List rs = q.getResultList();
         Course c = (Course) ((Object[]) rs.get(0))[0];
         Semester s = (Semester) ((Object[]) rs.get(0))[1];
 
         em.clear();
-        String query4 = "select ENTRY(e) from Student s, " +
+        query = "select ENTRY(e) from Student s, " +
             " in (s.enrollment) e order by s.id";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Student.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(c.equals(me.getKey()));
         assertEquals(s.getId(), ((Semester) me.getValue()).getId());
@@ -81,15 +100,21 @@
         em.clear();
         query = "select KEY(e), e from Student s " +
             " left join s.enrollment e order by s.id";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Student.class);
+        rs = q.getResultList();
         c = (Course) ((Object[]) rs.get(0))[0];
         s = (Semester) ((Object[]) rs.get(0))[1];
 
         em.clear();
-        query4 = "select ENTRY(e) from Student s " +
+        query = "select ENTRY(e) from Student s " +
             " left join s.enrollment e order by s.id";
-        rs4 = em.createQuery(query4).getResultList();
-        me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Student.class);
+        rs = q.getResultList();
+        me = (Map.Entry) rs.get(0);
 
         assertTrue(c.equals(me.getKey()));
         assertEquals(s.getId(), ((Semester) me.getValue()).getId());
@@ -97,14 +122,6 @@
         em.close();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj(EntityManagerFactory emf) {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -217,15 +234,5 @@
         tran.commit();
         em.close();
     }
-
-    public class Listener extends AbstractJDBCListener {
-        @Override
-        public void beforeExecuteStatement(JDBCEvent event) {
-            if (event.getSQL() != null && sql != null) {
-                sql.add(event.getSQL());
-                sqlCount++;
-            }
-        }
-    }
 }
 



Mime
View raw message