Make your own free website on Tripod.com

 

Enterprise JavaBeans - Part 4

Gopalan Suresh Raj

Developing an N-tier EJB Application

How can you provide an EJB-based business solution by integrating session and entity beans? Assume you are a consulting firm that was just asked to develop an online store for a fictitious bookstore chain called Horses and Stable, Inc. This bookstore chain now wants to expand its business to the Web. Now suppose Horses and Stable Online carries about 5 million books and sells tens of thousands of copies of books every day.

Horses and Stable Online offers extensive book catalogs, as well as a variety of other resources including customer reviews, personal recommendations, and gift suggestions. When customers visit Horses and Stable Online, they should be able to:

While the previous scenario is hypothetical, you are likely to find similar requirements that need similar solutions in the real world. Throughout much of this chapter, we will gradually develop the functionality for this online bookstore, while explaining the concepts behind building and deploying powerful EJB applications

To develop the example, you must have the appropriate deployment tools and an EJB server. The deployment tools are used to generate enterprise bean containers, which are the classes that provide an interface to the low-level implementations in a given EJB server.

All the EJB source code follows certain naming conventions to help the EJB server find the application classes, containers, and database tables. For example, the source code that constitutes enterprise beans—the enterprise bean class, home interface, and primary key class names—use the remote interface name as a prefix. These naming conventions are discussed as we go along. While source file-naming conventions are standard across EJB server implementations, naming conventions used within the implementation sources are specific to the EJB server or other deployment tools.

All these examples make use of the EJB server "HomeBase" v0.5.1 (formerly called "EJBHome"—not to be confused with the javax.ejb.ejbhome interface) from Iona, the makers of the popular CORBA ORB Orbix. You can download a free implementation of HomeBase, as well as deployment tools for generating containers from http://ejbhome.iona.com. You can also, of course, opt to use any other EJB Server and deployment tools as long as you know how to modify your deployment descriptors to match the particular EJB server with which you are working. Similarly, you need a database and you should know how to set up the data source for your platform.

Assuming you follow through, by the end of this article, you will have built an online store from which books and music CDs can be purchased over the Web.

The code used for developing our online store consists of:

1. A couple of entity beans (Books and Music entity beans).

2. A session bean (Cart session bean) that creates and manages the entities.

3. A servlet client (Online servlet) that creates a Cart and mimics an online store.

4. An entity bean client to test out our entities.

5. A session bean client to test out our session bean.

6. A Microsoft Access database (Shop.mdb) containing the store inventory.

The following Figure 6, shows the architecture for our online bookstore. The Web browser client starts the whole process by initiating a session and sending a GET message to the Online servlet, which resides on a Web server. The init() method of the Online servlet class looks up the Cart EJB from the EJB server and creates the Cart EJB. The Cart EJB, in turn, creates a Books Entity bean and a Music Entity bean that talk to the database to get the work done.

Fig 6: The four-tier architecture for our online bookstore

Go to Part 5 of this article

You can always refer to my Homepage at http://www.execpc.com/~gopalan for more EJB source code. Another good resource is the EJB-INTEREST@JAVA.SUN.COM mailing list from Sun and the EJBHome mailing list ejbhome-discuss@iona.com from Iona.

click here to go to
My EJB HomePage...

 

About the Author...
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He is contributing author to a couple of books "Enterprise Java Computing-Applications and Architecture" and "The Awesome Power of JavaBeans". His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia site (http://www.execpc.com/~gopalan) or mail him at gopalan@execpc.com.

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since September 21,1998.

Last Updated : Dec 19, '98

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-2000, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.