O'Reilly logo

Enterprise JavaBeans 3.1, 6th Edition by Bill Burke, Andrew Lee Rubinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required