Is there some fancy way to make a "differential" update on a list of rows in Spring? For instance, I have such rows in my database:
- Row A
- Row B
- Row C
I am provided with a new set of items:
- Row A
- Row C
- Row D
What I want to have as a result is:
- Row A (updated, not removed and added)
- Row C (updated, not removed and added)
- Row D (added)
- deleted row B
It is crucial here to keep track of creation and modification dates. Is there some convenient way to achieve this in Spring?
Thank you in advance for any tips.
SOLUTION:
I haven't found a "nice" way to do this. In the end I added Date fields with @CreationTimestamp and @UpdateTimestamp (though the latter could be a simple Date/LocalDate field). While uploading a new set, for each row I checked if repository didn't have such object already (had to be done by comparing all fields but ID since ID was auto-generated and I needed comparison by values - fortunately each combination of values in my system is unique).
If it did, the update date was changed to current date.
After this was done I simply deleted entities with update date prior to current date. Not a fancy way and quite slow but it works well.