You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Aradiusz Milewski <ar...@gmail.com> on 2014/12/01 11:05:39 UTC
SelectQuery with setPageSize
Hi
I have a SelectQuery with setPageSize. After running this query i would
like to know on which index is specific object in this list, without
fetching full list of objects into memory. Is it possible to do it using
Cayenne API ?
Thanks
Arek
Re: SelectQuery with setPageSize
Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi,
List.indexOf(..) is a linear search (unless the list is known to be ordered and you can use binary search). So on average such lookup would resolve ~50% of the objects.
Another way is to query for this object directly against the DB. Yet another is to do an in-memory check of the object against the original SelectQuery qualifier:
query.getQualifier().match(object);
Neither of the 2 will always be equivalent to List.indexOf(..). After all DB data changes over time, and also SQL and in-memory eval have subtle differences. So make a decision based on the task at hand.
Andrus
> On Dec 1, 2014, at 1:05 PM, Aradiusz Milewski <ar...@gmail.com> wrote:
>
> Hi
>
> I have a SelectQuery with setPageSize. After running this query i would like to know on which index is specific object in this list, without fetching full list of objects into memory. Is it possible to do it using Cayenne API ?
>
> Thanks
> Arek
>