Performance in org.ofbiz.entity.util.EntityListIterator class

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Performance in org.ofbiz.entity.util.EntityListIterator class

Rodrigo Lima-2
Hi community!

This is a my implementation to best performance in pagination using
org.ofbiz.entity.util.EntityListIterator class.

Add this method to get size of resultset without create GenericValue.

* public int getSize()throws GenericEntityException {*
*        int result = 0;*
*        try{*
*               if( resultSet.last() )*
*                   result = resultSet.getRow();*

*        }  catch (SQLException e) {*
*              Debug.logWarning("Warning: No calculate EntityListIterator
size because of exception: " + e.toString(), module);*
*        }*

*        return result;*
*    }*
Reply | Threaded
Open this post in threaded view
|

Re: Performance in org.ofbiz.entity.util.EntityListIterator class

David E Jones

I'm not sure where this fits into a larger process or what intention is, but there is a more efficient way that involves minimal data coming back from the database when you only need a count and don't need and of the data. For that see the GenericDelegator.findCountByAnd or findCountByCondition methods.

-David


Rodrigo Souza wrote:

> Hi community!
>
> This is a my implementation to best performance in pagination using
> org.ofbiz.entity.util.EntityListIterator class.
>
> Add this method to get size of resultset without create GenericValue.
>
> * public int getSize()throws GenericEntityException {*
> *        int result = 0;*
> *        try{*
> *               if( resultSet.last() )*
> *                   result = resultSet.getRow();*
>
> *        }  catch (SQLException e) {*
> *              Debug.logWarning("Warning: No calculate EntityListIterator
> size because of exception: " + e.toString(), module);*
> *        }*
>
> *        return result;*
> *    }*
>
Reply | Threaded
Open this post in threaded view
|

Re: Performance in org.ofbiz.entity.util.EntityListIterator class

Rodrigo Lima-2
Hi Mrs,

GenericDelegator.findCountByAnd is high cost.

One example:

 // do the lookup
            if (mainCond != null || "Y".equals(showAll)) {
                try {
                    // set distinct on so we only get one row per order
                    EntityFindOptions findOpts = new EntityFindOptions(true,
EntityFindOptions.TYPE_SCROLL_INSENSITIVE,
EntityFindOptions.CONCUR_READ_ONLY, true);
                    // using list iterator
                    EntityListIterator pli =
delegator.findListIteratorByCondition(dynamicView, mainCond, null,
fieldsToSelect, orderBy, findOpts);

                    // get the indexes for the partial list
                    lowIndex = (((viewIndex - 1) * viewSize) + 1);
                    highIndex = viewIndex * viewSize;

                    // get the partial list for this page
                    partyList = pli.getPartialList(lowIndex, viewSize);

                   **********************************************************
*

*                    /**/ attempt to get the full size
   FROM       pli.last();
                    partyListSize = pli.currentIndex();
                    if (highIndex > partyListSize) {
                        highIndex = partyListSize;
                    }*

*                 **********************************************************
*

*                  // attempt to get the full size
   TO
                    partyListSize = pli.getSize();*

*
                    if (highIndex > partyListSize) {
                        highIndex = partyListSize;
                    }*

                    // close the list iterator
                    pli.close();
                } catch (GenericEntityException e) {
                    String errMsg = "Failure in party find operation,
rolling back transaction: " + e.toString();
                    Debug.logError(e, errMsg, module);
                    return ServiceUtil.returnError(errMsg);
                }
            } else {
                partyListSize = 0;
            }


2007/6/26, David E Jones <[hidden email]>:

>
>
> I'm not sure where this fits into a larger process or what intention is,
> but there is a more efficient way that involves minimal data coming back
> from the database when you only need a count and don't need and of the data.
> For that see the GenericDelegator.findCountByAnd or findCountByCondition
> methods.
>
> -David
>
>
> Rodrigo Souza wrote:
> > Hi community!
> >
> > This is a my implementation to best performance in pagination using
> > org.ofbiz.entity.util.EntityListIterator class.
> >
> > Add this method to get size of resultset without create GenericValue.
> >
> > * public int getSize()throws GenericEntityException {*
> > *        int result = 0;*
> > *        try{*
> > *               if( resultSet.last() )*
> > *                   result = resultSet.getRow();*
> >
> > *        }  catch (SQLException e) {*
> > *              Debug.logWarning("Warning: No calculate
> EntityListIterator
> > size because of exception: " + e.toString(), module);*
> > *        }*
> >
> > *        return result;*
> > *    }*
> >
>