So you need two queries in your data layer, one which returns a subset 
of the query results for the particular page, and one which returns the 
size of the potential result set (i.e. COUNT(*)).

There's no other way to implement this sensibly.

For Hibernate Criteria queries, this can look like this:

criteria.setProjection(Projections.rowCount()).uniqueResult();

I also have a HibernateIterator which will take a criteria and give you 
a ScrollableResults, so if your database supports cursors properly then 
you don't even need to load all the results for a single page at once 
(not that this should generally be an issue).

I then have a class that implements IDataProvider and does the above.

Regards,

Al

V. Jenks wrote:
> I prefer not to do it that way because it requires a potentially large list
> of records to be pulled up initially whereas now, I'm only pulling the
> records on the current page, making it much faster.  I pass the x & y right
> through to the data access layer.
> 
> 
> Johan Compagner wrote:
>> this only works if you have a seperate method:
>>
>> private List getOrders()
>> {
>>   if (orders == null)
>>   {
>>           orders = DAO.getOrders()
>>   }
>> }
>>
>> iterator()
>> {
>>    return getOrders().sublist(x,y).iterator()
>> }
>>
>>
>> size()
>> {
>>   return getOrders().size();
>> }
>>
>> detach()
>> {
>>   orders = null;
>> }
>>
>> johan
>>
>> On 5/29/07, V. Jenks <[EMAIL PROTECTED]> wrote:
>>>
>>> I'm trying to use a provider class for a DataView so I can do
>>> paging/sorting,
>>> etc.  It looks like this:
>>>
>>> ************************************************
>>> public class OrderProvider implements IDataProvider
>>> {
>>>         private transient List<Order> orders;
>>>
>>>         public OrderProvider()
>>>         {
>>>         }
>>>
>>>         public Iterator iterator(int first, int count)
>>>         {
>>>                 this.orders =
>>> WicketHelper.<List<Order>>getDetachedModelObject(
>>>                                 OrderProxy.getAll(first, first + count));
>>>
>>>                 return this.orders.iterator();
>>>         }
>>>
>>>         public IModel model(Object model)
>>>         {
>>>                 return WicketHelper.getDetachedModel(model);
>>>         }
>>>
>>>         public int size()
>>>         {
>>>                 return this.orders.size();
>>>         }
>>> }
>>> ************************************************
>>>
>>> I thought this would work but it looks like size() is called first, since
>>> I
>>> get a NPE:
>>>
>>> ************************************************
>>> Caused by: java.lang.NullPointerException
>>>         at com.myapp.provider.OrderProvider.size(OrderProvider.java:36)
>>> ************************************************
>>>
>>> It works if size() makes a call to the database to get a count of
>>> records...but I'm trying to use a global field to prevent that data call.
>>>
>>> Any suggestions?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Chicken-and-egg-w--Data-Provider-tf3834369.html#a10855464
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> -------------------------------------------------------------------------
>>> This SF.net email is sponsored by DB2 Express
>>> Download DB2 Express C - the FREE version of DB2 express and take
>>> control of your XML. No limits. Just data. Click to get it now.
>>> http://sourceforge.net/powerbar/db2/
>>> _______________________________________________
>>> Wicket-user mailing list
>>> Wicket-user@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/wicket-user
>>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by DB2 Express
>> Download DB2 Express C - the FREE version of DB2 express and take
>> control of your XML. No limits. Just data. Click to get it now.
>> http://sourceforge.net/powerbar/db2/
>> _______________________________________________
>> Wicket-user mailing list
>> Wicket-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/wicket-user
>>
>>
> 


-- 
Alastair Maw
Wicket-biased blog at http://herebebeasties.com

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to