In Ted Husted's scaffold package, he created a utility function that does 
exactly this:

org.apache.scaffold.sql.ResultSetUtils - getCollection(Object bean, 
ResultSet rs).  This function will return a Collection (ArrayList) of beans 
automatically populated from the ResulSet.  Very simple - your done!

Chris....

At 12/2/2001 05:41 PM, you wrote:
>Given that the responsiblity of a PropertySearch object would then be to
>return a set of found Properties,  I would have thought the best approach
>would be :
>
>1. Have the PropertySearch query do one database hit which gets all 100 (for
>e.g) rows in to a rowset object.
>2. The PropertySearch object would then be responsible for the creating a
>blank Property object, and mapping the values in the rowset to the
>attributes of the Property object.
>3. Keep the created object in a collection (ArrayList for e.g)
>4. Repeat for all rows in DB rowset
>5. Return collection of Property objects when finished.
>
>Andy
>
>
>----- Original Message -----
>From: Andrew Myers <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Sunday, December 02, 2001 10:45 PM
>Subject: Design of Business Objects
>
>
> > Hi,
> >
> > This is not exactly a question related to Struts as such but it does
>relate to a Struts application I'm building. :)
> >
> > I have a search function that allows users to search for a Property via a
>street address.  The business objects I have to support this are a
>"Property" object and a "PropertySearch" object.  From my action class I
>call a method on the PropertySearch object which then will ultimately return
>an array of Property objects corresponding to those which match the search
>criteria.
> >
> > My question is this:
> >
> > Which object should take responsibility for the population of the Property
>objects with data from the database?  It seems much better from an OO
>viewpoint to be able to pass the primary key into the constructor of the
>Property object and then call a helper method to populate the object.  But
>this is inefficient if the search returns a large number of results.  Eg.
>for 100 results there's 101 database hits (1 to get all the matching primary
>keys, and then 100 to populate each of the objects in turn).  The other
>alternative is to have my initial query return all the data and then have a
>constructor on the Property object which takes about 25 parameters (ugly and
>perhaps not very reusable, but more efficient?)
> >
> > Does anyone have any thoughts on what the best practice is here?
> >
> > Thanks,
> > Andrew.
> > --
> >
> >
> >
> >
> > __________________________________________________________________
> > Your favorite stores, helpful shopping tools and great gift ideas.
>Experience the convenience of buying online with Shop@Netscape!
>http://shopnow.netscape.com/
> >
> > Get your own FREE, personal Netscape Mail account today at
>http://webmail.netscape.com/
> >
> >
> > --
> > To unsubscribe, e-mail:
><mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
><mailto:[EMAIL PROTECTED]>
> >
>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to