-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Reassociating Struts Form back to (cached?) scrollable coll.
PostPosted: Fri Oct 10, 2003 5:15 pm 
Newbie

Joined: Fri Oct 10, 2003 5:08 pm
Posts: 2
I'm looking for advice on something that is probably a common pattern, but I haven't found anything on the Hibernate Wiki or forums about it (at least under this description -- please point me in the right direction if I missed something obvious).

Basically, I want to build a Scrollable Smart Collection, that is a pseudo-Record Set, but containing mapped POJO Domain Objects (or Active Records). The collection would have a Page Size and would maintain a state of where the window/page was in the total Record Set.

I think I understand how to build that, either using a ScrollableResults Query, or using setFirstResult/setMaxResults on Criteria. [Although I'm not certain how to get from ScrollableResults to rich domain objects].

My real question, is how to maintain that Scrollable window position (and the data), from user request to request, in a Struts application, with efficient database access.

--------------

I think I need to transfer my data from the smart collection of domain objects to populate a set of Struts Forms (possibly with DTO/VOs), possibly with BeanUtils, though I'm considered about triggering lazy loading at the wrong time. I don't think I want rich domain objects in a web session / request, as they would not serialize well and would break the application tier structure.

Once the user decides to take some action with the current page, or to scroll to the next page, how do I communicate that back to the Business Layer, and reconnect to the smart collection?

Do I need some kind of registry or JCS cache? I'm trying to avoid EJBs, unless absolutely necessary. I'm using Oracle with Tomcat and Struts, and the Open Session in View pattern/anti-pattern (though I'd love to find a better way).

I've looked at Spring, but I'm concerned about timing of opening/closing the Session and how to get efficient caching and lazy loading.

Do I need to pass the window position into Struts, and then requery the database/cache every time the user takes an action?

Basically, what's the best way to reassociate/convert a Struts Form back to a corresponding domain object (in a scrollable collection)?

Any help, examples, suggestions, or pointers to specific documentation would be greatly appreciated!

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 11, 2003 4:40 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 4:19 pm
Posts: 42
You've got a lot of issues here...I've implemented similar front-end functionality, a screen displaying paged search results that the user can navigate through by page. But did it in a somewhat simpler way.

I'd strongly suggest using setFirstResult/setMaxResults rather than messing with scrollable result sets. You may wind up hitting the database a bit more, but the code is simpler. This way, the only user state you need to maintain between requests is the page size and the offset. When the user requests another page, you just create a new query and pull a fresh set of objects. Of course, this is probably not the best pattern for a high-concurrency enviro.

In my own app, I've got a DTO that holds all the user's search criteria, along with the page size and offset. After the user submits a DynaActionForm, I use beanutils to copy the data to the DTO. I store it in the user's httpsession. Here's the code to handle a user's request for the prev/next page:

Code:
       if(request.getParameter("init") != null ){
            filterDTO = new FilterDTO(); }
        else{
            filterDTO = (FilterDTO)mysession.getAttribute("FilterParams");
            if(request.getParameter("offset") != null){
            String offset = request.getParameter("offset");
            if(offset.equalsIgnoreCase("fwd")){
                int newoffset = filterDTO.getOffset() + filterDTO.getPagesize();
                filterDTO.setOffset(newoffset);
            }
            if(offset.equalsIgnoreCase("rev")){
                int newoffset = filterDTO.getOffset() - filterDTO.getPagesize();
                filterDTO.setOffset(newoffset);
                }
            }
       }


Then I send the DTO to my service layer, where Hibernate pulls a new set of objects according to the filter criteria.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2003 2:35 pm 
Newbie

Joined: Fri Oct 10, 2003 5:08 pm
Posts: 2
Thanks for the FilterDTO tips -- that should help for the smaller queries, where performance isn't an issue. I like the approach, as it will keep the code simple and easy to maintain.

However, for large queries, I'd prefer not to have to go to the database again, especially if the user is taking an action with the rows on the current page.

Do you (or anyone else) have advice on manipulating larger query sets, when the user may choose to update 1 or more rows?

If I set up a JCS cache, can I do a
Code:
load()
with the hidden primaryKey passed from my Struts Form to reload the Domain Object from the cache instead of hitting the DB again?

Any easy way or pattern to do this across an entire scrollable smart collection?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2003 7:16 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
cimershe wrote:
Thanks for the FilterDTO tips -- that should help for the smaller queries, where performance isn't an issue. I like the approach, as it will keep the code simple and easy to maintain.

I am 100% sure "FilterDTO" is more performant for "big" queries for "big" web application.
maxAppUsers <= maxDbConnections for db scollable result sets or "OutOfMemoryError" if your are going to scroll memory result sets mapped to http session ( maxAppUsers <= maxMemory/resultSetSize ).


Top
 Profile  
 
 Post subject: Could you give and example of the pagination system?
PostPosted: Tue Nov 25, 2003 9:36 am 
Newbie

Joined: Fri Sep 19, 2003 2:57 pm
Posts: 10
Hi,

could you bring completely the pagination system that you use with FilterDTO?

Imagine that you have a string property.
Theres is any way to do something like that for a filter?:

if ((((o1.getFirstName()).toUpperCase()).indexOf((catalogFilter.toUpperCase())) == -1) &&
(((o1.getLastName()).toUpperCase()).indexOf((catalogFilter.toUpperCase())) == -1) &&
(((o1.getLogon()).toUpperCase()).indexOf((catalogFilter.toUpperCase())) == -1) ) {

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.