cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5806] Adding a patch from Romain Castan
Date Thu, 19 Jun 2014 11:27:56 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes a2cfbf0cb -> 528cde38c


[CXF-5806] Adding a patch from Romain Castan


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/528cde38
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/528cde38
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/528cde38

Branch: refs/heads/2.7.x-fixes
Commit: 528cde38c42370b9647e1aef0543399e48a4e9f2
Parents: a2cfbf0
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Jun 18 21:31:56 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Jun 19 12:27:34 2014 +0100

----------------------------------------------------------------------
 .../jpa/AbstractJPATypedQueryVisitor.java       | 32 ++++++++++++++------
 .../search/jpa/JPATypedQueryVisitorTest.java    | 13 ++++++--
 .../cxf/jaxrs/ext/search/jpa/Library.java       | 14 +++++++++
 3 files changed, 46 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/528cde38/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
index 084cd93..6872dd8 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
@@ -283,19 +283,19 @@ public abstract class AbstractJPATypedQueryVisitor<T, T1, E>
         if (name.contains(".")) {
             String pre = name.substring(0, name.indexOf('.'));
             String post = name.substring(name.indexOf('.') + 1);
-            return getPath(getNextPath(element, pre, cv, null), 
-                           post, 
-                           cv,
-                           collSize);
+            final Path<?> nextPath = getNextPath(element, pre, post, cv, null);
+            return getPath(nextPath, post, cv, collSize);
         } else {
-            return getNextPath(element, name, cv, collSize);
+            return getNextPath(element, name, null, cv, collSize);
         }
     }
 
-    private Path<?> getNextPath(Path<?> element, String name, ClassValue cv,
CollectionCheckInfo collSize) {
-        if (collSize == null
-            && (cv.isCollection(name) || isJoinProperty(name)) && (element
== root || element instanceof Join)) {
-            
+    private Path<?> getNextPath(Path<?> element, String name, String postName,

+        ClassValue cv, CollectionCheckInfo collSize) {
+        final boolean isCollectionOrJoin = collSize == null
+            && (cv.isCollection(name) || isJoinProperty(name) || existingCollectionInPostName(cv,
postName)) 
+            && (element == root || element instanceof Join);
+        if (isCollectionOrJoin) {
             final Path<?> path = getExistingJoinProperty((From<?, ?>)element,
name);
             if (path != null) {
                 return path;
@@ -303,7 +303,7 @@ public abstract class AbstractJPATypedQueryVisitor<T, T1, E>
                 return element == root ? root.join(name) : ((Join<?, ?>)element).join(name);
             }
         } else {
-            return element.get(name);
+            return element.get(name);                
         }
     }
     
@@ -321,4 +321,16 @@ public abstract class AbstractJPATypedQueryVisitor<T, T1, E>
         }
         return null;
     }
+    
+    private boolean existingCollectionInPostName(ClassValue cv, String postName) {
+        if (postName != null) {
+            final String[] splitName = postName.split("\\.");
+            for (String name : splitName) {
+                if (cv.isCollection(name)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/528cde38/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
index 9a4de94..2931377 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
@@ -98,7 +98,6 @@ public class JPATypedQueryVisitorTest extends Assert {
             b1.setLibrary(lib);
             b1.getAuthors().add("John");
             em.persist(b1);
-            assertTrue(em.contains(b1));
             
             BookReview br2 = new BookReview();
             br2.setId(2);
@@ -120,7 +119,6 @@ public class JPATypedQueryVisitorTest extends Assert {
             b2.setLibrary(lib);
             b2.getAuthors().add("John");
             em.persist(b2);
-            assertTrue(em.contains(b2));
             
             BookReview br3 = new BookReview();
             br3.setId(3);
@@ -141,7 +139,10 @@ public class JPATypedQueryVisitorTest extends Assert {
             b3.setOwnerInfo(info3);
             b3.setLibrary(lib);
             em.persist(b3);
-            assertTrue(em.contains(b3));
+
+            lib.getBooks().add(b1);
+            lib.getBooks().add(b2);
+            lib.getBooks().add(b3); 
             
             em.getTransaction().commit();
         } catch (Exception ex) {
@@ -192,6 +193,12 @@ public class JPATypedQueryVisitorTest extends Assert {
     }
     
     @Test
+    public void testGetLibraryBook() throws Exception {
+        List<Book> books = queryBooks("library.books.bookTitle==num10");
+        assertEquals(3, books.size());
+    }
+
+    @Test
     public void testQueryCollection() throws Exception {
         List<Book> books = 
             queryBooks("reviews.authors==Ted");

http://git-wip-us.apache.org/repos/asf/cxf/blob/528cde38/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Library.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Library.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Library.java
index 1c24625..c5879a2 100644
--- a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Library.java
+++ b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Library.java
@@ -18,14 +18,20 @@
  */
 package org.apache.cxf.jaxrs.ext.search.jpa;
 
+import java.util.LinkedList;
+import java.util.List;
+
 import javax.persistence.Entity;
 import javax.persistence.Id;
+import javax.persistence.OneToMany;
 
 @Entity
 public class Library {
     @Id
     private int id;
     private String address;
+    @OneToMany
+    private List<Book> books = new LinkedList<Book>(); 
     
     public int getId() {
         return id;
@@ -42,4 +48,12 @@ public class Library {
     public void setAddress(String address) {
         this.address = address;
     }
+
+    public List<Book> getBooks() {
+        return books;
+    }
+
+    public void setBooks(List<Book> books) {
+        this.books = books;
+    }
 }


Mime
View raw message