openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r767084 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/ openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ openjpa...
Date Tue, 21 Apr 2009 09:21:04 GMT
Author: fancy
Date: Tue Apr 21 09:21:02 2009
New Revision: 767084

URL: http://svn.apache.org/viewvc?rev=767084&view=rev
Log:
1035 JPA2 Query allow embeddable as orderby item
add more test strings for IS NULL and IS EMPTY predicates with path navigation thru key path
or embeddable

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
    openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.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

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java?rev=767084&r1=767083&r2=767084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java
Tue Apr 21 09:21:02 2009
@@ -292,15 +292,13 @@
                 case JavaTypes.ARRAY:
                 case JavaTypes.COLLECTION:
                     ValueMapping elem = pstate.field.getElementMapping();
+                    if (pstate.field.isElementCollection() &&
+                        pstate.field.getElement().isEmbedded())
+                        return ((HandlerCollectionTableFieldStrategy)
+                            pstate.field.getStrategy()).getElementColumns(
+                            elem.getTypeMapping());
                     if (pstate.joinedRel && elem.getTypeCode() == JavaTypes.PC)
-                    {
-                        if (pstate.field.isElementCollection() &&
-                            pstate.field.getElement().isEmbedded())
-                            return ((HandlerCollectionTableFieldStrategy)
-                                pstate.field.getStrategy()).getElementColumns(
-                                elem.getTypeMapping());
                         return elem.getTypeMapping().getPrimaryKeyColumns();
-                    }
                     if (elem.getColumns().length > 0)
                         return elem.getColumns();
                     return pstate.field.getColumns();

Modified: openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt?rev=767084&r1=767083&r2=767084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt (original)
+++ openjpa/trunk/openjpa-kernel/src/main/jjtree/org/apache/openjpa/kernel/jpql/JPQL.jjt Tue
Apr 21 09:21:02 2009
@@ -1277,7 +1277,9 @@
 
 void orderby_item() #ORDERBYITEM : { }
 {
-	(LOOKAHEAD(path()) path() | qualified_path() | orderby_extension() | identification_variable()
+	(LOOKAHEAD(path()) path() | LOOKAHEAD(qualified_path()) qualified_path()
+	 | LOOKAHEAD(general_identification_variable()) general_identification_variable()
+	 | orderby_extension() | identification_variable()
 	 )
 	    [ <ASC> #ASCENDING | <DESC> #DESCENDING ]
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java?rev=767084&r1=767083&r2=767084&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
Tue Apr 21 09:21:02 2009
@@ -1037,13 +1037,26 @@
                 "select e from " +
                     " EntityA_Coll_String a " +
                     " , in (a.nickNames) e order by a.id",
+                "select e from " +
+                    " EntityA_Coll_String a " +
+                    " , in (a.nickNames) e order by e",
+                "select a from " +
+                    " EntityA_Coll_String a " +
+                    " WHERE a.nickNames IS EMPTY order by a",
             };
         List rs = null;
         for (int i = 0; i < query.length; i++) {
             rs = em.createQuery(query[i]).getResultList();
-            assertTrue(rs.size() > 0);
-            Object obj = rs.get(0);
-            assertTrue(obj instanceof String);
+            switch (i) {
+            case 0:
+            case 1:
+                assertTrue(rs.size() > 0);
+                Object obj = rs.get(0);
+                assertTrue(obj instanceof String);
+                break;
+            case 2:
+                assertTrue(rs.size() == 0);
+            }
             em.clear();
         }
         EntityTransaction tran = em.getTransaction();
@@ -1068,6 +1081,11 @@
                 " EntityA_Embed_ToOne a ",
             "select e from EntityA_Embed_ToOne a " +
                 " join a.embed e join e.b b where e.b.id > 0 order by a.id",
+            "select a.embed from " +
+                " EntityA_Embed_ToOne a ORDER BY a.embed",
+            "select a.embed from " +
+                " EntityA_Embed_ToOne a WHERE a.embed.b IS NOT NULL " +
+                " ORDER BY a.embed",
         };
         for (int i = 0; i < query.length; i++) {
             List<Object[]> rs = null;
@@ -1100,6 +1118,12 @@
                 " EntityA_Embed_MappedToOne a ",
             "select e from EntityA_Embed_MappedToOne a " +
                 " join a.embed e join e.bm bm where e.bm.id > 0 order by a.id",
+            "select a.embed as e from " +
+                " EntityA_Embed_MappedToOne a ORDER BY e",
+            "select a.embed from " +
+                " EntityA_Embed_MappedToOne a WHERE a.embed IS NOT NULL",
+            "select a.embed from " +
+                " EntityA_Embed_MappedToOne a WHERE a.embed.bm IS NOT NULL",
         };
         for (int i = 0; i < query.length; i++) {
             List<Object[]> rs = null;
@@ -1137,6 +1161,16 @@
                 " EntityA_Coll_Embed_ToOne a " +
                 " , in (a.embed1s) e where e.name1 like '%1'" +
                 " order by e.name3",
+            "select e, e.b.id  from " +
+                " EntityA_Coll_Embed_ToOne a " +
+                " , in (a.embed1s) e where e.name1 like '%1'" +
+                " order by e",
+            "select e, e.b.id  from " +
+                " EntityA_Coll_Embed_ToOne a " +
+                " , in (a.embed1s) e where e.name1 like '%1' and" +
+                " a.embed1s IS NOT EMPTY and " +
+                " e.b IS NOT NULL " +
+                " order by e",
         };
         List<Object[]> rs = null;
         for (int i = 0; i < query.length; i++) {
@@ -1179,7 +1213,13 @@
                 " b",
             "select e from EntityA_Embed_ToMany a join a.embed e " +
                 " where e.name1 like '%1'",
-        };
+            "select a.embed from EntityA_Embed_ToMany a ORDER BY a.embed",
+            "select e from EntityA_Embed_ToMany a join a.embed e ORDER BY e",
+            "select b from EntityA_Embed_ToMany a join a.embed.bs" +
+                " b ORDER BY b",
+            "select e from EntityA_Embed_ToMany a join a.embed e " +
+                " WHERE e.bs IS NOT EMPTY ORDER BY e",
+            };
         List rs = null;
         for (int i = 0; i < query.length; i++) {
             rs = em.createQuery(query[i]).getResultList();
@@ -1188,10 +1228,14 @@
             switch (i) {
             case 0:
             case 1:
+            case 4:
+            case 5:
+            case 7:
                 assertTrue(obj instanceof Embed_ToMany);
                 assertTrue(((Embed_ToMany) obj).getEntityBs().size() > 0);
                 break;
             case 2:
+            case 6:
                 assertTrue(obj instanceof EntityB1);
                 break;
             }
@@ -1227,6 +1271,11 @@
                 " left join a.embed e1 left join e1.embed e2",
             "select e2 from EntityA_Embed_Embed_ToMany a " +
                 " join a.embed e1 join e1.embed e2",
+            "select a.embed as e from EntityA_Embed_Embed_ToMany a ORDER BY e",
+            "select a.embed.embed as e from EntityA_Embed_Embed_ToMany a " +
+                " where a.embed.embed.name1 like '%1' ORDER BY e",
+            "select a.embed from EntityA_Embed_Embed_ToMany a " +
+                " where a.embed.embed.bs IS NOT EMPTY",
         };
         List rs = null;
         for (int i = 0; i < query.length; i++) {
@@ -1236,6 +1285,8 @@
             switch (i) {
             case 0:
             case 1:
+            case 7:
+            case 9:
                 assertTrue(obj instanceof Embed_Embed_ToMany);
                 assertTrue(((Embed_Embed_ToMany) obj).getEmbed().getEntityBs().
                     size() > 0);
@@ -1244,6 +1295,7 @@
             case 4:
             case 5:
             case 6:
+            case 8:
                 assertTrue(obj instanceof Embed_ToMany);
                 assertTrue(((Embed_ToMany) obj).getEntityBs().size() > 0);
                 break;
@@ -1273,12 +1325,19 @@
         String[] query = {
             "select e, a.id from " +
                 " EntityA_Embed_Coll_Integer a " +
+                " , in (a.embed.otherIntVals) e order by e",
+            "select e, a.id from " +
+                " EntityA_Embed_Coll_Integer a " +
                 " , in (a.embed.otherIntVals) e order by a.id",
             "select e, a.embed.intVal1 from EntityA_Embed_Coll_Integer a " +
                 " , in (a.embed.otherIntVals) e order by a.id",
             "select e, a.embed.intVal2 from " +
                 " EntityA_Embed_Coll_Integer a " +
                 " , in (a.embed.otherIntVals) e order by e",
+            "select e, a.embed.intVal2 from " +
+                " EntityA_Embed_Coll_Integer a " +
+                " , in (a.embed.otherIntVals) e " +
+                " WHERE a.embed.otherIntVals IS NOT EMPTY order by e",
         };
         List<Object[]> rs = null;
         for (int i = 0; i < query.length; i++) {
@@ -1308,7 +1367,10 @@
         // test select embeddable
         String query[] = {
             "select a.embed from EntityA_Embed_Embed a",
-            "select a.embed.embed from EntityA_Embed_Embed a"
+            "select a.embed.embed from EntityA_Embed_Embed a",
+            "select a.embed as e from EntityA_Embed_Embed a ORDER BY e",
+            "select a.embed from EntityA_Embed_Embed a WHERE a.embed.embed " +
+                " IS NOT NULL",
         };
         List rs = null;
         for (int i = 0; i < query.length; i++) {
@@ -1316,10 +1378,13 @@
             assertTrue(rs.size() > 0);
             switch (i) {
             case 0:
+            case 2:
+            case 3:
                 assertTrue(rs.get(0) instanceof Embed_Embed);
                 break;
             case 1:
                 assertTrue(rs.get(0) instanceof Embed);
+                break;
             }
             em.clear();
         }
@@ -1346,6 +1411,12 @@
                 " , in (a.embeds) e order by e.intVal3",
             "select e, a.id from EntityA_Coll_Embed_Embed a " +
                 " , in (a.embeds) e order by a.id",
+            "select e, a.id from EntityA_Coll_Embed_Embed a " +
+                " , in (a.embeds) e order by e desc",
+            "select e, e.intVal1, e.embed.intVal2 from " +
+                " EntityA_Coll_Embed_Embed a " +
+                " , in (a.embeds) e WHERE a.embeds IS NOT EMPTY " +
+                " order by e.intVal3",
         };
         List rs = null;
         for (int i = 0; i < query.length; i++) {
@@ -1374,6 +1445,9 @@
         EntityManager em = emf.createEntityManager();
         // test select embed object from element collection in embeddable object
         String[] query = {
+            "select e, e.intVal1, e.intVal2 from " +
+                " EntityA_Embed_Coll_Embed a " +
+                " , in (a.embed.embeds) e order by e",
             "select e, e.intVal1 from " +
                 " EntityA_Embed_Coll_Embed a " +
                 " , in (a.embed.embeds) e order by e.intVal3",
@@ -1382,6 +1456,10 @@
             "select e, e.intVal1, e.intVal2 from " +
                 " EntityA_Embed_Coll_Embed a " +
                 " , in (a.embed.embeds) e order by e.intVal3",
+            "select e, e.intVal1, e.intVal2 from " +
+                " EntityA_Embed_Coll_Embed a " +
+                " , in (a.embed.embeds) e where a.embed.embeds IS NOT EMPTY" +
+                " order by e",
         };
         List<Object[]> rs = null;
         for (int i = 0; i < query.length; i++) {

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=767084&r1=767083&r2=767084&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 Apr 21 09:21:02 2009
@@ -89,7 +89,7 @@
             setCandidate(q, PhoneNumber.class);
         List rs = q.getResultList();
         String d = (String) rs.get(0);
-
+   
         query = "select KEY(p) from Employee e, " +
                 " in (e.phones) p";
         q = em.createQuery(query);
@@ -126,6 +126,15 @@
         rs = q.getResultList();
         assertEquals((String) rs.get(0), "String1");
 
+        query = "select KEY(e) from PhoneNumber p, " +
+            " in (p.emps) e WHERE KEY(e) = ?1";
+        q = em.createQuery(query);
+        q.setParameter(1, "String1");
+        if (inMemory) 
+            setCandidate(q, PhoneNumber.class);
+        rs = q.getResultList();
+        assertEquals((String) rs.get(0), "String1");
+
         em.close();
     }
 

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=767084&r1=767083&r2=767084&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 Apr 21 09:21:02 2009
@@ -135,6 +135,7 @@
         rs = q.getResultList();
         d2 = (Department) ((Object[]) rs.get(0))[0];
         String dname = (String) ((Object[]) rs.get(0))[1];
+        assertEquals(d2.getName(), dname);
 
         // test GROUP BY qualified path
         sql.clear();
@@ -147,6 +148,35 @@
         if (!inMemory)
             assertTrue(sql.get(0).toUpperCase().indexOf(" GROUP BY ") != -1);
 
+        query = "select KEY(p) as k, KEY(p).name from Employee e, " +
+          " in (e.phones) p ORDER BY k";
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        d2 = (Department) ((Object[]) rs.get(0))[0];
+        dname = (String) ((Object[]) rs.get(0))[1];
+        assertEquals(d2.getName(), dname);
+
+        query = "select KEY(p), KEY(p).name from Employee e, " +
+          " in (e.phones) p ORDER BY KEY(p)";
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        d2 = (Department) ((Object[]) rs.get(0))[0];
+        dname = (String) ((Object[]) rs.get(0))[1];
+        assertEquals(d2.getName(), dname);
+
+        query = "select VALUE(p), KEY(p).name from Employee e, " +
+          " in (e.phones) p ORDER BY VALUE(p)";
+        q = em.createQuery(query);
+        if (inMemory) 
+            setCandidate(q, Employee.class);
+        rs = q.getResultList();
+        PhoneNumber ph = (PhoneNumber) ((Object[]) rs.get(0))[0];
+        assertEquals(ph.getNumber(), 1);
+
         em.close();
     }
 



Mime
View raw message