Thursday, July 5, 2007

Can I Has Cursor?

There is something like a cursor in ofbiz. It is known as an EntityListIterator. When you do findAll or findByAnd() on an entity, it returns a list into memory and if the result set is too large, you will have performance problems. That is, if you consider death to be a performance problem. Instead of a List, you can get the equivalent of a cursor that you can loop through and retrieve your data. EntityListIterators only work "byCondition". That is, you have to write the command differently.

personList = delegator.findByAnd("Person", utilMisc.toMap("lastName","Smith"));

would become

EntityExpr entityExpr = new EntityExpr("lastName",EntityOperator.EQUALS "Smith");
personELI = delegator.findListIteratorByCondition("Person",entityExpr);