You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by John Chien <jo...@ncmail.net> on 2006/04/12 16:53:59 UTC

pager in ibatis

Dear sir:

I have a feature that requires me to return query result of a selection 
statment in certain amount of successive records every time.
This is just like a page.

For example:

SELECT  id, name
FROM employee;

The selection result of this statement is a list.
However, I want to only get 30 records every time.
For the first call, I want to get the first 30 (1 - 30) records, for 
thext call, I would like to get the next 30 (31 - 60) records.

How can I do this in Ibatis ?

Thanks,

John Chien

Re: what does the PaginatedList method means ?

Posted by Zarar Siddiqi <za...@utoronto.ca>.
All the questions you are asking can be easily answered by writing some code 
and playing around with paginated lists for about fifteen minutes.  Maybe 
you should consider using DisplayTag instead of paginated lists since that 
will make your life easier and you won't have to worry about writing Java 
code to handle paging.  Using either method carries approximately the same 
performance hit.  As mentioned earlier, if performance is your goal, write 
vendor specific SQL code to return smaller result sets.

Zarar


----- Original Message ----- 
From: "John Chien" <jo...@ncmail.net>
To: <us...@ibatis.apache.org>
Sent: Wednesday, April 12, 2006 3:19 PM
Subject: what does the PaginatedList method means ?


> Dear Sir:
>
> After we called the iBatis queryForPaginatedList(), we get a list of
> type PaginatedList.
> Let us call it queryResultList;
> The PaginatedList has several methods like:
>
> void gotoPage(int i);
> boolean nextPage();
> boolean previosPage();
>
> What does these methods mean ?
> What I want is to get a list to be returned to client side to be 
> displayed.
> Let us call it toBeDisplayList;
>
>
> 1) I want to go to page 5, so I write the following statement
>
> queryResultList.getoPage(5);  What does this mean ?
>
> Suppose the queryResultList have 600 element originally, and each page
> display 30 elements,
> after calling queryResultList.getoPage(5) , does the queryResultList
> become a subList that begins with the 121th element ?
>
> 2) I am in page 1, and I want to go to next page
>
> boolean ok = queryResultList.nextPage();
> The ok is true.
>
> Does the queryResultList become the sublist that begins from 31th element 
> ?
>
> Do I need to call a subList method to return a sublist that I want to
> display ?
>
> Thanks,
>
> John Chien
>
>
>
>
>
>
> 



what does the PaginatedList method means ?

Posted by John Chien <jo...@ncmail.net>.
Dear Sir:

After we called the iBatis queryForPaginatedList(), we get a list of 
type PaginatedList.
Let us call it queryResultList;
The PaginatedList has several methods like:

void gotoPage(int i);
boolean nextPage();
boolean previosPage();

What does these methods mean ?
What I want is to get a list to be returned to client side to be displayed.
Let us call it toBeDisplayList;


1) I want to go to page 5, so I write the following statement
   
queryResultList.getoPage(5);  What does this mean ?

Suppose the queryResultList have 600 element originally, and each page 
display 30 elements,
after calling queryResultList.getoPage(5) , does the queryResultList 
become a subList that begins with the 121th element ?

2) I am in page 1, and I want to go to next page

boolean ok = queryResultList.nextPage();
The ok is true.

Does the queryResultList become the sublist that begins from 31th element ?

Do I need to call a subList method to return a sublist that I want to 
display ?

Thanks,

John Chien


 




Re: pager in ibatis

Posted by Larry Meadors <lm...@apache.org>.
Agreed.

Larry


On 4/12/06, Zarar Siddiqi <za...@utoronto.ca> wrote:
> The queryForPaginatedList() retrieves all the records from the database and
> simply then returns a subList based on whatever you've set via
> gotoPage/nextPage and the page size.  So yes, you have to pass in pageSize
> every time and then set the appropriate page via gotoPage(), nextPage() or
> previousPage() each time.  It's somewhat a manual process.
>
> If this is a large query, I'd actually recommend just writing the SQL which
> efficiently gets the correct set of records that you want.  (E.g: LIMIT in
> MySQL or TOP in SQL Server)
>
> Zarar Siddiqi
>
>
> ----- Original Message -----
> From: "John Chien" <jo...@ncmail.net>
> To: <us...@ibatis.apache.org>
> Sent: Wednesday, April 12, 2006 12:26 PM
> Subject: Re: pager in ibatis
>
>
> > L:arry:
> >
> > Thank you for the information.
> > The queryForPaginatedList() will return a list, then I can check for the
> > existence of successive records by calling the isNextPageAvailable().
> > and go to that page by calling  gotoPage();
> >
> > However, I can not keep this list in my server due to concurrecy reason.
> > Does that mean that I have to call the same method every time and  give
> > it the page number for it to return me the records ?
> >
> > I am doing the web development.
> > How can I make use of this returned list in JSP with Struct development ?
> >
> > Should I keep the list in the session or request scope ?
> >
> > Thanks,
> >
> > John Chien
> >
> > Larry Meadors wrote:
> >
> >>queryForPaginatedList()
> >>
> >>Larry
> >>
> >>
> >>On 4/12/06, John Chien <jo...@ncmail.net> wrote:
> >>
> >>
> >>>Dear sir:
> >>>
> >>>I have a feature that requires me to return query result of a selection
> >>>statment in certain amount of successive records every time.
> >>>This is just like a page.
> >>>
> >>>For example:
> >>>
> >>>SELECT  id, name
> >>>FROM employee;
> >>>
> >>>The selection result of this statement is a list.
> >>>However, I want to only get 30 records every time.
> >>>For the first call, I want to get the first 30 (1 - 30) records, for
> >>>thext call, I would like to get the next 30 (31 - 60) records.
> >>>
> >>>How can I do this in Ibatis ?
> >>>
> >>>Thanks,
> >>>
> >>>John Chien
> >>>
> >>>
> >>>
> >>>
> >>>
> >
>
>
>

Re: pager in ibatis

Posted by John Chien <jo...@ncmail.net>.
Actually, the page size will always be the same.
The trouble for me is do I have to do the query to get the whole list 
again before I can return any sublist that I want to display ?
Will I be able to skip the query to get the whole list part by saving 
the list in the session scope ?

If the returned list is too big, is it good to do so ?

Zarar Siddiqi wrote:

> The queryForPaginatedList() retrieves all the records from the 
> database and simply then returns a subList based on whatever you've 
> set via gotoPage/nextPage and the page size.  So yes, you have to pass 
> in pageSize every time and then set the appropriate page via 
> gotoPage(), nextPage() or previousPage() each time.  It's somewhat a 
> manual process.
>
> If this is a large query, I'd actually recommend just writing the SQL 
> which efficiently gets the correct set of records that you want.  
> (E.g: LIMIT in MySQL or TOP in SQL Server)
>
> Zarar Siddiqi
>
>
> ----- Original Message ----- From: "John Chien" <jo...@ncmail.net>
> To: <us...@ibatis.apache.org>
> Sent: Wednesday, April 12, 2006 12:26 PM
> Subject: Re: pager in ibatis
>
>
>> L:arry:
>>
>> Thank you for the information.
>> The queryForPaginatedList() will return a list, then I can check for the
>> existence of successive records by calling the isNextPageAvailable().
>> and go to that page by calling  gotoPage();
>>
>> However, I can not keep this list in my server due to concurrecy reason.
>> Does that mean that I have to call the same method every time and  give
>> it the page number for it to return me the records ?
>>
>> I am doing the web development.
>> How can I make use of this returned list in JSP with Struct 
>> development ?
>>
>> Should I keep the list in the session or request scope ?
>>
>> Thanks,
>>
>> John Chien
>>
>> Larry Meadors wrote:
>>
>>> queryForPaginatedList()
>>>
>>> Larry
>>>
>>>
>>> On 4/12/06, John Chien <jo...@ncmail.net> wrote:
>>>
>>>
>>>> Dear sir:
>>>>
>>>> I have a feature that requires me to return query result of a 
>>>> selection
>>>> statment in certain amount of successive records every time.
>>>> This is just like a page.
>>>>
>>>> For example:
>>>>
>>>> SELECT  id, name
>>>> FROM employee;
>>>>
>>>> The selection result of this statement is a list.
>>>> However, I want to only get 30 records every time.
>>>> For the first call, I want to get the first 30 (1 - 30) records, for
>>>> thext call, I would like to get the next 30 (31 - 60) records.
>>>>
>>>> How can I do this in Ibatis ?
>>>>
>>>> Thanks,
>>>>
>>>> John Chien
>>>>
>>>>
>>>>
>>>>
>>>>
>>
>
>

Re: pager in ibatis

Posted by Zarar Siddiqi <za...@utoronto.ca>.
The queryForPaginatedList() retrieves all the records from the database and 
simply then returns a subList based on whatever you've set via 
gotoPage/nextPage and the page size.  So yes, you have to pass in pageSize 
every time and then set the appropriate page via gotoPage(), nextPage() or 
previousPage() each time.  It's somewhat a manual process.

If this is a large query, I'd actually recommend just writing the SQL which 
efficiently gets the correct set of records that you want.  (E.g: LIMIT in 
MySQL or TOP in SQL Server)

Zarar Siddiqi


----- Original Message ----- 
From: "John Chien" <jo...@ncmail.net>
To: <us...@ibatis.apache.org>
Sent: Wednesday, April 12, 2006 12:26 PM
Subject: Re: pager in ibatis


> L:arry:
>
> Thank you for the information.
> The queryForPaginatedList() will return a list, then I can check for the
> existence of successive records by calling the isNextPageAvailable().
> and go to that page by calling  gotoPage();
>
> However, I can not keep this list in my server due to concurrecy reason.
> Does that mean that I have to call the same method every time and  give
> it the page number for it to return me the records ?
>
> I am doing the web development.
> How can I make use of this returned list in JSP with Struct development ?
>
> Should I keep the list in the session or request scope ?
>
> Thanks,
>
> John Chien
>
> Larry Meadors wrote:
>
>>queryForPaginatedList()
>>
>>Larry
>>
>>
>>On 4/12/06, John Chien <jo...@ncmail.net> wrote:
>>
>>
>>>Dear sir:
>>>
>>>I have a feature that requires me to return query result of a selection
>>>statment in certain amount of successive records every time.
>>>This is just like a page.
>>>
>>>For example:
>>>
>>>SELECT  id, name
>>>FROM employee;
>>>
>>>The selection result of this statement is a list.
>>>However, I want to only get 30 records every time.
>>>For the first call, I want to get the first 30 (1 - 30) records, for
>>>thext call, I would like to get the next 30 (31 - 60) records.
>>>
>>>How can I do this in Ibatis ?
>>>
>>>Thanks,
>>>
>>>John Chien
>>>
>>>
>>>
>>>
>>>
> 



Re: pager in ibatis

Posted by John Chien <jo...@ncmail.net>.
L:arry:

Thank you for the information.
The queryForPaginatedList() will return a list, then I can check for the 
existence of successive records by calling the isNextPageAvailable().
and go to that page by calling  gotoPage();

However, I can not keep this list in my server due to concurrecy reason.
Does that mean that I have to call the same method every time and  give 
it the page number for it to return me the records ?

I am doing the web development.
How can I make use of this returned list in JSP with Struct development ?

Should I keep the list in the session or request scope ?

Thanks,

John Chien

Larry Meadors wrote:

>queryForPaginatedList()
>
>Larry
>
>
>On 4/12/06, John Chien <jo...@ncmail.net> wrote:
>  
>
>>Dear sir:
>>
>>I have a feature that requires me to return query result of a selection
>>statment in certain amount of successive records every time.
>>This is just like a page.
>>
>>For example:
>>
>>SELECT  id, name
>>FROM employee;
>>
>>The selection result of this statement is a list.
>>However, I want to only get 30 records every time.
>>For the first call, I want to get the first 30 (1 - 30) records, for
>>thext call, I would like to get the next 30 (31 - 60) records.
>>
>>How can I do this in Ibatis ?
>>
>>Thanks,
>>
>>John Chien
>>
>>
>>
>>    
>>

Re: pager in ibatis

Posted by Larry Meadors <lm...@apache.org>.
queryForPaginatedList()

Larry


On 4/12/06, John Chien <jo...@ncmail.net> wrote:
> Dear sir:
>
> I have a feature that requires me to return query result of a selection
> statment in certain amount of successive records every time.
> This is just like a page.
>
> For example:
>
> SELECT  id, name
> FROM employee;
>
> The selection result of this statement is a list.
> However, I want to only get 30 records every time.
> For the first call, I want to get the first 30 (1 - 30) records, for
> thext call, I would like to get the next 30 (31 - 60) records.
>
> How can I do this in Ibatis ?
>
> Thanks,
>
> John Chien
>
>
>