> Yea, I can see how that would work. You're just saying to put 
> the "black box" in the ListView, right?
There is no black box. The paging that the pagedlist does is no longer
necessary.

> Your DataProvider 
> interface is a bit too simple (doesn't allow ordering, and 
> EJB and Hibernate2 can't wrap an object in a model with only 
> the object itself for reference), but I think it could work 
> nicely with some fleshing out.

I am working on example that does both of the above, here are some snippets:

Sorting (I know its not generalized yet, just a working prototype)

public class SortableContactDataProvider extends ContactDataProvider
{
        private String sort; // <===== yes later this will be a list of
sortparams
        public Iterator iterator(int first, int count)
        {
                return getContactsDB().find(first, count, sort).iterator();
        }
        public void setSort(String sort) {
                this.sort=sort;
        }
        public String getSort() {
                return sort;
        }
}

Model wrapping:

public class DetachableContactModel extends AbstractReadOnlyDetachableModel
{
        private long id;
        private transient Contact contact;
        
        protected ContactsDatabase getContactsDB() {
                return DatabaseLocator.getDatabase();
        }
        
        public DetachableContactModel(Contact c) {
                this(c.getId()); // <=========== here is the trick
                contact=c;
        }
        
        public DetachableContactModel(long id) {
                if (id==0) throw new IllegalArgumentException();
                this.id=id;
        }

        protected void onAttach()
        {
                if (contact==null) { // <======== no need to load if ctor
with object used
                        contact=getContactsDB().get(id);
                }
        }

        ... 
}

> Returning an Iterator is very nice. If all you need to do is 
> iterate, there's no reason to require a List.

What more can you do with a read-only list?

> But because I'm 
> implementing a List, there's no way to incorporate that. 
> However, returning a list WILL use the cache, just not by 
> default. You have to set useQueryCache to true.

I don't think that works the same way, I might be wrong though. If you set
hibernate.use_query_cache=true and then set query.setCachable(true) you will
cache the entire resultset which is not the same. When you call
query.iterate() it uses n+1 queries to retrieve data, that means the first
query gets all the primary keys, and then it retrieves the objects object by
object (the other n queries) so you end up with each object being cached
separately in the cache not as the entire resultset. This gives you a much
higher cache-hit chance when retrieving multiple objects and when retrieving
an object by pk.

-Igor




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to