Hi Joacim,
I think the best way to do the thing you are trying to do is to use
LargeSelect
it provides more functionality than just number of rows limitation.
It gives you the paged tables that almost every weblication needs.
Actually using LargeSelect you are not responsible for the SQL statement
/( Criteria preparation) for limiting the rows anymore.
I am using it and it is quite good ..in fact it has all that I need.
1) display single page of a db table (example 10 rows)
2) display the navigation info (example "page 3 of 10 total")
3) and of course methods for first/prev/next/last pages
4) the LargeSelect class provides customization of the number of rows to be
fetched..and numbers of rows to be displayed in a single page
example from my code: (there is some of my local logic ..like weblication
action object ..but i think you will get the idea of using the LargeSelect
object)
load the data:
private static final int PAGE_SIZE = 10; // maximum page size
private static final int PAGES_FETCH_COUNT = 10; // pages to be loaded on
time
private void LoadLargeSelect(Criteria parameter) {
largeSelect = new LargeSelect(parameter, PAGE_SIZE, PAGES_FETCH_COUNT,
CsVpbxPeer.class.getName());
try {
largeSelect.getNextResults();
}
catch (Exception e) {
logError(e);
}
}
weblication actions interpret:
if (action.equals(Action.COMMON_LIST_FIRST_PAGE)) {
businessObjectList = largeSelect.getPage(1);
}
else if (action.equals(Action.COMMON_LIST_LAST_PAGE)) {
businessObjectList =
largeSelect.getPage(largeSelect.getTotalPages());
}
else if (action.equals(Action.COMMON_LIST_NEXT_PAGE)) {
businessObjectList = largeSelect.getNextResults();
}
else if (action.equals(Action.COMMON_LIST_PREV_PAGE)) {
businessObjectList = largeSelect.getPreviousResults();
}
else {
largeSelect.invalidateResult();
businessObjectList = largeSelect.getPage(1);
}
I am not sure that it is what you need but is a good start point.
With best regards,
Bogdan Vatkov
----- Original Message -----
From: "Joacim Turesson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 09, 2004 11:35 AM
Subject: [Newbie] Getting limited number of rows
> Hi!
>
>
>
> I'm using Torque and it works fine:-)
>
>
>
> I'm working with a webbapplication and I want to display a limited
> amount of a data in a list.
>
>
>
> How do I get a limited number of rows, and still knows how many total
> number of rows there exist?
>
>
>
> As I understand:
>
> * setOffset indicates from where I start (zero based)
> * setLimit indicates how many rows from the offset I get
>
>
>
> Do I have to do a select count statement with the criteria above without
> offset and limit to get the total number of rows?
>
> Or is it a better way?
>
>
>
> Best Regards
>
>
>
> Joacim Turesson
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]