Here is my idea on convert two hooks into single hook:

public abstract class LoadableDataProvider  {

    public static interface IPageableData {
        public Iterator getIterator();
        public int getSize();
    }

    protected abstract IPageableData load(int start, int count);
}

and several examples usage:

new LoadableDataProvider() {
    @Override
    protected IPageableData load(int start, int count) {
        MyData myData = myService.getBooks(start, count);
        return new DefaultPageableData(myData.iterator(), myData.getTotalSize());
    }
};

new LoadableDataProvider() {
    @Override
    protected IPageableData load(int start, int count) {
        Collection myBooks = myDAO.findBooks(start, count) ;
        int totalSize = myDAO.getTotalSize() ;
        return new DefaultPageableData(myBooks, totalSize);
    }
};

new LoadableDataProvider() {
    @Override
    protected IPageableData load(int start, int count) {
        List allBookList = myService.listAllBooks();
        return new DefaultPageableData(allBookList);
    }
};

The API is not elegant as original IDataProvider but at least this solves all of my problems....

If this is not possible, I hope that 1.2 DataView can accept IModel as 1.1 do.


On 1/13/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
yep. the point of the dataview is to work with database data, so the assumption is that you only want to retrieve a page of the data and not the whole thing, and that the number of rows in the page is much smaller then the total number of rows available. that is why there are two queries. the count returns the entire number of rows, while the iterator only retrieves a certain subset of the rows.

-Igor



On 1/12/06, Martijn Dashorst < [EMAIL PROTECTED]> wrote:
Only when your list is small enough, then it is more efficient to grab
the whole contents in one query, and return the size of the list
itself, instead of a query result.

To do such a thing, just create a transient list property, that gets
lazy initialized. Let both size and iterator use the list property
instead of directy going to the database.

Be warned though, that this might lead to performance and memory
problems when your list is too big.

Martijn


On 1/13/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> but you would still have to access the database twice. once to retrieve the
> total count and once to retrieve the page. true idataprovider makes it
> difficult to aquire all this in a single transaction, but what would you
> propose a signature/return type of the method call would be to acquire both?
>
> also, usually select queries are not ran inside transactions so i have never
> thought it would be such a big concern.
>
> im open to discussing this so please go ahead.
>
> -Igor
>
>
>
>  On 1/12/06, Ingram Chen <[EMAIL PROTECTED]> wrote:
> > I also have same problem...  IDataProvider has two callback methods:
> > iterator() and size(), this force subclass always access database twice
> every request. And even worse, I can not combine these two access within
> single transaction if integrating with Spring.
> >
> > I use technique as karthik mentioned in first post to solve this issue
> before, but I can't do it now. The only thing I can do is tweaking something
> in onBeginRequest().
> >
> >
> > I hope IDataProvider can provide "single" hook instead of two hooks.
> >
> >
> >
> > On 1/13/06, Igor Vaynberg < [EMAIL PROTECTED]> wrote:
> >
> > > the dataprovider is quieried every request for the data, so manipulate
> the data in the object that the idataprovider represents instead of changing
> the idataprovider directly. will that do? if not i can add a
> setDataProvider() method, but i thought it would be unnecessary.
> > >
> > > -Igor
> > >
> > >
> > >
> > >
> > > On 1/12/06, karthik Guru < [EMAIL PROTECTED] > wrote:
> > > >
> > > > Hi Igor,
> > > >
> > > > DataView in wicket 1.2 does'nt accept a Model and instead accepts only
> IDataProvider. I need to change the contents of the ListDataProvider
> dynamically. Earlier ( 1.1) I c'd get this working through Model.getObject( )
> where i used to return a different ListDataProvider.
> > > >
> > > > DataViewBase.internalGetDataProvider( ) is final so
> am unable to override it in my DataView derived class.
> > > > What do you think is the best way to accomplish this now?
> > > >
> > > > thanks
> > > > karthik
> > > >
> > > >
> > > > On 1/4/06, Igor Vaynberg < [EMAIL PROTECTED] > wrote:
> > > > > this is the right approach. this is exactly why the listview either
> takes a collection instance or an imodel instance instead.
> > > > >
> > > > > -Igor
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On 1/3/06, karthik Guru < [EMAIL PROTECTED] > wrote:
> > > > > >
> > > > > > I'm want to be able to supply the ListView with a IModel that
> tells it how to get to the list. I'm not in a position to supply the List at
> the time of construction. The ListView needs to fetch it while rendering. So
> i supplied a Model configured with the "List source" with its
> getObject(Component) call overriden (where I fetch the list ). Ofcourse it
> works just fine!
> > > > > > My question is - Is this an acceptable way of using a Model / is
> there a better delegation model built in that I can use to do such things ?
> > > > > >
> > > > > > thanks,
> > > > > > karthik
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> > --
> > Ingram Chen
> > Java [EMAIL PROTECTED]
> > Institue of BioMedical Sciences Academia Sinica Taiwan
> > blog: http://www.javaworld.com.tw/roller/page/ingramchen
>
>


--
Living a wicket life...

Martijn Dashorst - http://www.jroller.com/page/dashorst

Wicket 1.1 is out: http://wicket.sourceforge.net/wicket-1.1


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&opclick
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user




--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen

Reply via email to