Appendix H. Transactions: Blackjack Game Example

Description

All but the most simple of applications will have the requirement that a composite action, say, “Register a User,” succeeds or fails completely. In these cases, the single request is in fact a collection of many smaller pieces of work. If any of these smaller pieces fail halfway through the request, our application can be left in some inconsistent or error state. The use of transactions verifies that all compound actions comply with the ACID properties (atomicity, consistency, isolation, and durability). In other words, compound actions will either complete or fail as a single unit.

EJB offers declarative and programmatic support for transactions via the Java EE TransactionManager, and it comes complete with annotations/XML to manage transactional boundaries.

Our example is a transactionally aware poker service, showing the use of @TransactionAttribute and the various TransactionAttributeTypes.

Get Enterprise JavaBeans 3.1, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.