0

I'm working on a project for JavaFX and databasing practice (mostly I'm a beginner), where I have a unique class which holds records about concerts (name, location, date etc). I originally held these in an observable arraylist which populated a table view. From here the records could be editted, deleted or new ones added.

I am now storing these in a database using ORMLite and sqlite. This is so I can perform filtering on the data (ie show all events in a particular location) and then show this on the table.

My issue is that when I read in the data from the database I convert it to a ObservableArrayList so the table view can use it, but by creating the new array list my edit/new/delete buttons only effect this list and not the database. The problem is that every time I perform a query such as adding or deleting records to the database, it needs to re-produce the observableArrayList for the tableView which is taking around 5 seconds with ~250k records.

Is there a more efficient way to work with databases and javaFx tableViews?

J. Doe
  • 23
  • 2
  • 1
    If you want the updates in the database to take place, while the user is doing stuff on the table, it may take sometime for completion, because database operations are time-consuming operations. You can use threading, if you want to get away with the lag. A very nice read would be the answer to the question [Using threads to make database requests](http://stackoverflow.com/questions/30249493/using-threads-to-make-database-requests/30250308#30250308) – ItachiUchiha Sep 14 '15 at 07:24
  • 1
    Why do you need to "reproduce" the data on each update? Why not just perform the update in the database and, if successful, update the local data in the observable list? – James_D Sep 14 '15 at 11:08

1 Answers1

1

Is there a more efficient way to work with databases and javaFx tableViews?

  1. How about setting some sort of dirty flag on the records when you update certain fields and then go through your list of records and only make the DAO calls on those that are dirty? Maybe an enum with CREATE, DELETE, UPDATE, NONE.

  2. Another idea would be to do your dao.update(...), dao.delete(...), or dao.create(...) calls whenever you update an record although you may want to do the chances all once time.

  3. Last idea is to keep 4 arrays. One with the entire list, one for the new records, one for the dirty records, and one for the records to be deleted. You would add the records to the lists as edit/new/delete buttons are pressed and then at the end you can save them all at once.

Gray
  • 115,027
  • 24
  • 293
  • 354