org.hdpagination.dataaccess.support.orm
Interface QueryResultProcessor


public interface QueryResultProcessor

An interface used by HBN3QueryCallbackWrapper, HBN3QueryCallbackNamedParamWrapper, JPAQueryCallbackWrapper and JPAQueryCallbackNamedParamWrapper to process the query result (java.util.List) before Session or EntityManager is closed. The query result usually comes from calling the method javax.persistence.Query.getResultList() or org.hibernate.Query.list(). Quite often, you need to trigger lazy loading before Session (Hibernate) or EntityManager (JPA) is closed. This interface is mainly for this purpose.

The following code shows the way of triggering JPA Lazy Loading::

   JPAQueryCallbackWrapper callback = JPAQueryCallbackWrapper.newInstance("select p from ProductVO p", "p")
       .addRestriction( Restrictions.eq("p.prodNo", crit.getProdNo()) )
       .addRestriction( Restrictions.in("p.madeIn", crit.getMadeIn()) )
       .addRestriction( Restrictions.contains("p.description", crit.getDescription()) )
       .addRestriction( Restrictions.range("p.price", priceFrom, priceTo))
       .setOrderBy("p.madeIn");
      
   callback.setQueryResultProcessor( new QueryResultProcessor() {
         public List process(List queriedResult) {
               for (int i=0;i<queriedResult.size();i++) {
                     ProductVO prod = (ProductVO)queriedResult.get(i);
                     //initialise lazy loading here ......
               }
               return queriedResult;
         }
      });

Since:
1.3.2
Author:
Liangfeng Ren

Method Summary
 java.util.List process(java.util.List queriedResult)
          Process the query result (java.util.List) before Session or EntityManager is closed.
 

Method Detail

process

java.util.List process(java.util.List queriedResult)
Process the query result (java.util.List) before Session or EntityManager is closed. Mainly for triggering lazy loading.

Parameters:
queriedResult - It usually comes from calling the method javax.persistence.Query.getResultList() or org.hibernate.Query.list()
Returns:
you need to return the processed list. This returned list will be finally used in the UI side.


Copyright © 2008 HDPagination All Rights Reserved.