Understanding JCA Transactions
By Mikhail Genkin2005-04-22
Overview of JCA Transactions
A working example will help explore some common JCA transaction issues. In this example, the task is to build an e-commerce application for a company whose primary business is selling manufactured goods to consumers. The company has decided to expand by establishing a Web presence and retailing its goods to a wider audience. The Web site will let any customer with a Web browser access the company's home page; browse the catalog of available products; view detailed price information, availability, and a description of available items; add items to a shopping cart; and, finally, make a purchase. To illustrate the required transactional behavior, I'll focus on the use case where the customer decides to make a purchase. Figure 1 shows the application design.
Figure 1. Accessing EIS in your e-commerce application
The company's existing IT infrastructure is built around two enterprise information systems. EIS1 is a mainframe running Cobol transactions under CICS. Transactions running on this system implement business logic and access data necessary for order entry and customer relationship management (CRM). EIS2 is an IMS system containing the product description catalog, pricing information, and inventory control. To support the required functions, your J2EE application must be able to access and seamlessly integrate data from both systems. In order to make a purchase, you need to perform the following actions as a unit of work (for a single transaction):
1. Get current product price (EIS2)
2. Enter the customer's order into the order system (EIS1)
3. Bill the customer (EIS1)
4. Update product availability information (EIS2)
A failure during steps 2, 3, or 4 will result in the undoing of all previous steps.
In this example Web application, the client (a JSP page in the Web tier) holds a reference to, and calls methods on, an instance of the CustomerSession stateful session EJB component. You use CustomerSession to store the shopping cart contents, product information from the catalog, and customer information. During the course of interaction with the end user, as shown in Figure 1, this session bean accumulates and stores product selections and customer-specific information necessary to make a purchase. Methods defined in CustomerSession make calls to methods on stateless session EJB components (with the bean serving as a facade) such as OrderService, to invoke transactions on an EIS.
In this design, the OrderService stateless session bean acts as a facade for EIS1. It defines the following methods:
1. OrderInfo addOrder(String customerId, ItemInfo itemInfo) uses the JCA common client interface (CCI) to invoke the SHIPTO transaction on EIS1. This transaction looks up the ship-to address for the customer and prepares information that the EIS then communicates to the shipping department. The return structure OrderInfo contains the order number (which is used for tracking), the shipping costs, and shipping address information.
2. BillingInfo billCustomer(String customerId, OrderInfo orderInfo) also uses the JCA CCI to invoke the BILLTO transaction on EIS1. This transaction looks up the customer's credit card number and debits the customer's account for the order amount. The return structure BillingInfo contains the total cost to the customer, including shipping fees and structures, the ID number for the order (used for tracking and cancellations), and customer information.
3. void cancelOrder(OrderInfo orderInfo) uses the JCA CCI to invoke the RMVORD transaction running on EIS1 to cancel the order.
The CatalogService session bean (see Figure 1) acts as a facade to EIS2. It defines the following methods:
1. double getItemPrice(String itemId) uses the JCA CCI to invoke the ITMPRICE transaction on EIS2. This transaction returns the latest pricing information for the item.
2. void updateStockInfo(String itemId, int numItems) uses the JCA CCI to invoke the UPDSTOCK transaction on EIS2. This transaction updates the current in-stock information based on item ID. The input parameter numItems can be positive or negative.
All five of these methods and the underlying EIS transactions running on two different systems have to execute as part of a single business transaction. In the next section, you'll see how this is accomplished.
Tutorial Pages:
» Learn How the Various Levels of Transaction Support Provided by Different EISs and Resource Adapters Can Affect Application Design.
» Overview of JCA Transactions
» Transaction Support Levels
» JCA Transaction Support
» Transaction Demarcation Strategies
» Programmatic Transaction Demarcation
» EJB Deployment Descriptor Settings
» In Conclusion
» Resources
First published by IBM DeveloperWorks
