Search in sources :

Example 1 with JPACriteriaQueryVisitor

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;
}
Also used : PersonInfo(common.advanced.PersonInfo) JPACriteriaQueryVisitor(org.apache.cxf.jaxrs.ext.search.jpa.JPACriteriaQueryVisitor) ArrayList(java.util.ArrayList) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Person(common.advanced.Person) Tuple(javax.persistence.Tuple)

Aggregations

Person (common.advanced.Person)1 PersonInfo (common.advanced.PersonInfo)1 ArrayList (java.util.ArrayList)1 Tuple (javax.persistence.Tuple)1 SingularAttribute (javax.persistence.metamodel.SingularAttribute)1 JPACriteriaQueryVisitor (org.apache.cxf.jaxrs.ext.search.jpa.JPACriteriaQueryVisitor)1