Re: Nested transactions or other refactoring method
Posted: Fri May 23, 2008 4:10 pm
If it starts getting complicated we're probably on the wrong track. At least that how I approach things. I've used the composite pattern here. This article suggests it may not be a good approach for saving into a db:
http://devzone.zend.com/node/view/id/8
edit: you also might need to mark objects in the tree as dirty to prevent duplication.
http://devzone.zend.com/node/view/id/8
Seperating save into a save and insert method might work. Every component of country call country->save() when asked to save, and country->save() starts the transaction (and closes/rolls back), loops through the tree and asks everyone to insert. It feels strange though.Another issue to bear in mind when deploying the Composite pattern is that of storage and retrieval. Tree structures do not lend themselves well to relational databases.
edit: you also might need to mark objects in the tree as dirty to prevent duplication.