CELEBRATE EARTH WEEK
Save 70% on video training and simulators now through April 27*—use code EARTH. Shop now.
Written by the architects of the Enterprise JavaBean (EJB) specification, Applying Enterprise JavaBeans, Second Edition is an advanced programming guide and reference source which has been updated and expanded to reflect updates in the EJB 2.1 specification. This book is an invaluable resource for IT personnel building in-house applications and for the independent software vendors (ISVs) building applications for sale to enterprise.
The authors use example applications to clearly illustrate many of the typical problems encountered in enterprise application development, and to help developers learn to use the newest features of the EJB. Applying Enterprise JavaBeans, Second Edition also explores the use of EJB architecture in the construction and accessing of Web services, thus integrating applications across enterprises with interoperable, standards-based protocols and service description formats.
In-depth coverage includes such EJB topics as:
Applying Enterprise JavaBeans, Second Edition discusses when and how each EJB feature should be used in applications and concludes with a comprehensive API reference for developers. This book is an essential addition to every Java programmer's bookshelf.
Download the Sample Chapter related to this title.
Conventions Used in This Book.
Note about the Example Applications.
Contents of the Book.
From a Two-Tier to a J2EE Architecture.
Two-Tier Application Architecture.
Traditional Three-Tier Application Architecture.
Early Web-Based Application Architecture.
J2EE Application Architecture.
Advantages of the Enterprise JavaBeans Architecture.
Benefits to the Application Developer.
Benefits to Customers.
What Are Enterprise JavaBeans Applications?
Client View of Enterprise Beans.
Business Entities and Processes, and Enterprise Bean Types.
Implementation of Business Rules.
Enterprise Bean Types.
Session Beans and Entity Beans.
Choosing Entity Beans or Session Beans.
Using Java Classes Instead of Entity Beans.
Structure of Enterprise Beans.
Local and Remote Client Views.
Enterprise Bean Home Interfaces.
Enterprise Bean Component Interface.
Enterprise Bean Class.
Container Tools and Services.
Container Runtime Services.
EJB Container Provider.
EJB Server Provider.
When to Use Session Beans.
Using Session Beans in Web Applications.
Using Session Beans in Three-Tier Applications.
Understanding the State of a Session Object.
Stateful versus Stateless Session Beans.
Understanding Conversational State.
Overview of the Example Application.
User View of the Application.
Main Parts of the Application.
The Benefits Enrollment Business Process.
EnrollmentEJB Stateful Session Bean in Detail.
EnrollmentEJB Session Bean Parts.
EnrollmentBean Session Bean Class Details.
Client Developer's Perspective.
PayrollEJB Stateless Session Bean.
PayrollEJB Stateless Session Bean Parts.
Client Developer's Perspective.
How the Container Manages Session Beans at Runtime.
EJB Home Interface Lookup.
Session Object Creation.
Business Method Invocation.
Session Bean Passivation and Activation.
Session Object Removal.
Session Bean Timeout.
JMS and Communication Modes.
Synchronous and Asynchronous Communication.
Message-Driven Bean Concepts.
Implementing a Message-Driven Bean.
Message-Driven Beans and Transactions.
Message-Driven Bean Usage.
Using a Message-Driven Bean in the Benefits Application.
PayrollMDB Message-Driven Bean.
PayrollEJB Local Interfaces.
Using JMS and Connectors for Communication.
Using JMS to Communicate With Messaging Systems.
Using Connectors to Communicate With EISs.
Client View of an Entity Bean.
Primary Key and Object Identity.
Entity Object Life Cycle.
Entity Bean Handle.
Bean Developer View of an Entity Bean.
EJB QL Query Language.
Entity Bean Class Methods.
Entity Bean Instance Life Cycle.
Using the ejbLoad and ejbStore Methods.
Designing the Entity Bean Component Interface.
Concurrent Invocation of an Entity Object.
Using Entity Beans with Preexisting Data.
Main Parts of the Application.
Parts Developed by Wombat.
Overview of the Wombat Parts.
EnrollmentEJB Session Bean.
EmployeeEJB Entity Bean.
SelectionEJB Entity Bean.
PlanEJB Entity Bean.
DoctorEJB Entity Bean.
EnrollmentWeb Web Application.
BenefitsAdminWeb Web Application.
Packaging of Parts.
Parts developed at Star Enterprise.
EmployeeDatabase and Deployment of EmployeeEJB.
EmployeeBeanBMP Entity Bean Class.
Introduction to Web Services.
Web Services Technologies.
J2EE and Web Services.
Developing a Web Service Using Stateless Session Beans.
Developing a New Web Service.
Exposing A Stateless Session Bean as a Web Service.
Stateless Session Bean Web Service Example.
InsurancePlanAdminEJB Stateless Session Bean.
Developing and Packaging the Web Service.
Accessing a Web Service from an Enterprise Bean.
Accessing a Web Service Example.
Providence Web Service.
ProvidencePlanEJB Entity Bean.
ProvidenceDoctorEJB Entity Bean.
Document-Oriented Web Services.
Declarative Transaction Demarcation.
Transaction Attribute Values.
Transaction Attributes for Message Driven Beans.
Transaction Attributes for Sample Application.
Programmatic Transaction Demarcation.
Transaction Demarcated by a Client.
Transaction Demarcation by a Session Bean.
Pitfalls of Using Programmatic Transaction Demarcation.
Responsibilities of the System Administrator.
Administering Users and Security Principals.
Managing Principal Mapping.
Responsibilities of the Container Provider.
Authentication and Authorization Tasks.
Managing Multiple Applications and Domains.
Application Provider's View of Security.
Declarative Security Mechanism.
Using Run-As Principal.
Programmatic Security API.
Example Security Application.
Deploying Wombat's Enterprise Beans.
Deploying Star Enterprise's Beans.
EJBObject Interface Methods.
EJBLocalObject Interface Methods.
EJBHome Interface Methods.
EJBContext Interface Methods.
EJBMetaData Interface Methods.
EntityBean Interface Methods.
EntityContext Interface Methods.
Handle Interface Methods.
HomeHandle Interface Methods.
SessionBean Interface Methods.
SessionContext Interface Methods.
SessionSynchronization Interface Methods.
Session Bean Helper Classes.
EnrollmentBean Source Code.
PayrollEJB Session Bean Class.
Entity Application EnrollmentBean Implementation.
PlanBean Implementation Class.
PayrollBean Implementation Class Using Connectors.
CCI Interface Classes.
This book, now in its second edition, provides in-depth coverage of the Enterprise JavaBeans™ (EJB) 2.1 architecture. It describes how to develop and deploy enterprise applications using the latest EJB component architecture. This second edition covers the new features of the EJB architecture, including message-driven beans and asynchronous communication, enhanced container-managed persistence, support for Web services, and the EJB QL query language.
This book and the Java BluePrints program do not provide information on how to use individual Java technologies to write applications—that’s the role of the companion Java Tutorial program. Instead, Java BluePrints focuses on guidelines for application architecture.
Readers of this book should be familiar with the Java™ programming language, have a basic knowledge of the J2EE platform, and should have had some exposure to enterprise beans and the EJB architecture. Although we briefly cover the basics of the EJB architecture, this book is not meant to be a tutorial for those just getting started with enterprise beans. Instead, the book provides in-depth coverage of the EJB 2.1 architecture for information technology (IT) personnel implementing applications in-house and for independent software vendors (ISVs) developing generic applications for sale to enterprises.
The EJB architecture defines a component model for enterprise applications. It describes
The EJB architecture defines these interactions as contracts, which enable applications to use components from different sources. Because EJB components must adhere to these contracts, an application can consist of software components from multiple vendors.
The EJB specification defines the architecture contracts mainly from the point of view of the container vendor. In contrast, this book presents the EJB architecture from the point of view of the application developer—that is, the person who develops EJB applications.
A detailed description of the development of two enterprise applications forms the backbone of the book. Although the example applications are relatively simple, they illustrate many of the typical problems encountered in enterprise application development. We use these examples to show how the EJB architecture helps developers solve these problems.
The first example is a benefits enrollment application developed in-house by an IT department. This application works well for explaining how a session bean works and for illustrating how developers use session beans.
The second example takes the benefits application from the first example, which was developed in-house, and turns it into an application developed by an ISV. An ISV has different design goals from that of an in-house IT department. The ISV must design the application so that it can be easily deployed in many different customers’ operational environments. Because each customer has a unique operational environment, the ISV must address a number of challenges. In addition, an ISV typically needs to design the application so that it can be extended by a customer or integrator. We illustrate how the entity bean architecture helps ISVs to overcome these challenges.
The EJB 2.1 architecture makes it possible to implement applications as Web services. This updated edition of the book includes a chapter that describes how to incorporate and use enterprise beans in a Web service.
These annotated examples illustrate many of the techniques for applying the EJB architecture to specific problems in enterprise application development. In addition to the two application examples, we describe the individual features of the EJB architecture and discuss when and how they should be used in applications.
Although the typical application developer does not need to know how the EJB container works, we illustrate some of the inner workings of the EJB container. We do this mainly to give the reader an appreciation of how much work the container performs on behalf of the application.
You should refer to other publications related to the Java 2 platform, Enterprise Edition application architecture (J2EE™). The following books are of particular interest to those developing other application components besides enterprise beans:
It is important to note that the example applications described in the book are written without the use of an interactive development environment (IDE). Normally, enterprise developers use a commercial IDE when developing EJB applications. An IDE generates much of the JDBC and other database access code—code that is often tedious to write by hand. However, we wanted our examples to illustrate how the EJB architecture works and, had we used an IDE, the code generated by the IDE would obscure the discussion of the EJB architecture. Therefore, we chose to write all the code manually. Keep this in mind and realize that developing with the EJB architecture is easier than some of our code samples may indicate because in practice a lot of the code is generated automatically by the IDE.
Because our goal is to illustrate the use of the EJB architecture, we wanted to keep the code relatively simple. As a result, we don’t always show what some developers would consider to be the best coding practices for enterprise applications. By including code to show such practices, we would have obscured the EJB discussion. For the sake of simplicity of the code examples, we sometimes do not handle properly all exceptions thrown by the code.
The book begins by describing the advantages of the EJB architecture. Chapter 1, Advantages of the Enterprise JavaBeans™ Architecture, discusses the different enterprise application architectures and how they have evolved, especially with the growth of the Web. It describes the current state-of-the-art EJB, J2EE, and Web Services architectures, and how they are well suited to meet today’s enterprise computing needs.
Chapter 2, Enterprise JavaBeans Architecture Overview, provides a concise overview of the EJB architecture. For someone not so familiar with the EJB architecture, this chapter is a good starting point because it defines the EJB terminology and the structure of enterprise beans. It defines and describes EJB applications, and such basic concepts as business entities and business processes. It provides an overview of the different enterprise bean types, the parts that comprise an enterprise bean, and how to use enterprise beans to model business logic of enterprise applications.
The development of an EJB application can be thought of in terms of the tasks that need to be performed. To that end, Chapter 3, Enterprise JavaBeans Roles, delineates the roles and tasks involved during the application development process.
Once the stage has been set and the introductory material explained, the book focuses on session beans, entity beans, and message-driven beans. Two chapters focus on session beans and two chapters focus on entity beans. Chapter 4, Working with Session Beans, focuses on typical programming styles for applications using session beans. This chapter is of interest to bean developers implementing session beans and to application programmers developing session bean clients. For bean developers, the chapter describes how best to implement the methods of a session bean. For application programmers developing session bean clients, it shows how to use the session bean home, remote, and local interfaces properly. An extensive benefits enrollment application example illustrates the key points about session beans.
Chapter 5, Session Bean in Its Container, describes the support and services that an EJB container provides for a session bean. Containers typically provide services to session beans when they are deployed and customized for a particular operational environment, and at runtime, when a client application invokes the session bean. Although the container services are hidden from the bean developer and the client programmer, these services go a long way in simplifying bean and application development. This chapter describes much of what goes on behind the scenes.
After completing the discussion of session beans, Chapter 6, Enterprise Application Integration Using Message-Driven Beans and Connectors, presents message-driven beans. A message-driven bean is a new type of enterprise bean introduced in the latest EJB architecture. It enables asynchronous message-oriented communication with enterprise beans. This chapter presents the basic concepts of the Java Message Service (JMS) and then describes how to develop message-driven beans. The benefits enrollment application from the session bean chapter is extended to show how to integrate it with a payroll application in a loosely coupled manner using message-driven beans.
The book then shifts its focus to entity beans. Entity beans differ significantly from session beans. Chapter 7, Understanding Entity Beans, combines a presentation of the basic concepts regarding programming with entity beans, from both the client and bean developer points of view, along with a discussion of the services that the container provides to entity beans. This chapter is analogous to Chapter 5 for session beans. The chapter also provides a detailed description of strategies for managing entity object state: bean-managed and container-managed persistence, including the EJB QL query language. Chapter 8, Entity Bean Application Example, takes the benefits enrollment application example used for session beans and shows how to write the same application using entity beans. The example illustrates many of the techniques for working with entity beans and using container-managed persistence. It also illustrates how entity beans can be used by ISVs to make their application reusable across many customers’ operational environments.
Web services technologies have become prominent in the last few years as a means to integrate applications across enterprises using interoperable, standards-based protocols and service description formats. Chapter 9, Using Enterprise JavaBeans in Web Services, introduces Web services technologies. It describes how to use the EJB architecture to build and access Web services using new Java standard APIs that are currently being developed. Virtually all applications using enterprise beans rely on transactions. Chapter 10, Understanding Transactions, describes the EJB architecture approach to transaction demarcation. It covers the essential aspects of transactions necessary for application developers.
Security is another area of critical importance to enterprise applications. The EJB architecture provides declarative support for security management. Chapter 11, Managing Security, describes the EJB security environment, particularly from the point of view of the application developer.
Last, the book includes an appendix that contains the API reference, a second appendix that contains code samples of supporting classes, and a glossary of terms. The reference section contains all the interfaces defined by the EJB architecture as well as the methods within each interface.
We would like to thank the following individuals who, on short notice, took the time to review the early draft of the book and who provided us with invaluable feedback: Mark Hapner, Bill Shannon, Rahul Sharma, Rick Cattell, George Copeland (IBM), Susan Cheung (Oracle), Liane Acker (Encore Development), Jim Frentress (nPassage, Inc.), Moshe Sambol (GTE), and John Stearns.
Likewise, we want to thank the following individuals for reviewing the final draft of the book and for providing feedback: Liane Acker (Encore Development), Ken Nordby (IBM), Jorgen Thelin (Orbware), Marc Fleury (Telkel), Jim Healy, and Jim Frentress (nPassage, Inc.).
We especially want to thank Walter Jenny and Rahul Sharma. Walter’s programming brought the entity bean example application to life at the JavaOne show this past June. Rahul not only reviewed both drafts of the book, he also developed the PayrollBean to use the Connector specification to access a mainframe application.
We also want to acknowledge the following people who helped us accomplish all the tasks necessary to publish this book: Jeff Jackson, for enthusiastically encouraging us to do this book; Lisa Friendly and Jim Inscore, for assisting us with publication details; and Mike Hendrickson and Ross Venables, among others at Addison-Wesley, who had the flexibility to adapt their schedules to ours.
Download the Index
file related to this title.