You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2012/12/18 18:21:48 UTC
svn commit: r1423539 - in /cxf/branches/2.6.x-fixes: ./
rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/
rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/
Author: sergeyb
Date: Tue Dec 18 17:21:47 2012
New Revision: 1423539
URL: http://svn.apache.org/viewvc?rev=1423539&view=rev
Log:
Merged revisions 1423535 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1423535 | sergeyb | 2012-12-18 17:18:31 +0000 (Tue, 18 Dec 2012) | 1 line
Minor updates to JPA2 visitor
........
Modified:
cxf/branches/2.6.x-fixes/ (props changed)
cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1423535
Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java?rev=1423539&r1=1423538&r2=1423539&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java (original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPACriteriaQueryVisitor.java Tue Dec 18 17:21:47 2012
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
@@ -62,7 +63,22 @@ public class JPACriteriaQueryVisitor<T,
public CriteriaQuery<E> getQuery() {
return getCriteriaQuery();
}
-
+
+ public Long count() {
+ if (super.getQueryClass() != Long.class) {
+ throw new IllegalStateException("Query class needs to be of type Long");
+ }
+ @SuppressWarnings("unchecked")
+ CriteriaQuery<Long> countQuery = (CriteriaQuery<Long>)getCriteriaQuery();
+ countQuery.select(getCriteriaBuilder().count(getRoot()));
+ return super.getEntityManager().createQuery(countQuery).getSingleResult();
+ }
+
+ public TypedQuery<E> getArrayTypedQuery(List<SingularAttribute<T, ?>> attributes) {
+ CriteriaQuery<E> cQuery = selectArraySelections(toSelectionsArray(toSelectionsList(attributes, false)));
+ return getTypedQuery(cQuery);
+ }
+
public CriteriaQuery<E> selectArray(List<SingularAttribute<T, ?>> attributes) {
return selectArraySelections(toSelectionsArray(toSelectionsList(attributes, false)));
}
@@ -78,6 +94,11 @@ public class JPACriteriaQueryVisitor<T,
return selectConstructSelections(toSelectionsArray(toSelectionsList(attributes, false)));
}
+ public TypedQuery<E> getConstructTypedQuery(List<SingularAttribute<T, ?>> attributes) {
+ CriteriaQuery<E> cQuery = selectConstructSelections(toSelectionsArray(toSelectionsList(attributes, false)));
+ return getTypedQuery(cQuery);
+ }
+
private CriteriaQuery<E> selectConstructSelections(Selection<?>... selections) {
getQuery().select(getCriteriaBuilder().construct(getQueryClass(), selections));
return getQuery();
@@ -87,6 +108,11 @@ public class JPACriteriaQueryVisitor<T,
return selectTupleSelections(toSelectionsArray(toSelectionsList(attributes, true)));
}
+ public TypedQuery<E> getTupleTypedQuery(List<SingularAttribute<T, ?>> attributes) {
+ CriteriaQuery<E> cQuery = selectTupleSelections(toSelectionsArray(toSelectionsList(attributes, true)));
+ return getTypedQuery(cQuery);
+ }
+
private CriteriaQuery<E> selectTupleSelections(Selection<?>... selections) {
@SuppressWarnings("unchecked")
CompoundSelection<E> selection =
@@ -109,4 +135,7 @@ public class JPACriteriaQueryVisitor<T,
return selections.toArray(new Selection[]{});
}
+ private TypedQuery<E> getTypedQuery(CriteriaQuery<E> theCriteriaQuery) {
+ return super.getEntityManager().createQuery(theCriteriaQuery);
+ }
}
Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java?rev=1423539&r1=1423538&r2=1423539&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java (original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java Tue Dec 18 17:21:47 2012
@@ -229,6 +229,11 @@ public class JPATypedQueryVisitorTest ex
}
@Test
+ public void testEqualsCriteriaQueryCount() throws Exception {
+ assertEquals(1L, criteriaQueryBooksCount("id==10"));
+ }
+
+ @Test
public void testEqualsCriteriaQueryConstruct() throws Exception {
List<BookInfo> books = criteriaQueryBooksConstruct("id==10");
assertEquals(1, books.size());
@@ -439,6 +444,15 @@ public class JPATypedQueryVisitorTest ex
return em.createQuery(cquery).getResultList();
}
+ private long criteriaQueryBooksCount(String expression) throws Exception {
+ SearchCondition<Book> filter =
+ new FiqlParser<Book>(Book.class).parse(expression);
+ JPACriteriaQueryVisitor<Book, Long> jpa =
+ new JPACriteriaQueryVisitor<Book, Long>(em, Book.class, Long.class);
+ filter.accept(jpa);
+ return jpa.count();
+ }
+
private List<BookInfo> criteriaQueryBooksConstruct(String expression) throws Exception {
SearchCondition<Book> filter =
new FiqlParser<Book>(Book.class).parse(expression);
@@ -469,10 +483,7 @@ public class JPATypedQueryVisitorTest ex
selections.add(Book_.id);
selections.add(Book_.title);
- jpa.selectArray(selections);
-
- CriteriaQuery<Object[]> cquery = jpa.getQuery();
- return em.createQuery(cquery).getResultList();
+ return jpa.getArrayTypedQuery(selections).getResultList();
}
public static class BookInfo {