You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Gary Jarrel <ga...@gmail.com> on 2010/06/30 03:08:57 UTC

Testing for Pagination

Hi Guys,

If I have a small application I am working on which is a DAO like
interface to Cayenne to simplify access to the database to one call.

Currently I am working with paginated queries, and what I wanted to
know is if I execute a paginated query how does one write a test case
to verify that the query was actually paginated. Eg. In a 10 record
page how do you ascertain that the first 10 records have been
completely retrieved and the others just the IDs.

I though I'd ask given that it's a simple question before I start
diving into the Cayenne source code.

Thank you

Gary

Re: Testing for Pagination

Posted by Gary Jarrel <ga...@gmail.com>.
On Wed, Jun 30, 2010 at 11:42 AM, Aristedes Maniatis <ar...@ish.com.au> wrote:

> Records after the first 10 will have a status of "hollow".
>
> Ari
>

Thank you Ari

Re: Testing for Pagination

Posted by Andrus Adamchik <an...@objectstyle.org>.
Via a cast.

On Jun 30, 2010, at 10:07 AM, Gary Jarrel wrote:

> So given the query
>
> SelectQuery s = new SelectQuery(Role.class);
> s.setPageSize(2);
> List<Role> results = getDataContext().performQuery(s);
>
> How can I use the PersistentObjectList ???
>
> Thank you
>
> Gary
>
> On Wed, Jun 30, 2010 at 4:24 PM, Andrus Adamchik <andrus@objectstyle.org 
> > wrote:
>> Exactly. Essentially it is "List.get(int)" method that loads the  
>> page, so
>> once you get an object via this method it is already inflated.
>>
>> Andrus
>>
>> On Jun 30, 2010, at 8:40 AM, Andrey Razumovsky wrote:
>>
>>> For getting unresolved list, you can use
>>> PersistentObjectList.getValueDirectly(), if that helps
>>>
>
> <snip>
>


Re: Testing for Pagination

Posted by Gary Jarrel <ga...@gmail.com>.
So given the query

SelectQuery s = new SelectQuery(Role.class);
s.setPageSize(2);
List<Role> results = getDataContext().performQuery(s);

How can I use the PersistentObjectList ???

Thank you

Gary

On Wed, Jun 30, 2010 at 4:24 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
> Exactly. Essentially it is "List.get(int)" method that loads the page, so
> once you get an object via this method it is already inflated.
>
> Andrus
>
> On Jun 30, 2010, at 8:40 AM, Andrey Razumovsky wrote:
>
>> For getting unresolved list, you can use
>> PersistentObjectList.getValueDirectly(), if that helps
>>

<snip>

Re: Testing for Pagination

Posted by Andrus Adamchik <an...@objectstyle.org>.
Exactly. Essentially it is "List.get(int)" method that loads the page,  
so once you get an object via this method it is already inflated.

Andrus

On Jun 30, 2010, at 8:40 AM, Andrey Razumovsky wrote:

> For getting unresolved list, you can use
> PersistentObjectList.getValueDirectly(), if that helps
>
> 2010/6/30 Gary Jarrel <ga...@gmail.com>
>
>> On Wed, Jun 30, 2010 at 1:44 PM, Aristedes Maniatis  
>> <ar...@maniatis.org>
>> wrote:
>>>
>>> If that is happening, then that might be a bug. Could you put  
>>> logging in
>>> there to identify exactly when you see the SQL query inflating the
>> record?
>>> Does it happen right after getPersistenceState()?
>>>
>>
>> I've changed the test case to:
>>
>> List<Role> results = getDataContext().performQuery(s);
>>
>> assertEquals(5, results.size());
>>
>> Role r0 = results.get(0);
>> Role r1 = results.get(1);
>> assertEquals(PersistenceState.COMMITTED, r0.getPersistenceState());
>> assertEquals(PersistenceState.COMMITTED, r1.getPersistenceState());
>>
>> Role r4 = results.get(4);
>> assertEquals(PersistenceState.HOLLOW, r4.getPersistenceState());
>>
>> Stepping though the code with a debugger the following happens:
>>
>> List<Role> results = getDataContext().performQuery(s);
>>
>> Causes:
>>
>> SELECT t0.role_id FROM role t0
>>
>> Role r0 = results.get(0);
>>
>> Causes
>>
>> SELECT t0.name, t0.active, t0.role_id FROM role t0 WHERE  
>> (t0.role_id =
>> ?) OR (t0.role_id = ?) [bind: 1->role_id:1, 2->role_id:2]
>>
>> As you said the whole page is inflated rather than a single object
>>
>> Nothing in the log until:
>>
>> Role r4 = results.get(4);
>>
>> Which causes:
>>
>> SELECT t0.name, t0.active, t0.role_id FROM role t0 WHERE t0.role_id =
>> ? [bind: 1->role_id:5]
>>
>> Hence once this executes the test fails as r4 is not hollow!
>>
>> Gary
>>
>
>
>
> -- 
> Andrey


Re: Testing for Pagination

Posted by Andrey Razumovsky <ra...@gmail.com>.
For getting unresolved list, you can use
PersistentObjectList.getValueDirectly(), if that helps

2010/6/30 Gary Jarrel <ga...@gmail.com>

> On Wed, Jun 30, 2010 at 1:44 PM, Aristedes Maniatis <ar...@maniatis.org>
> wrote:
> >
> > If that is happening, then that might be a bug. Could you put logging in
> > there to identify exactly when you see the SQL query inflating the
> record?
> > Does it happen right after getPersistenceState()?
> >
>
> I've changed the test case to:
>
> List<Role> results = getDataContext().performQuery(s);
>
> assertEquals(5, results.size());
>
> Role r0 = results.get(0);
> Role r1 = results.get(1);
> assertEquals(PersistenceState.COMMITTED, r0.getPersistenceState());
> assertEquals(PersistenceState.COMMITTED, r1.getPersistenceState());
>
> Role r4 = results.get(4);
> assertEquals(PersistenceState.HOLLOW, r4.getPersistenceState());
>
> Stepping though the code with a debugger the following happens:
>
> List<Role> results = getDataContext().performQuery(s);
>
> Causes:
>
> SELECT t0.role_id FROM role t0
>
> Role r0 = results.get(0);
>
> Causes
>
> SELECT t0.name, t0.active, t0.role_id FROM role t0 WHERE (t0.role_id =
> ?) OR (t0.role_id = ?) [bind: 1->role_id:1, 2->role_id:2]
>
> As you said the whole page is inflated rather than a single object
>
> Nothing in the log until:
>
> Role r4 = results.get(4);
>
> Which causes:
>
> SELECT t0.name, t0.active, t0.role_id FROM role t0 WHERE t0.role_id =
> ? [bind: 1->role_id:5]
>
> Hence once this executes the test fails as r4 is not hollow!
>
> Gary
>



-- 
Andrey

Re: Testing for Pagination

Posted by Gary Jarrel <ga...@gmail.com>.
On Wed, Jun 30, 2010 at 1:44 PM, Aristedes Maniatis <ar...@maniatis.org> wrote:
>
> If that is happening, then that might be a bug. Could you put logging in
> there to identify exactly when you see the SQL query inflating the record?
> Does it happen right after getPersistenceState()?
>

I've changed the test case to:

List<Role> results = getDataContext().performQuery(s);

assertEquals(5, results.size());

Role r0 = results.get(0);
Role r1 = results.get(1);
assertEquals(PersistenceState.COMMITTED, r0.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, r1.getPersistenceState());

Role r4 = results.get(4);
assertEquals(PersistenceState.HOLLOW, r4.getPersistenceState());

Stepping though the code with a debugger the following happens:

List<Role> results = getDataContext().performQuery(s);

Causes:

SELECT t0.role_id FROM role t0

Role r0 = results.get(0);

Causes

SELECT t0.name, t0.active, t0.role_id FROM role t0 WHERE (t0.role_id =
?) OR (t0.role_id = ?) [bind: 1->role_id:1, 2->role_id:2]

As you said the whole page is inflated rather than a single object

Nothing in the log until:

Role r4 = results.get(4);

Which causes:

SELECT t0.name, t0.active, t0.role_id FROM role t0 WHERE t0.role_id =
? [bind: 1->role_id:5]

Hence once this executes the test fails as r4 is not hollow!

Gary

Re: Testing for Pagination

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 30/06/10 1:27 PM, Gary Jarrel wrote:
> But it seems that results.get(n) always inflates the object and put it
> into a committed persistence state, hence the test fails.

Can't imagine how the get is doing that.


> Any way to stop the object from inflating when you access it's
> Persistence State.

If that is happening, then that might be a bug. Could you put logging in there to identify exactly when you see the SQL query inflating the record? Does it happen right after getPersistenceState()?


> I can see in the logs that the query has also changed to just select
> the object ID as follows:
>
> SELECT t0.role_id FROM role t0

Yes, that's exactly the point.


Also, your test is not right. An entire page of data will always be inflated at once. So items 0 and 1 in the first query with page size 2. Then 2 and 3 will be pulled together when you try to inflate record 2.

Ari


-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Re: Testing for Pagination

Posted by Gary Jarrel <ga...@gmail.com>.
On Wed, Jun 30, 2010 at 11:42 AM, Aristedes Maniatis <ar...@ish.com.au> wrote:

>
> Records after the first 10 will have a status of "hollow".
>

I've been trying to test for this using:

        SelectQuery s = new SelectQuery(Role.class);
        s.setPageSize(2);
        List<Role> results = getDataContext().performQuery(s);

        assertEquals(5, results.size());

        assertEquals(PersistenceState.COMMITTED,
results.get(0).getPersistenceState());
        assertEquals(PersistenceState.COMMITTED,
results.get(1).getPersistenceState());

        assertEquals(PersistenceState.HOLLOW,
results.get(4).getPersistenceState());
        assertEquals(PersistenceState.HOLLOW,
results.get(3).getPersistenceState());
        assertEquals(PersistenceState.HOLLOW,
results.get(2).getPersistenceState());

But it seems that results.get(n) always inflates the object and put it
into a committed persistence state, hence the test fails.

Any way to stop the object from inflating when you access it's
Persistence State.

I can see in the logs that the query has also changed to just select
the object ID as follows:

SELECT t0.role_id FROM role t0

Thank you

Gary

Re: Testing for Pagination

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 30/06/10 11:08 AM, Gary Jarrel wrote:
> Currently I am working with paginated queries, and what I wanted to
> know is if I execute a paginated query how does one write a test case
> to verify that the query was actually paginated. Eg. In a 10 record
> page how do you ascertain that the first 10 records have been
> completely retrieved and the others just the IDs.

Records after the first 10 will have a status of "hollow".

Ari

-- 
-------------------------->
Aristedes Maniatis
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A