I have a huge java list of simple objects, stored in the database, maintaining the position of the elements by a index column. I use hibernate but manage the list by myself since it's too big to be stored as a collection.
After some changes to the list are made (add, remove, move) I want to persist the changes in the database by manually updating the index columns and inserting new respectively removing elements by hibernate.
Now, (1) is there an efficient algorithm how to combine the list delta to as few as possible sql statements - or (2) do I have to record every change and apply it step by step?
You could try maintaining index changes for segments of the huge list. For instance, in a list of 1000 items, if you:
you can do the following with HQL:
I'm not ready to work on details of the algorithm, will just say that you need to maintain a list of collection segments and offset for each segment.