openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r757670 [1/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
Author: faywang
Date: Tue Mar 24 05:55:13 2009
New Revision: 757670

URL: http://svn.apache.org/viewvc?rev=757670&view=rev
Log:
OPENJPA-967: Qualified Identifier in-memory query test cases

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex0/TestMany2ManyMap.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex1/TestMany2ManyMapEx1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex2/TestMany2ManyMapEx2.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex3/TestMany2ManyMapEx3.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex4/TestMany2ManyMapEx4.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex5/TestMany2ManyMapEx5.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/TestMany2ManyMapEx6.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex7/TestMany2ManyMapEx7.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex8/TestMany2ManyMapEx8.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex9/TestMany2ManyMapEx9.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex0/TestSpec10_1_26.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex1/TestSpec10_1_26_Ex1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex2/TestSpec10_1_26_Ex2.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex3/TestSpec10_1_26_Ex3.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex0/TestSpec10_1_27.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex3/TestSpec10_1_27_Ex3.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex4/TestSpec10_1_27_Ex4.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex5/TestSpec10_1_27_Ex5.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_27_ex8/TestSpec10_1_27_Ex8.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex1/TestSpec10_1_29_Ex1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_29_ex3/TestSpec10_1_29_Ex3.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex0/TestMany2ManyMap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex0/TestMany2ManyMap.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex0/TestMany2ManyMap.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex0/TestMany2ManyMap.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.m2mmapex0;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -30,14 +29,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.kernel.QueryImpl;
 import org.apache.openjpa.persistence.ArgumentException;
-import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.persistence.test.AllowFailure;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
-
-public class TestMany2ManyMap extends SingleEMFTestCase {
+public class TestMany2ManyMap extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbersPerEmployee = 2;
@@ -45,67 +42,102 @@
     public Map<Integer, PhoneNumber> phoneMap =
         new HashMap<Integer, PhoneNumber>();
 
-    public List<String> namedQueries = new ArrayList<String>();
 
     public int empId = 1;
     public int phoneId = 1;
     public int divId = 1;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES, Division.class,
-            Employee.class, PhoneNumber.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { this.new Listener() });
+            Employee.class, PhoneNumber.class);
         createObj();
+       	rsAllPhones = getAll(PhoneNumber.class);
+       	rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+    
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
 
         // test navigation thru VALUE
         String query = "select VALUE(e).empId from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
 
         // test navigation thru KEY
         query = "select KEY(e), KEY(e).name from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         Division d0 = (Division) ((Object[]) rs.get(0))[0];
         String name = (String)((Object[]) rs.get(0))[1];
         assertEquals(d0.getName(), name);
 
         query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         Division d = (Division) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        Division d2 = (Division) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        Division d2 = (Division) rs.get(0);
 
-        String query3 = "select VALUE(e) from PhoneNumber p, " +
+        query = "select VALUE(e) from PhoneNumber p, " +
             " in (p.emps) e";
-
-        List rs3 = em.createQuery(query3).getResultList();
-        Employee e = (Employee) rs3.get(0);
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Employee e = (Employee) rs.get(0);
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
-        String query5 = "select TYPE(KEY(p)) from Employee e, " +
+        query = "select TYPE(KEY(p)) from Employee e, " +
             " in (e.phones) p";
-        List rs5 = em.createQuery(query5).getResultList();
-        assertEquals(Division.class, rs5.get(0));
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        assertEquals(Division.class, rs.get(0));
 
         // expects parser error:
         // JPA2 has no support for predicate comparison using
@@ -113,17 +145,21 @@
         String query1 = "select KEY(p) from Employee e, " +
             " in (e.phones) p where KEY(p) = ?1";
         try {
-             List rs1 = em.createQuery(query1).setParameter(1, d2).
-                 getResultList();
+            q = em.createQuery(query).setParameter(1, d2);
+            if (inMemory) 
+                setCandidate(q, Employee.class);
+            rs = q.getResultList();
         } catch (Exception ex) {
             assertException(ex, ArgumentException.class);
         }
 
         // test VALUE(e) IS NULL predicate
-        query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p WHERE VALUE(p) IS NULL";
-        rs2 = em.createQuery(query2).getResultList();
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
         em.close();
     }
 
@@ -132,14 +168,6 @@
         findObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -179,19 +207,6 @@
         return d;
     }
 
-    public void removeAll() {
-        EntityManager em = emf.createEntityManager();
-        EntityTransaction tran = em.getTransaction();
-        tran.begin();
-        Query q = em.createNativeQuery("delete from department");
-        q.executeUpdate();
-        q = em.createNativeQuery("delete from employee");
-        q.executeUpdate();
-        System.out.println("committing removes");
-        tran.commit();
-        em.close();
-    }
-
     public void findObj() throws Exception {
         EntityManager em = emf.createEntityManager();
         Employee e = em.find(Employee.class, 1);
@@ -277,13 +292,4 @@
         }
     }    
 
-    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/m2mmapex1/TestMany2ManyMapEx1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex1/TestMany2ManyMapEx1.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex1/TestMany2ManyMapEx1.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex1/TestMany2ManyMapEx1.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.m2mmapex1;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -31,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 TestMany2ManyMapEx1 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx1 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbersPerEmployee = 2;
@@ -45,48 +43,75 @@
     public Map<Integer, PhoneNumber> phoneMap =
         new HashMap<Integer, PhoneNumber>();
 
-    public List<String> namedQueries = new ArrayList<String>();
-
     public int empId = 1;
     public int phoneId = 1;
     public int divId = 1;
     public int deptId = 10;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
+    public List rsAllDivisions = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Department.class,
             Division.class,
             Employee.class,
-            PhoneNumber.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { 
-            this.new Listener() 
-        });
-
+            PhoneNumber.class);
         createObj(emf);
-    }
-
+       	rsAllPhones = getAll(PhoneNumber.class);
+       	rsAllEmps = getAll(Employee.class);
+       	rsAllDivisions = getAll(Division.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+        else if (clz == Division.class)
+            qi.setCandidateCollection(rsAllDivisions);
+    }
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e), p from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         Division d = (Division) ((Object[]) rs.get(0))[0];
         PhoneNumber p = (PhoneNumber) ((Object[]) rs.get(0))[1];
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
                 " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        Department d2 = (Department) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        Department d2 = (Department) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -94,69 +119,102 @@
         em.clear();
         query = "select KEY(e), KEY(e).name from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         Division d0 = (Division) ((Object[]) rs.get(0))[0];
         String name = (String)((Object[]) rs.get(0))[1];
         assertEquals(d0.getName(), name);
 
         em.clear();
-        query2 = "select KEY(p), KEY(p).name from Employee e, " +
+        query = "select KEY(p), KEY(p).name from Employee e, " +
             " in (e.phones) p";
-        rs2 = em.createQuery(query2).getResultList();
-        d2 = (Department) ((Object[]) rs2.get(0))[0];
-        String dname = (String) ((Object[]) rs2.get(0))[1];
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        d2 = (Department) ((Object[]) rs.get(0))[0];
+        String dname = (String) ((Object[]) rs.get(0))[1];
         assertEquals(d2.getName(), dname);
 
         // test ORDER BY qualified path
         em.clear();
 
-        query2 = "select KEY(p), KEY(p).name from Employee e, " +
+        query = "select KEY(p), KEY(p).name from Employee e, " +
             " in (e.phones) p ORDER BY KEY(p).name DESC";
-        rs2 = em.createQuery(query2).getResultList();        
-        String name1 = (String) ((Object[]) rs2.get(0))[1];
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        String name1 = (String) ((Object[]) rs.get(0))[1];
 
         em.clear();
 
-        query2 = "select KEY(p), KEY(p).name as name from Employee e, " +
+        query = "select KEY(p), KEY(p).name as name from Employee e, " +
             " in (e.phones) p ORDER BY name DESC";
-        rs2 = em.createQuery(query2).getResultList();
-        String name2 = (String) ((Object[]) rs2.get(0))[1];
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        String name2 = (String) ((Object[]) rs.get(0))[1];
         
         assertEquals(name1, name2);
 
         // test GROUP BY qualified path
-        String query5 = "select count(KEY(p).name) from Employee e, " +
+        query = "select count(KEY(p).name) from Employee e, " +
             " in (e.phones) p GROUP BY KEY(p).name";
-        List rs5 = em.createQuery(query5).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
 
         em.clear();
-        query2 = "select p.division, KEY(p), KEY(p).name from Employee e, " +
+        query = "select p.division, KEY(p), KEY(p).name from Employee e, " +
             " in (e.phones) p ORDER BY KEY(p).name DESC";
-        rs2 = em.createQuery(query2).getResultList();        
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
 
-        query2 = "select KEY(e) from PhoneNumber p, " +
+        query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e";
-        rs2 = em.createQuery(query2).getResultList();        
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
 
-        query2 = "select KEY(e) from PhoneNumber p " +
+        query = "select KEY(e) from PhoneNumber p " +
             " left join p.emps e";
-        rs2 = em.createQuery(query2).getResultList();        
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
 
         query = "select p.division, KEY(e), KEY(e).name as nm" +
             " from PhoneNumber p, " +
             " in (p.emps) e order by nm";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         String n1 = ((Division) ((Object[]) rs.get(0))[1]).getName();
         String n2 = (String) ((Object[]) rs.get(0))[2];
         assertEquals(n1, n2);
 
         query = "select d.name, KEY(e), KEY(e).name from PhoneNumber p, " +
             " in (p.emps) e, Division d";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         query = "select d.name, KEY(e), KEY(e).name from " +
             "Division d join d.phone p, " +
             " in (p.emps) e order by d.name";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Division.class);
+        rs = q.getResultList();
         n1 = ((Division) ((Object[]) rs.get(0))[1]).getName();
         n2 = (String) ((Object[]) rs.get(0))[2];
         assertEquals(n1, n2);
@@ -169,14 +227,6 @@
         findObj(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();
@@ -309,13 +359,4 @@
         }
     }    
 
-    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/m2mmapex10/TestMany2ManyMapEx10.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex10/TestMany2ManyMapEx10.java Tue Mar 24 05:55:13 2009
@@ -31,12 +31,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 TestMany2ManyMapEx10 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx10 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -54,38 +53,64 @@
     public int empId = 1;
     public int phoneId = 1;
     public int divId = 1;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(DROP_TABLES,EmployeePK.class, PhonePK.class,
-            Employee.class, PhoneNumber.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { 
-            this.new Listener() 
-        });
+            Employee.class, PhoneNumber.class);
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+    
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e where e.empPK = ?1";
-        List rs = em.createQuery(query).setParameter(1, empPKs.get(0)).
-            getResultList();
+        Query q = em.createQuery(query).setParameter(1, empPKs.get(0));
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         EmployeePK d = (EmployeePK) rs.get(0);
-        String query2 = "select KEY(p) from Employee e, " +
+        
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        PhonePK k = (PhonePK) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        PhonePK k = (PhonePK) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e  where e.empPK = ?1";
-        List rs4 = em.createQuery(query4).setParameter(1, empPKs.get(0)).
-            getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query).setParameter(1, empPKs.get(0));
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -93,30 +118,42 @@
         em.clear();
         query = "select KEY(e), KEY(e).name from PhoneNumber p, " +
             " in (p.emps) e";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         EmployeePK d0 = (EmployeePK) ((Object[]) rs.get(0))[0];
         String name = (String)((Object[]) rs.get(0))[1];
         assertEquals(d0.getName(), name);
 
         em.clear();
-        query2 = "select KEY(p), KEY(p).phoneNum from Employee e, " +
+        query = "select KEY(p), KEY(p).phoneNum from Employee e, " +
             " in (e.phones) p";
-        rs2 = em.createQuery(query2).getResultList();
-        k = (PhonePK) ((Object[]) rs2.get(0))[0];
-        String phoneNum = (String) ((Object[]) rs2.get(0))[1];
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        k = (PhonePK) ((Object[]) rs.get(0))[0];
+        String phoneNum = (String) ((Object[]) rs.get(0))[1];
         assertEquals(k.getPhoneNum(), phoneNum);
 
         // test ORDER BY qualified path
-        query2 = "select KEY(p), KEY(p).phoneNum as pno from Employee e " +
+        query = "select KEY(p), KEY(p).phoneNum as pno from Employee e " +
             " left join e.phones p ORDER BY pno ";
-        rs2 = em.createQuery(query2).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
 
         // test GROUP BY qualified path
         sql.clear();
-        query2 = "select COUNT(KEY(p).phoneNum) from Employee e " +
+        query = "select COUNT(KEY(p).phoneNum) from Employee e " +
             " left join e.phones p GROUP BY KEY(p).phoneNum";
-        rs2 = em.createQuery(query2).getResultList();
-
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        if (!inMemory)
         assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
 
         em.close();
@@ -127,14 +164,6 @@
         findObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -255,14 +284,4 @@
                 throw new Exception("Assertion failure");
         }
     } 
-
-    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/m2mmapex2/TestMany2ManyMapEx2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex2/TestMany2ManyMapEx2.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex2/TestMany2ManyMapEx2.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex2/TestMany2ManyMapEx2.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.m2mmapex2;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -30,12 +29,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 TestMany2ManyMapEx2 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx2 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -46,44 +44,68 @@
     public Map<Integer, PhoneNumber> phoneMap =
         new HashMap<Integer, PhoneNumber>();
 
-    public List<String> namedQueries = new ArrayList<String>();
-
     public int empId = 1;
     public int phoneId = 1;
     public int divId = 1;
     public int deptId = 1;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Department.class,
             Employee.class,
-            PhoneNumber.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            PhoneNumber.class
         );
         createObj();
+           rsAllPhones = getAll(PhoneNumber.class);
+           rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         String d = (String) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
                 " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        Department d2 = (Department) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        Department d2 = (Department) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -95,14 +117,6 @@
         findObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -224,13 +238,4 @@
         }
     }    
 
-    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/m2mmapex3/TestMany2ManyMapEx3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex3/TestMany2ManyMapEx3.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex3/TestMany2ManyMapEx3.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex3/TestMany2ManyMapEx3.java Tue Mar 24 05:55:13 2009
@@ -30,18 +30,16 @@
 
 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 TestMany2ManyMapEx3 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx3 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
     public int numEmployeesPerPhoneNumber = 2;
     public int numPhoneNumbersPerEmployee = 2;
-    public List<String> namedQueries = new ArrayList<String>();
 
     public Map<Integer, Employee> empMap = new HashMap<Integer, Employee>();
     public Map<Integer, PhoneNumber> phoneMap =
@@ -51,36 +49,68 @@
     public int phoneId = 1;
     public int divId = 1;
     public int deptId = 1;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Department.class,
             Employee.class,
             PhoneNumber.class,
-            FullName.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            FullName.class
         );
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+    
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         FullName d = (FullName) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        Department d2 = (Department) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        Department d2 = (Department) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -88,24 +118,34 @@
         em.clear();
         query = "select KEY(e), KEY(e).fName from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         d = (FullName) ((Object[]) rs.get(0))[0];
         String fname = (String) ((Object[]) rs.get(0))[1];
         assertEquals(d.getFName(), fname);
         
         em.clear();
-        query2 = "select KEY(p), KEY(p).name from Employee e, " +
+        query = "select KEY(p), KEY(p).name from Employee e, " +
             " in (e.phones) p";
-        rs2 = em.createQuery(query2).getResultList();
-        d2 = (Department) ((Object[]) rs2.get(0))[0];
-        String dname = (String) ((Object[]) rs2.get(0))[1];
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        d2 = (Department) ((Object[]) rs.get(0))[0];
+        String dname = (String) ((Object[]) rs.get(0))[1];
 
         // test GROUP BY qualified path
         sql.clear();
-        query2 = "select COUNT(KEY(p).id) from Employee e " +
+        query = "select COUNT(KEY(p).id) from Employee e " +
             " left join e.phones p GROUP BY KEY(p).id";
-        rs2 = em.createQuery(query2).getResultList();
-        assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        if (!inMemory)
+            assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
 
         em.close();
     }
@@ -115,17 +155,6 @@
         findObj();
     }
 
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;    
-
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -247,14 +276,4 @@
                 throw new Exception("Assertion failure");
         }
     }    
-
-    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/m2mmapex4/TestMany2ManyMapEx4.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex4/TestMany2ManyMapEx4.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex4/TestMany2ManyMapEx4.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex4/TestMany2ManyMapEx4.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 TestMany2ManyMapEx4 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx4 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -55,6 +54,8 @@
     public int deptId = 1;
     public int officeId = 1;
     public int numOfficesPerDivision = 2;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
@@ -62,46 +63,85 @@
             Employee.class,
             PhoneNumber.class,
             Office.class,
-            Address.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            Address.class
         );
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         // a collection valued path thru KEY in FROM clause
-        String query1 = "select o.address.city from PhoneNumber p, " +
+        String query = "select o.address.city from PhoneNumber p, " +
             " in (p.emps) e, in(KEY(e).offices) o";
-        List rs1 = em.createQuery(query1).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
 
         // a path thru KEY nagivation apprear in ORDER BY
-        query1 = "select o.address.city as city from PhoneNumber p, " +
+        query = "select o.address.city as city from PhoneNumber p, " +
             " in (p.emps) e, in(KEY(e).offices) o order by city";
-        rs1 = em.createQuery(query1).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
 
         // a path thru KEY nagivation apprear in WHERE clause
-        query1 = "select o.address.city as city from PhoneNumber p, " +
+        query = "select o.address.city as city from PhoneNumber p, " +
             " in (p.emps) e, in(KEY(e).offices) o " +
             " where o.address.city like '%1'";
-        rs1 = em.createQuery(query1).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
 
-        String query = "select KEY(e) from PhoneNumber p, " +
+        query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
         Division d = (Division) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        String k = (String) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        String k = (String) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -254,14 +294,4 @@
                 throw new Exception("Assertion failure");
         }
     }    
-
-    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/m2mmapex5/TestMany2ManyMapEx5.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex5/TestMany2ManyMapEx5.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex5/TestMany2ManyMapEx5.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex5/TestMany2ManyMapEx5.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 TestMany2ManyMapEx5 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx5 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -53,37 +52,66 @@
     public int phoneId = 1;
     public int divId = 1;
     public int deptId = 1;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Employee.class,
-            PhoneNumber.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            PhoneNumber.class
         );
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         String d = (String) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        String k = (String) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        String k = (String) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -95,14 +123,6 @@
         findObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -213,14 +233,4 @@
                 throw new Exception("Assertion failure");
         }
     }    
-
-    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/m2mmapex6/TestMany2ManyMapEx6.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/TestMany2ManyMapEx6.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/TestMany2ManyMapEx6.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex6/TestMany2ManyMapEx6.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 TestMany2ManyMapEx6 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx6 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -54,46 +53,80 @@
     public int divId = 1;
     public int deptId = 1;
 
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Employee.class,
             PhoneNumber.class,
-            FullName.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            FullName.class
         );
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         FullName d = (FullName) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        String k = (String) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        String k = (String) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.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).lName) from PhoneNumber p " +
+        query = "select count(KEY(e).lName) from PhoneNumber p " +
             " left join p.emps e GROUP BY KEY(e).lName";
-        List rs5 = em.createQuery(query5).getResultList();
-        assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        if (!inMemory)
+            assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
 
         em.close();
     }
@@ -103,14 +136,6 @@
         findObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -223,14 +248,4 @@
                 throw new Exception("Assertion failure");
         }
     }    
-
-    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/m2mmapex7/TestMany2ManyMapEx7.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex7/TestMany2ManyMapEx7.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex7/TestMany2ManyMapEx7.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex7/TestMany2ManyMapEx7.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 TestMany2ManyMapEx7 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx7 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -53,36 +52,68 @@
     public int phoneId = 1;
     public int divId = 1;
     public int deptId = 1;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Division.class,
             Employee.class,
             FullName.class,
-            PhoneNumber.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            PhoneNumber.class
         );
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         Division d = (Division) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        FullName f = (FullName) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        FullName f = (FullName) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
         
@@ -227,14 +258,4 @@
                 throw new Exception("Assertion failure");
         }
     }
-
-    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/m2mmapex8/TestMany2ManyMapEx8.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex8/TestMany2ManyMapEx8.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex8/TestMany2ManyMapEx8.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex8/TestMany2ManyMapEx8.java Tue Mar 24 05:55:13 2009
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc.maps.m2mmapex8;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -30,12 +29,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 TestMany2ManyMapEx8 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx8 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -43,7 +41,6 @@
     public int numPhoneNumbersPerEmployee = 2;
     public Map<Integer, PhoneNumber> phones =
         new HashMap<Integer, PhoneNumber>();
-    public List<String> namedQueries = new ArrayList<String>();
 
     public Map<Integer, Employee> empMap = new HashMap<Integer, Employee>();
     public Map<Integer, PhoneNumber> phoneMap =
@@ -53,38 +50,67 @@
     public int phoneId = 1;
     public int divId = 1;
     public int deptId = 1;
-
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Employee.class,
             FullName.class,
-            PhoneNumber.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            PhoneNumber.class
         );
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         String d = (String) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        FullName d2 = (FullName) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        FullName d2 = (FullName) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -92,8 +118,12 @@
         sql.clear();
         query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e where KEY(e) like '%1'";
-        rs = em.createQuery(query).getResultList();
-        assertTrue(sql.get(0).toUpperCase().indexOf("LIKE") > 0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        if (!inMemory)
+            assertTrue(sql.get(0).toUpperCase().indexOf("LIKE") > 0);
 
         em.close();
     }
@@ -103,14 +133,6 @@
         findObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -224,14 +246,4 @@
                 throw new Exception("Assertion failure");
         }
     }
-
-    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/m2mmapex9/TestMany2ManyMapEx9.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex9/TestMany2ManyMapEx9.java?rev=757670&r1=757669&r2=757670&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex9/TestMany2ManyMapEx9.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/m2mmapex9/TestMany2ManyMapEx9.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 TestMany2ManyMapEx9 extends SingleEMFTestCase {
+public class TestMany2ManyMapEx9 extends SQLListenerTestCase {
 
     public int numEmployees = 2;
     public int numPhoneNumbers = numEmployees + 1;
@@ -55,38 +54,68 @@
     public Map<Integer, PhoneNumber> phoneMap =
         new HashMap<Integer, PhoneNumber>();
 
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllPhones = null;
+    public List rsAllEmps = null;
 
     public void setUp() {
         super.setUp(CLEAR_TABLES,
             Employee.class,
             FullName.class,
             PhoneNumber.class,
-            FullPhoneName.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] {  this.new Listener() }
+            FullPhoneName.class
         );
         createObj();
+        rsAllPhones = getAll(PhoneNumber.class);
+        rsAllEmps = getAll(Employee.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 == PhoneNumber.class)
+            qi.setCandidateCollection(rsAllPhones);
+        else if (clz == Employee.class)
+            qi.setCandidateCollection(rsAllEmps);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        List rs = q.getResultList();
         FullName d = (FullName) rs.get(0);
 
-        String query2 = "select KEY(p) from Employee e, " +
+        query = "select KEY(p) from Employee e, " +
             " in (e.phones) p";
-        List rs2 = em.createQuery(query2).getResultList();
-        FullPhoneName k = (FullPhoneName) rs2.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        FullPhoneName k = (FullPhoneName) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from PhoneNumber p, " +
+        query = "select ENTRY(e) from PhoneNumber p, " +
             " in (p.emps) e order by e.empId";
-        List rs4 = em.createQuery(query4).getResultList();
-        Map.Entry me = (Map.Entry) rs4.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        Map.Entry me = (Map.Entry) rs.get(0);
 
         assertTrue(d.equals(me.getKey()));
 
@@ -98,14 +127,6 @@
         findObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -138,19 +159,6 @@
         return e;
     }
 
-    public void removeAll() {
-        EntityManager em = emf.createEntityManager();
-        EntityTransaction tran = em.getTransaction();
-        tran.begin();
-        Query q = em.createNativeQuery("delete from phonenumber");
-        q.executeUpdate();
-        q = em.createNativeQuery("delete from employee");
-        q.executeUpdate();
-        System.out.println("committing removes");
-        tran.commit();
-        em.close();
-    }
-
     public void findObj() throws Exception {
         EntityManager em = emf.createEntityManager();
         Employee e = em.find(Employee.class, 1);
@@ -234,14 +242,4 @@
                 throw new Exception("Assertion failure");
         }
     }
-
-    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_26_ex0/TestSpec10_1_26.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_ex0/TestSpec10_1_26.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_ex0/TestSpec10_1_26.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex0/TestSpec10_1_26.java Tue Mar 24 05:55:13 2009
@@ -24,19 +24,19 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import junit.framework.*;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
 import javax.persistence.Query;
 
-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 junit.framework.Assert;
 
-public class TestSpec10_1_26 extends 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 extends SQLListenerTestCase {
 
     public int numDepartments = 2;
     public int numEmployeesPerDept = 2;
@@ -45,8 +45,9 @@
     public int deptId = 1;
     public int empId = 1;
 
-    protected List<String> sql = new ArrayList<String>();
-    protected int sqlCount;
+    public List rsAllDepartment1 = null;
+    public List rsAllDepartment2 = null;
+    public List rsAllDepartment3 = null;
 
     public void setUp() {
         super.setUp(DROP_TABLES,
@@ -57,28 +58,61 @@
             Employee2.class,
             Employee3.class,
             EmployeeName3.class,
-            EmployeePK2.class,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { 
-            this.new Listener() 
-        });
+            EmployeePK2.class);
         createObj();
+        rsAllDepartment1 = getAll(Department1.class);
+        rsAllDepartment2 = getAll(Department2.class);
+        rsAllDepartment3 = getAll(Department3.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 == Department1.class)
+            qi.setCandidateCollection(rsAllDepartment1);
+        else if (clz == Department2.class)
+            qi.setCandidateCollection(rsAllDepartment2);
+        else if (clz == Department3.class)
+            qi.setCandidateCollection(rsAllDepartment3);
+    }
+
+    public void queryQualifiedId(boolean inMemory) throws Exception {
         EntityManager em = emf.createEntityManager();
         String query = "select KEY(e) from Department1 d, " +
             " in (d.empMap) e";
-        List rs = em.createQuery(query).getResultList();
+        Query q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department1.class);
+        List rs = q.getResultList();
         Integer d = (Integer) rs.get(0);
-        String query2 = "select KEY(e) from Department2 d, " +
+        
+        query = "select KEY(e) from Department2 d, " +
             " in (d.empMap) e";
-        List rs2 = em.createQuery(query2).getResultList();
-        EmployeePK2 d2 = (EmployeePK2) rs2.get(0);
-        String query3 = "select KEY(e) from Department3 d, " +
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department2.class);
+        rs = q.getResultList();
+        EmployeePK2 d2 = (EmployeePK2) rs.get(0);
+        
+        query = "select KEY(e) from Department3 d, " +
             " in (d.emps) e";
-        List rs3 = em.createQuery(query3).getResultList();
-        EmployeeName3 d3 = (EmployeeName3) rs3.get(0);
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department3.class);
+        rs = q.getResultList();
+        EmployeeName3 d3 = (EmployeeName3) rs.get(0);
         em.close();
     }
 
@@ -86,15 +120,6 @@
         queryObj();
     }
 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -336,14 +361,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_26_ex1/TestSpec10_1_26_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_26_ex1/TestSpec10_1_26_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_26_ex1/TestSpec10_1_26_Ex1.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/maps/spec_10_1_26_ex1/TestSpec10_1_26_Ex1.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_Ex1 extends SingleEMFTestCase {
+public class TestSpec10_1_26_Ex1 extends SQLListenerTestCase {
 
     public int numDepartments = 2;
     public int numEmployeesPerDept = 2;
@@ -43,33 +42,53 @@
 
     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,
-            "openjpa.jdbc.JDBCListeners", 
-            new JDBCListener[] { 
-            this.new Listener() 
-        });
+            Employee.class);
         createObj();
+        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.empMap) 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();
         Integer d = (Integer) rs.get(0);
 
         em.clear();
-        String query4 = "select ENTRY(e) from Department d, " +
+        query = "select ENTRY(e) from Department d, " +
             " in (d.empMap) 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()));
 
@@ -77,7 +96,10 @@
         sql.clear();
         query = "select KEY(e) from Department d, " +
             " in (d.empMap) e where KEY(e) > 1";
-        rs = em.createQuery(query).getResultList();
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Department.class);
+        rs = q.getResultList();
         assertTrue(sql.get(0).toUpperCase().indexOf(">") > 0);
 
         em.close();
@@ -88,14 +110,6 @@
         findObj();
     }
                 
-    public List<String> getSql() {
-        return sql;
-    }
-
-    public int getSqlCount() {
-        return sqlCount;
-    }
-
     public void createObj() {
         EntityManager em = emf.createEntityManager();
         EntityTransaction tran = em.getTransaction();
@@ -222,14 +236,4 @@
         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++;
-            }
-        }
-    }
 }



Mime
View raw message