Looking for a better design: how to populate db result to object with lists

I have a query that returns from the db an arrayList of class CarBean:
carID, model, color, rentUserID, fname, lname, dateRentStart, dateRentEndThe query is with reference to a particular car that N people (rentUserID) rented and the user (the system user) wish to know how many rentals were made for this carID.
I wish to populate the result into ONE class name CarRental which looks like this:
private Car; //model
private List<RentUser> rentals; //all info relating to rentUserso, my question is this, what creative way (Design Pattern, maybe?) is there to populate all the objects (CarBean) from the arrayList into CarRental?
In my solution I'm doing something like this:
Iterator<CarBean> itr = list.iterator();
CarRental carRental = new CarRental();
List rentals = new ArrayList();
while (itr.hasNext())
    CarBean cb = itr.next();
    carRental.setCarID(cb.getCarID);
    //for the list of users:
   User u = new User(); 
   u.setUserID(cb.getUserID()); 
   rentals.add(u);
carRental.setRentals(rentals);* please consider a more complicated query that the end result of ONE object should have X arrayList and other M objects in it
thank you!

Just to make sure I understand, here's a simple version of your question. Please correct anything I have wrong.
Your design will have two classes: Car and Renter. A Renter is a Person who rents a Car on a given day:
package model;
public class Renter implements Serializable
    private Long id;
    private String name;
    private Address address;
    // Details left for you.
}You'll also have a Car:
package model;
public class Car implements Serializable
    private Long id;
    private String make;
    private String model;
    private int year;
    // Details left for you.
}It sounds like you want to have a one-to-many relationship between Car and Renter. I think you have a couple of choices:
You can embed a List<Renter> as a data member inside the Car class, or
You can encapsulate the relationship between a Car and a Renter in a separate class like a Contract.
I kinda like the second option because it reifies a nice concept.
As far as the database goes, I'd recommend following an idiom from Spring- their RowMapper interface:
package persistence;
public interface RowMapper
    Object map(ResultSet rs);
}Encapsulate the mapping from ResultSets to Objects that way.
Or use Hibernate, TopLink, or another ORM tool.
%

Similar Messages

  • I am looking for an example of how to use the Rendezvous synchronization object.

    I can't seem to find an example that uses the TestStand Synchronization Step Types. I am specifically interested in the Rendezvous type. I am have programmed quite a few VC++ applications that use semaphores, so I am familiar with the overall idea of sync objects.
    Thanks in advance.
    ~tony

    Here is a pretty good example that illustrates the benefits of multithreading over single threaded tests, and it utilizes a rendezvous to synchronize its multiple threads (see attachment to this post).
    Jason F.
    Applications Engineer
    National Instruments
    www.ni.com/ask
    Attachments:
    Rendezvous_Demo.zip ‏81 KB

  • Looking for a better solution that tunnel interface

    Hi
    acctualy I have a Vsat connection between my remote site and central office
    on both site we have router and sat modem
    I have now a tunnel interface between my two routers,I am looking for a better idea,,

    hi...
    so you have tunnel interface between your two router so now what are you looking for...?
    secure IPsec connection or what???
    please explaine in details
    regards
    Devang

  • Looking for a better heatsink help....K8N NEO2

    Im looking for a better heatsink....any suggestions? I may oc it but for now I wont....it idles at 40-41 and stays at 60 when im gaming 58 if i turn off cool n quiet.....and thats with some ocz ultra5 Thermal compund....ThX

    Yes, agree with SAB, zalman 7000 is a good one, however I´ve got 2 very simular K8N Neo2-systems but with 2 different cpu coolers.
    One with zalman 7000alcu and one with Thermalright XP-90 and a zalman 92mm fan ( you can use what ever 80/92mm fan you like high speed, low speed, led colored, etc).
    Both are equal regarding cooling to my experience, but I prefered the XP-90 because I did not have to remove the backplate ( I think zalman recommends mounting it´s own backplate to get the right distance/pressure between the cooler and cpu ).
    With the XP-90 you just switch the retension mechanism which is easy ( even with the MoBo in the case ).

  • Looking for some guidance on how to splice 2 vidoes together in Adobe Elements 13.

    Looking for some guidance on how to splice 2 vidoes together in Adobe Elements 13.

    ScottWarnerBC
    What computer operating system is your Premiere Elements 13 running on?
    What do you mean by splice 2 videos together?
    a. put them side by side on the Timeline and export them to one file saved to the computer hard drive or burned to disc
    or
    b. something like the following even before import into any Premiere Elements project
    ATR Premiere Elements Troubleshooting: PE12: Seamless File Merging Before Import
    If it is "a", then we need to know the properties of those 2 files so that the project settings can be set accordingly.
    What is your intended export? Based on the properties of the source media, we can then decide on export settings
    to produce a file with properties as close as possible to the source (if that is what you want).
    We will be watching for further information.
    Thanks.
    ATR

  • Looking for Great Flash Designer

    Hello,
    I am looking for a Flash designer that can create beautiful
    designs. Here are some examples of some sites that I like:
    http://www.garniernutritioniste.com/en
    http://www.minhlong.com/MinhLong08/
    http://www.voxhon.com/
    http://www.themontgomeryimprovementassociation.org/website/
    http://www.poseidonresorts.com
    If you can design a site of this quality, please email me
    some samples of your work and your prices to [email protected]
    Thank you

    Jon chu wrote:
    I have LabVIEW project experience and I do love it. So I want to join JKI when I graduate in September 2007.
    Thank you.
    [email protected]
    Please check out our openings, here.  To apply, please email us at jobs (at) jameskring (dot) com,
    attaching examples of your LabVIEW work and a current resume in HTML,
    Word, Plain Text or PDF format. In
    the body of the email, explain why you would be a good fit for this job.

  • Old computer crashed.  trying to sync my iphone with new computer but phone is looking for old computer.  how do i change it?

    old computer crashed.  iphone is looking for old computer so I can't get it to sync with my new computer.  Suggestions?

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • Any suggestions?  I'm looking for a comfortable and secure drawer to house my keyboard (wired, with number pad) and magic tracker.

    Any suggestions?  I'm looking for a comfortable and secure drawer to house my keyboard (wired, with number pad) and magic tracker.

    Apples wireless magic trackpad
    http://www.apple.com/magictrackpad/

  • HT204266 looking for the old Netflix app that will work on original Ipad with ios 5.1.1

    looking for the old Netflix app that will work on original Ipad with ios 5.1.1

    Netflix does in fact have the old version of their app available.
    In iTunes on your computer, download the App you want a compatible version for using the same Apple Id that the iPad has for the App Store. For Paid Apps its best to consult with the App maker to make sure there is a compatible App. With the App Downloaded to iTunes on a computer you can go into The App Store App on your iPad, Tap on Purchased, and Look for the App there. Tap on it to begin the download. It will likely say its not compatible, but if there is a compatible version it will offer to download it. Install the latest compatible version of an app on an earlier version of iOS or OS X

  • How I can stop the combo box with list of values from fireing validations

    Hi I'm using Jdeveloper 11.1.2.3.0
    Using Hr Schema employees table
    I Display employees data in af:table
    and I make List Of values on Department_id filed to easy change the employee department
    and another one on Job_id filed
    and Imake them UI Hints as ( combo box with list of values ) in the employeesVO
    the problem is when I Select a value from department or jobs ( combo box with list of values )
    fires the entire filed validations for mandatory atributes
    Note : the af:table Property ( contedelivery) is set to (immediate )
    How I can stop the combo box with list of values from fireing validations

    check it out.,
    http://andrejusb.blogspot.in/2012/09/what-to-do-when-adf-editable-table.html

  • Looking for a better resource to get a handle on using effects in after effects (CS6 BTW)

    Hello thanks for looking in,
    I would like to get better control over Zooming. The Zooming I found in AE did not function when
    dragged it into my effects controller...Is the only Zoom control really the "Scale" as found in Prem-Pro?
    I could not find it in AE. I wanted to zoom over the shoulder of my actor and concentrate on what my Actor is looking at/pointing at. I could not find where that effect is at in AE.
    If you know of a couple good tutorials to watch that show how to control the effecst in After-Effects it would be welcomed and appreciated. If you know the specific path to use to pan and
    zoom for my desired shot mentioned, that too would be appreciated. One other ? I skimmed through "Creative Cow" but there are many videos and after watching a couple that were titled what
    I want, were not what I was looking for. Spent an hour plus surfing before I came here to ask.
    Are some of the effects only applicable to one or the other? IE: Movies or stills? If so is there a
    manual that states what can be used with what? I tried dragging some of the effects into my effects area and they would not populate. IE: Zoom Forward. Only used for Text?
    Thanks for your time with this in advance.

    Start here to learn After Effects: http://adobe.ly/bjBT3P
    (That link is the direct link to the resources recommended on the thread that shooternz gave.)

  • Looking for sample code of HOW-TO use EntityFacadeImpl class

    I have created the following using JDeveloper Ver 9.0.3.1:
    1. Entity Bean
    Localinterface: userLocal.java
    Local home interface: userLocalHome.java
    Remote interface: user.java
    Remote home interface: userHome.java
    Bean implementation: userBean.java
    2. Facade Session Bean (auto generated by JDeveloper)
    userFacade.xml
    userFacadeColImpl.java
    userFacadeImpl.java
    I am looking for sample client code on how to make use the facade session bean.
    Thanks in advance.

    repost

  • Looking for a desktop replacement, how will this one fare?

    I think I settled on the one I am looking for...
    My price range is probably no more than 1300-1500.
    http://www.amazon.com/Toshiba-X875-Q7190-17-3-Inch-Diamond-Textured-Aluminum/dp/B00AY1FGYK /ref=sr_1_1?s=pc&ie=UTF8&qid=1368339116&sr=1-1&keywords=Toshiba+Qosmio
    Toshiba X875-Q7190
    How will this stand up to some moderate to heavy editing? I am new to the video editing world, coming from music production. I would mostly like to make simple youtube videos for man on the street stuff and work my way up to documentaries and the like, maybe around 45 mins in length or so with lots of graphics and stock footage. Will this be a good bargain for what I am looking for? I would rather it be overkill than get invested in the process of editing only to find out my computer cant cut it...
    Thanks a lot you guys I am always learning more when I come here!

    BTW...this is something I did recently which got me on this kick. I did it on my brothers Dell. I think it was a 17R if im not mistaken. It took it pretty well and rendering was about 2 hours for this 22min clip which is longer than I would have liked. But I didnt do any color correction or get to heavy into it, I was just learning the lay of the land for Pp.
    I will mainly be using AVCHD full 1080p from my Canon Vixia M500 and 1080p from my GoPro Hero 3 Black if that makes any difference...Thanks!
    heres the clip.
    http://www.youtube.com/watch?feature=player_embedded&v=aOcBxMftY9U

  • Looking for app to design a book

    Hello
    I will try to design a book on arch, and I'm looking for the right software.
    I've tried Libreoffice (a bit messy for the task) and Scribus (master page handling lacks some flexibility) for the moment.
    I know this is a bit off-topic, but I would be very interested by your feedback.

    LaTeX can't be beat when it comes to layout/typesetting. However, I do all my actual writing using Pandoc's extended Markdown syntax. I can think of three reasons to prefer Pandoc, at least for the writing process:
    - LaTeX makes gorgeous final products but it's syntax is tedious to work with compared to Markdown, even the more complex Markdown used by Pandoc. Block quotes, lists, citations, headings, footnotes and bibliographies are all much easier to work with in Pandoc since you don't have to switch between writing prose and writing code---you just place simple punctuation marks in the appropriate place to get the desired effect.
    - Pandoc can output to damn near every format imaginable (including different TeX derivatives), so you can use LaTeX just for formatting the final product rather than writing the whole document.
    - In contrast, LaTeX can only output three formats on its own: PDF, Docbook and (unless I'm mistaken) ODF. You'd need an extra tool---like, say, Pandoc----to convert your LaTeX document to HTML or EPUB or MediaWiki or something if you wanted to publish in a medium other than print (or one that mimics print as PDF does).
    - Another possibly less-compelling reason would be that Markdown is deliberately designed with the intent of making an unprocessed document human-readable. Most people should be able to open or print out a plain text document marked up with Markdown and generally understand what the markup signifies. This makes collaborative editing with people unfamiliar with Markdown possible.

  • Looking for a better way to backup end users

    Hello there.
    Not sure if this the best forum for this post but here goes.
    Last week my company had a break in and a couple of laptops got lifted. Not a big deal as I had backups of the machines on tape. It did take a while to recover the files though. During that time I got to thinking about a better way to backup and I am looking for any ideas of if this would work or not.
    First quick overview. About 60 end users majority with laptops.
    What I am thinking of doing is this. Take an xServe RAID configured in RAID 5, for redundancy and speed, and creating a shared folder on it for each of my end users. This way if they need to retrieve a file they can log in and will not have to call me. Then, this is where I need help, use some tool to copy all of their files at specified intervals into their folder, at least once a day. I am currently using Retrospect to backup everyone directly to tape and I could use that to do this but the only thing I do not like about Retrospect is it can only do one user at a time. With 60 users I have to start it pretty early in the day. I know copy files would be alot faster so I am not ruling it out. I was also thinking about using ChronoSync to accomplish this and then use Retrospect to backup the RAID to tape for long term storage. I am ruling out using Home directories on the xServe for my users because they are all laptops and are usually out of the office at least one day a week.
    If anyone could offer some ideas of whether or not this is going to work or not or if you have other suggestions, any help would be greatly appreciated.
    Thanks in advance.
    Daniel Krajc

    Hi,
    you could be using a combination of Mobile Accounts (for the settings of the ibook) and rsync (which is installed by default on 10.3 and 10.4), check man rsync for more info.
    regards.
    Dimi.

Maybe you are looking for

  • Business Catalyst in Creative Cloud

    I have a question regarding Business Catalyst.  It seems that with my Creative Cloud subscription I can create 5 sites in either Dreamweaver or Muse, and upload to Business Catalyst.  But when I log on to manage my site it seems I get parts of Busine

  • Cannot connect to itunes store from my Netbook and Ipod touch 4g

    Hello I have upgrated my Ipod touch to Ios 5.0.1 and until recently i was able to download and update Apps from itune store from both my Netbook and Ipod Touch 4g . The weird thing is i am able to browse the store but only not able to doanload or upd

  • The menu button on the click wheel does not work!!!

    I just got my I pod nano Black(2gb) and for some weird reason the 'menu' button on the wheel just does not respond. So i cannot go back to the previous menu or reset. What do i do????

  • Is there a way to monitor active Sockets?

    Ok, so the RMISocketFactory creates sockets for use with RMI calls and placed into a socket pool that is used by RMI to establish connections. Is there a way to look at that Socket Pool and see how many Sockets are sitting there and if they are activ

  • Approval process in XML forms

    Hi, I am implementing XML forms with approval process.UI have created a news. and it goes to the folder /documents/news2 For Folder "News2" I have permission to one USER "Preeti " as approver.Everyone is Read access Service Permissions that "Preeti"