-1

I'm making a car rental java desktop application using JavaFX and JDBC. I have a table containing vehicles (license plate as pkey, brand, hp, color, etc.). When the customer selects the rent option, the program lists the available cars, but shows only the brand and type. If a car is selected, it will show every info about the vehicle. I think about two options when rent menu is selected:

  1. Select all available cars data (not only brand and type) and store it in a list or map, so when I select a car I don't have to connect again to the DB.
  2. Select only the brand and type to show and if I choose a car, select all the datas from DB that the specific car has.

Which way would be better or are they even good solutions?

Atul Dwivedi
  • 1,452
  • 16
  • 29
kaprip
  • 23
  • 4
  • I depends. Your requirements should drive whether to use lazy loading or eager loading. See this http://stackoverflow.com/questions/12569403/when-to-use-lazy-loading-eager-loading-in-hibernate – Atul Dwivedi Sep 01 '16 at 15:30
  • Thanks, never heard about it yet. – kaprip Sep 01 '16 at 15:34
  • I had programmed the same solution one year ago, I use the second one, because , you really need to update your database every time, something happened. if you don't you lose your data integrity – Towfik Alrazihi Sep 01 '16 at 16:06

2 Answers2

2

It depends on the scale. In my opinion:

Option a)

  • (+) After start it can work offline
  • (-) If DB contains a lot of data it will be slow (downloading unnecessary data)

Option b)

  • (+) If DB contains a lot of data it should have better performance (You can keep DB session alive to not lose time on reconnect)
  • (-) Can't work offline

You can also make a mix of both - Just select necessary data from DB, show them to user and start loading all data in background

osjo
  • 131
  • 6
1

You have mentioned only VEHICLES table so I am assuming that VEHICLES table is holding all the data what is needed in both cases(listing cars and displaying details on selecting car).

It would be good if you load vehicles that are sufficient enough to render on few navigational screens and once the threshold reaches load more.

In your case go ahead with mix of both options what you have mentioned.

So what I mean here, decide number of records as per your requirements/screen that can serve user couple of navigation without DB call and once user reaches at end, make DB call for again fetching the records.

Atul Dwivedi
  • 1,452
  • 16
  • 29