use of org.apache.cxf.jaxrs.ext.search.jpa.JPACriteriaQueryVisitor in project tesb-rt-se by Talend.
the class PersonInfoStorage method getTypedQueryTuple.
public List<PersonInfo> getTypedQueryTuple(SearchContext context, String expression) {
// Get search condition encapsulating the query expression
SearchCondition<Person> filter = getSearchCondition(context, expression);
// Initialise JPA2 visitor which can convert the captured search expression
// into JPA2 TypedQuery
JPACriteriaQueryVisitor<Person, Tuple> jpa = new JPACriteriaQueryVisitor<Person, Tuple>(em, Person.class, Tuple.class);
// Convert
filter.accept(jpa);
// Shape the response data with selections and Tuple
List<SingularAttribute<Person, ?>> selections = new ArrayList<SingularAttribute<Person, ?>>();
selections.add(Person_.id);
jpa.selectTuple(selections);
// Get CriteriaQuery and create TypedQuery
CriteriaQuery<Tuple> cquery = jpa.getQuery();
TypedQuery<Tuple> typedQuery = em.createQuery(cquery);
// Run the query
List<Tuple> tuples = typedQuery.getResultList();
// Return the results
List<PersonInfo> infos = new ArrayList<PersonInfo>(tuples.size());
for (Tuple tuple : tuples) {
infos.add(new PersonInfo(tuple.get(Person_.id.getName(), Long.class)));
}
return infos;
}
Aggregations