Skip to content

Commit

Permalink
Adding docs about CDI Events fired in JPATransactionInterceptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelGuerreiro committed Feb 24, 2015
1 parent f23dd65 commit 25caf7d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ To do that you just need to add the follow content into your project's `beans.xm
</decorators>
```

# CDI Events

While the JPATransactionInterceptor worries about handling the transaction, you can observe CDI events to include some logic of yours.

**Please, note that if you specializes or override the JPATransactionInterceptor, those events won't be fired.**
*Remember that CDI Events doesn't have an order when executing observers, so, when observing the same event in more than one method, they should be independents.*

The events are:
* Before trying to commit the transaction: `BeforeCommit`;
* After successfully committing the transaction: `AfterCommit`;
* After successfully rolling back (rollback) the transaction: `AfterRollback`;

```Java
import javax.enterprise.event.Observes;

import br.com.caelum.vraptor.jpa.event.BeforeCommit;
import br.com.caelum.vraptor.jpa.event.AfterCommit;
import br.com.caelum.vraptor.jpa.event.AfterRollback;

public class JPATransactionEventsObserver {
/* You can @Inject any dependencies here. */

public void beforeCommit(@Observes BeforeCommit before) {/* ... */}

public void afterCommit(@Observes AfterCommit after) {/* ... */}

public void afterRollback(@Observes AfterRollback after) {/* ... */}
}
```

# Help

Get help from vraptor developers and the community at VRaptor's mailing list.

0 comments on commit 25caf7d

Please sign in to comment.