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.

Source Listing

Following is a full listing of all source code used in this runnable example.

Implementation Resources

BankLocalBusiness.java

package org.jboss.ejb3.examples.ch17.transactions.api; import java.math.BigDecimal; import org.jboss.ejb3.examples.ch17.transactions.entity.Account; /** * Defines the contract for a bank * * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a> ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.