I have a managed bean that has properties that control sorting, and pagination that are bound to the UI controls.   The data is bound to a property that returns a List of objects.   Only the list of objects that was returned by the getter ('getCats()' in this case) is preserved.   The only magic I've employed is a PhaseListener that closes the thread-local Hibernate session once the request is complete.   This allows me to use mapped objects as Transfer Objects (hehe - take note all you Transfer Object haters!).
 
Something like this:
 
<x:dataTable
                                value="#{catListBean.cats}"
                                preserveDataModel="true"
                                ... etc ...
 
With the class:
 
public class CatListBean <== Request scoped, not session scoped!
{
    private String sort = "name";
    private boolean ascending = true;
    private int first;
    private int max;
 
    // ... getters and setters for sort, ascending, first, and max... all bound to UI components.
 
    public List getCats() throws Exception
    {
        Session sess = ... get hibernate session ...;
        Query q = sess.createQuery("from DomesticCat cat order by cat." + sort + " " + (isAscending() ? "asc" : "desc"));
        // These two lines do the pagination.   I have no idea what it does for ORACLE, but it works! :)
        q.setFirstResult(first);
        q.setMaxResults(max);
        List list = q.list();
        // NOTE: 'sess' is magically closed by a Phase Listener later. This way we don't care if list is lazy or not. :)
        return list;
    }
}

 

From: Dave [mailto:[EMAIL PROTECTED]
Sent: Friday, September 09, 2005 10:14 PM
To: MyFaces Discussion
Subject: RE: dataTable - Millions of records

will perserveDataModel=true keep a copy of the whole collection of data? when will the copy override the whole data model ? Thanks.

Joshua Davis <[EMAIL PROTECTED]> wrote:
I just connect my data table / data scroller up to a backing bean fed by a Hibernate-based DAO.   The sorting in the <x:commandSortHeader> generates the 'order by' in the Hibernate query.   The data scroller information is fed to the DAO as well, which informs the result set handling (set first result, etc.).   The selection is handled by a session scoped form which is edited on a different page.  Honestly, I use Hibernate in part because I can't be bothered to figure out all the peculiarities of each database.   I suppose I'm just lazy like that.  ;)
 
BTW, the <x:dataTable preserveDataModel="true"> feature works great!


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, September 09, 2005 9:45 PM
To: [email protected]; [email protected]
Subject: RE: dataTable - Millions of records

I totally see the purpose of coding the SQL so that you would get only a subset of the data at a time (Oracle gives what you pointed out. SQL Server, as far as i know does not offer such functionality out of the box) . However, once you throw sorting data in the game, isn't it much more complicated to handle and might actually make you run more queries than required if you deal with the subset/ordering in your backing bean?
 
I'm not actually sure here, I'm just wondering how you would handle sorting and using subsets in that case... It's an interesting dicussion though as many people are either going through this, or will go through it when developping their applications.
 
Greg
-----Original Message-----
From: David Haynes [mailto:[EMAIL PROTECTED]
Sent: Fri 9/9/2005 8:32 PM
To: MyFaces Discussion
Cc:
Subject: Re: dataTable - Millions of records

 

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Reply via email to