i am currently implementing a grails web-app, with a couple of complex forms where modifications on an association graph should be managed "in-memory" (that is the http session) as long as the entity or top-level domain object is not saved.
e.g.
top-to-bottom: Document -> Categories -> Sub-Categories ...
requirement: modifications to document/categories/sub-categories should only be saved whenever the document is saved and under no other circumstances.
my first approach was to store the association ids in the http session, but this ends up with lot of clue code in my DocumentController.update action that synchronizes session state with the current persistent state
// update some abstract association
for (def Iterator it = documentInstance.association.iterator(); it.hasNext();) {
if (!session.association.contains(it.next().someEntity.id)) {
it.remove()
}
}
for (def roleTypeId in session.association) {
// add/update association
...
}
clue code is getting even worse when it comes to actually modifying data e.g. of a category, meaning that the modified category object has to be detached/reattached/merged when the top-level entity is saved.
I would be very interested in your thoughts on such long-spanned unit of works.