Question

I have an application server that sends an array of record data to the client in response to a search. Prior to sending the data to the client, my thought is to have the server store the data in a session variable.

When the user selects and then submits a record to edit, the client sends the entire record to the server. It updates the entire the record in the database (in case some other user has committed an update after they have searched).

However, I still need to capture the changes so that I can properly store audit information. I think it's best to capture old and new values based on what the user saw and changed. Therefore, I plan to (deep) compare field by field the record in the session data and the updated record sent by the client. I have two questions:

1) Are there pitfalls/problems with this approach?

2) If not, what is a good Java utility/library for comparing objects?

Thanks in advance for your help.

Was it helpful?

Solution

You may be better off rejecting the change if another use has changed any field in the record. You can alert the user that the record has change and show them the new data to perform the update again (maybe keep their changed values available to them).

This way if another user changes a field that relates to a field they did not change, you will not be making changed to the records that no longer make sense with each other.

OTHER TIPS

There are various approaches:
If for some reason you cannot mark the chhanged fields on server side and in the response, I would use reflection to compare all fields of a class, which hopefully are primitive objects or at least support equals(). However I would limit that to primitve types and String.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top