I'm used to execute two queries (count + select) for each stament in this
kind of situations.
The code is hidden in the DAOs, so the business/web layers are not aware of
the strategy.

The following is the generic method I use:

private List executePagedQuery(Object params, int offset,
                 int limit, boolean countResults, String query, String
countQuery) {

        List l = super.getList(query, params, offset, limit);
        if (countResults) {
            Integer size = (Integer) super.getObject(countQuery, params);
            ListWrapper wrapper = new ListWrapper(l, size);
            return wrapper;
        } else {
            return l;
        }
    }

"ListWrapper" is a simple java.util.List wrapper that espose a constructor,
used to inject the maximum number of results, which PaginatedList doesn't
expose.

I think you should put the two queries in the same transaction, also.

Regards,
Fabrizio

-----Messaggio originale-----
Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Inviato: venerdì 18 marzo 2005 12.13
A: ibatis-user-java@incubator.apache.org
Oggetto: PaginatedList & 'google like' results


Hi,

I am using ibatis PaginatedList functionality for paging through search
results,
and I would like to add the ability for a user to go to the last page of the
results
(something like Google results) instead of having to page through big result
sets as
it is done in JPetStore4:

  <logic:notEqual name="orderBean" property="orderList.firstPage"
value="true" >
    <a href="switchOrderPage.shtml?pageDirection=previous">PREV</a>
  </logic:notEqual>
  <logic:notEqual name="orderBean" property="orderList.lastPage"
value="true" >
    <a href="switchOrderPage.shtml?pageDirection=next">NEXT</a>
  </logic:notEqual>

Is this possible or should I do two queries (my actual "select fields
from..."
and a new "select count(*) from...") to achieve it?

Thank you very much,
Guido.

--
Guido García Bernardo - [EMAIL PROTECTED]
Tfn. +34 983 54 89 08
ITDEUSTO - Valladolid


Reply via email to