I was curious about what you could accomplish with EventManager listeners.

I have a scenario where I normally use the Cayenne lifecycle callbacks to 
detect when an Object was updated, and “sync” it to an external system.

class SalesOrder {
        void sync() {
                // send data to external system
        }

        @PostUpdate
        void didUpdate() {
                this.sync();
        }
}


But I now want to sync a SalesOrder if it changes or if any of its 
SalesOrderLines (many relationship) change. But If both objects 
SalesOrder/SalesOrderLine are part of the same commit, then I don’t want the 
sync to get invoked more than once.

If I just used the logic below, its possible that the SalesOrder would get 
synced multiple times for all of its child SalesOrderLines, and possibly again 
if the SalesOrder itself changes

class SalesOrderLine {
        @PostUpdate
        void didUpdate() {
                this.getSalesOrder().sync();
        }
}

Was hoping to find something that I can execute after the commit of all objects 
is done, but call sync on the SalesOrder once. Can the EventManager help with 
this? 

post-commit listeners?

Thanks,

Matt Watson

Reply via email to