Hi
Please see comments below:
On 20/06/13 11:59, nikosdim wrote:
Hi all
I have a rest WS with CXF and I have implemented the FIQL
<http://cxf.apache.org/docs/jax-rs-search.html#JAX-RSSearch-BuildingFIQLqueries>
along with JPA using EclipseLink.
I am using the JPATypedQueryVisitor to get a TypedQuery and interact with
the database.
FIQL queries work well but I want to find a way to be able to choose which
columns to retrieve from the database.
For example lets say tha we have a table called "Employee" with the columns
"firstname", "lastname", "age"
with the FIQL ?_s=age==25 i will get back using the TypedQuery<Employee> a
list of Employee objects
with all the attributes, "firstname", "lastname", "age" filled with info.
The sql equivalent would be
"select * from Employee where age=25"
How can I choose to get back from the database only specific columns e.g.
"firstname"? The asql equivalent
"select firstname from employee where age=25"
Here is my code
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("default");
EntityManager em = emf.createEntityManager();
SearchCondition<Employee> sc = searchContext
.getCondition(Employee.class);
SearchConditionVisitor<Employee, TypedQuery<Employee>> visitor = new
JPATypedQueryVisitor<Employee>(
em, Employee.class, beanPropertiesMap);
sc.accept(visitor);
TypedQuery<Employee> typedQuery = visitor.getQuery();
typedQuery = typedQuery.setMaxResults(Integer.parseInt(returnNo));
employees.setEmployees(typedQuery.getResultList());
I think you need to work with CriteriaQuery and specifically with
JPACriteriaQueryVisitor, which has the utility methods for applying
various selection criteria, for example, the code from one of the tests:
SearchCondition<Book> filter = new
FiqlParser<Book>(Book.class).parse(expression);
JPACriteriaQueryVisitor<Book, Book> jpa =
new JPACriteriaQueryVisitor<Book, Book>(em, Book.class, Book.class);
filter.accept(jpa);
List<SingularAttribute<Book, ?>> selections =
new ArrayList<SingularAttribute<Book, ?>>();
selections.add(Book_.id);
TypedQuery tquery = jpa.getOrderedTypedQuery(selections, asc);
List<Book> books = tquery.getResultList();
Have a look at the examples at the end of:
http://cxf.apache.org/docs/jax-rs-search.html#JAX-RSSearch-JPA2.0
Does it help ?
Sergey
Thanks in advance
--
View this message in context:
http://cxf.547215.n5.nabble.com/How-to-select-specific-columns-to-retrieve-with-FIQL-using-JPATypedQueryVisitor-tp5729548.html
Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com