Event.markRollBack

I have a question regarding the markRollBack method of the Event class. Tracing through AbstractSession.createDocument to EventServiceImpl.fireEvent into a subclass of EventListener - I cannot see how calling markRollBack on the Event inside the listener subclass actually triggers a roll back of the transaction. Should this be mechanism be used for document-based event listeners to initiate rollbacks in exception conditions? I am unable to cause a rollback to happen in the unit test environment (have not yet tried in the local server environment.) I see the markRollBack method used in the org.nuxeo.ecm.user.invite package, and I also see it used in the nuxeo-quota addon. I just don't see the code that actually performs the rollback on the basis of the flag being set in the Event class. Clarification is appreciated on whether this is an appropriate way to manage transactions inside listeners and - if so - how it actually works. Thanks.

0 votes

1 answers

501 views

ANSWER



The pattern is to do event.markRollBack() then raise an exception. The framework will then re-raise an generic exception, and then the normal exception handling mechanism of Nuxeo will rollback the transaction.

An alternative is to call event.markBubbleException() then raise a specific exception like RecoverableClientException which will be kept as-is by the framework and can be caught by whoever initiated the event.

Failing to do either of those, an exception in a synchronous (inline) listener will be caught and logged, but the other ones will still be run and the transaction will continue.

Code for all this is in EventServiceImpl.fireEvent(Event).

0 votes