Hi. I was taking a look at how to indicate an offset into my findList
queries and I stumbled upon a quite disturbing behavior within ofbiz and I
would like to ask why it was design like that.
I was taking a look at the service 'performFindList' (in
org.ofbiz.common.FindServices of rev 686591) to see how it does paginating.
Heres a snippet of the code and how I understood the code:

// service calls performFind method to get an instance of EntityListIterator
(line 358)
        Map result = performFind(dctx,context);
        ...
// retrieve the target range of values from the EntityListIterator (lines
369 and 370)
        EntityListIterator it = (EntityListIterator) result.get("listIt");
        list = it.getPartialList(start+1, viewSize.intValue());
        ...
// return the partial list as the result of the service
        result.put("list",list);

Further inspecting how EntityListIterator retrieves the partial list, heres
a snippet of the method getPartialList from the class
org.ofbiz.entity.util.EntityListIterator (of rev 673024) and how I
understood the code:

// attempts to move resultSet pointer to the desired offset (line 457)
         if (!resultSet.absolute(start)) {
         ....
// calls resultset.next() to get the values until it has retrieved the
desired size or there is nothing more to get from the resultSet (lines
472-475)
        while (number > numRetreived && (nextValue = this.next()) != null) {
            list.add(nextValue);
            numRetreived++;
        }

This is what I understood from the codes mentioned:
1. The resultSet returns all of the rows as qualified by the prepared
statement.
2. Paging is done by selecting only the target rows.

Implications:
1. The query will always retrieve the all of the rows regardless of the
viewSize and viewIndex.
2. Traversing from each pages would mean retrieving the all of the rows
everytime a page is loaded.

I think this puts alot of unnecessary load into the application when some of
it could be performed within the database level. It was also the reason why
I was looking for a way to put in 'offset' within the query.
Anyways please do comment on my observation. Please correct me if I
misunderstood the code.
Thanks.


~ ian

Reply via email to