Re: [Wicket-user] Chicken-and-egg w/ Data Provider

2007-05-31 Thread Al Maw
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 ListOrder orders;

 public OrderProvider()
 {
 }

 public Iterator iterator(int first, int count)
 {
 this.orders =
 WicketHelper.ListOrdergetDetachedModelObject(
 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


Re: [Wicket-user] Chicken-and-egg w/ Data Provider

2007-05-30 Thread Johan Compagner

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 ListOrder orders;

public OrderProvider()
{
}

public Iterator iterator(int first, int count)
{
this.orders =
WicketHelper.ListOrdergetDetachedModelObject(
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


Re: [Wicket-user] Chicken-and-egg w/ Data Provider

2007-05-30 Thread kroekle

The size() method was one of my biggest stumbling blocks when I started using
DataProvders, but for slightly different reasons (i.e. just having a size
method makes it less maintainable, perform worse, less scalable and gives
less accurate results).  But when I tried to work around the size method, I
found it was very deeply embedded in the inner workings of DataTable.  I
also think DataTable is too nice of a component to not use.  So I came up
with a solution that doesn't require the DataProvider to have a size()
method, but leaves it in DataTable.  I've submitted this to JIRA
(https://issues.apache.org/jira/browse/WICKET-579), but since it requires
changing core classes, I wouldn't suggest anybody implement it before it is
an accepted patch.  (but maybe some support from others will help it get
accepted).

Kurt


James McLaughlin-3 wrote:
 
 The purpose of size() is to give the DataView an idea of how many
 pages there will be, so this really won't work. You should fetch size
 in a separate query as the number of orders total over all pages, and
 cache that.
 
 best,
 jim
 
 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 ListOrder orders;

 public OrderProvider()
 {
 }

 public Iterator iterator(int first, int count)
 {
 this.orders =
 WicketHelper.ListOrdergetDetachedModelObject(
 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
 
 

-- 
View this message in context: 
http://www.nabble.com/Chicken-and-egg-w--Data-Provider-tf3834369.html#a10875427
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


Re: [Wicket-user] Chicken-and-egg w/ Data Provider

2007-05-30 Thread V. Jenks

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 ListOrder orders;

 public OrderProvider()
 {
 }

 public Iterator iterator(int first, int count)
 {
 this.orders =
 WicketHelper.ListOrdergetDetachedModelObject(
 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
 
 

-- 
View this message in context: 
http://www.nabble.com/Chicken-and-egg-w--Data-Provider-tf3834369.html#a10879506
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


Re: [Wicket-user] Chicken-and-egg w/ Data Provider

2007-05-29 Thread James McLaughlin
The purpose of size() is to give the DataView an idea of how many
pages there will be, so this really won't work. You should fetch size
in a separate query as the number of orders total over all pages, and
cache that.

best,
jim

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 ListOrder orders;

 public OrderProvider()
 {
 }

 public Iterator iterator(int first, int count)
 {
 this.orders = 
 WicketHelper.ListOrdergetDetachedModelObject(
 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


Re: [Wicket-user] Chicken-and-egg w/ Data Provider

2007-05-29 Thread Timo Rantalaiho
On Tue, 29 May 2007, James McLaughlin wrote:
 The purpose of size() is to give the DataView an idea of how many
 pages there will be, so this really won't work. You should fetch size
 in a separate query as the number of orders total over all pages, and
 cache that.

I think that in DataGridView (or something such that
DataTable uses) this is already implemented, so you 
could have a look at that.

- Timo

-- 
Timo Rantalaiho   
Reaktor Innovations OyURL: http://www.ri.fi/ 

-
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