Home > Store > Programming > Java

Developing EJB 2.0 Components

Register your product to gain access to bonus material or receive a coupon.

Developing EJB 2.0 Components

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2002
  • Dimensions: K
  • Pages: 656
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-034863-5
  • ISBN-13: 978-0-13-034863-0

A practical guide to Enterprise JavaBeans 2.0 technology.

  • Master J2EE 1.3 platform architecture, design, and deployment
  • Leverage the full power of J2EE technology to build more robust and functional components
  • Covers message-driven beans, transactions, security, design patterns, and enhancements to the Enterprise JavaBeans component model

Developing EJB 2.0 Components is a "nuts and bolts" guide to real-world EJB 2.0 component architecture development. Whether you're new to the J2EE platform or upgrading from previous versions, leading developer and trainer Pravin Tulachan shows you how to make the most of EJB 2.0 technology within the context of the J2EE 1.3 platform. You won't just learn how to use session, entity, and message-driven beans—you'll learn how to leverage J2EE technology to maximize the functionality and robustness of every component you create. Coverage includes:

  • EJB 2.0 technology n-tier architecture and design guidelines, performance issues, and optimization strategies
  • Practical approaches for leveraging JNDI and RMI-IIOP
  • How to make the most of the new message-driven beans
  • Session and entity beans: features, characteristics, and lifecycles
  • Advanced techniques for packaging and deploying components
  • Migrating applications from EJB 1.1 component architecture to EJB 2.0 component architecture
  • EJB architecture design patterns, interoperability, and performance

Many chapters include a complete, easy-to-adapt project. In addition, Tulachan integrates these projects into a full-fledged enterprise application that demonstrates every key facet of EJB 2.0 technology.

Take full advantage of the J2EE platform with the one book that shows you how-Developing EJB 2.0 Components.

Developing EJB 2.0 Components delivers hands-on coverage of:

  • Stateless and stateful session beans
  • Bean-managed and container-managed entity beans
  • Message-driven beans and the JMS API
  • Java Transaction API (JTA)
  • Security options
  • Deployment and performance

Sample Content

Online Sample Chapters

Developing CMP 2.0 Entity Beans

Developing Message-Driven Beans

The Benefits of Java Message Service

Table of Contents

(NOTE: Each chapter concludes with a Summary.)

Preface.

I. OVERVIEW.

1. Introduction TO Java 2 Enterprise Edition 1.3.

The Evolution of Enterprise Computing. Considerations of Enterprise Computing. Enterprise Computing Platforms. Technologies Required by J2EE 1.3. The J2EE Architecture. Technical Advantages of the J2EE Architecture. Business-Related Advantages of the J2EE Architecture. J2EE Development and Deployment Roles. Developing a J2EE Application. J2EE Disadvantages.

2. Introduction to Enterprise JavaBeans 2.0.

The Software Component Model. Enterprise JavaBeans Architecture. EJB Security. EJB Advantages. EJB Disadvantages. Differences between Enterprise JavaBeans and JavaBeans.

II. DEVELOPING EJBS.

3. Overview of Sample Applications.

Naming Conventions. Locating Example Source Code. Database Tables. Sample Application Descriptions.

4. The EJB Client View.

Distributed Objects. Introduction to JNDI. JNDI in a Client Application. JNDI and EJBs. Introduction to RMI-IIOP. The EJB Client View. Remote and Local Interfaces. Local and Remote Interface APIs. Rules for Writing Remote and Local Interfaces. Creating a Remote Client Application. Compiling and Executing HelloWorld. Packaging the HelloWorld Application. Using the Local or the Remote Interface. Application Performance.

5. Introduction to Session Beans.

Session Bean Characteristics. Types of Session Beans. Session Bean Elements. Writing Session Beans: Rules and Requirements. Roles of the Deployment Tool in Implementing Session Beans. Packaging a Session Bean. Deployment.

6. Developing Stateless Session Beans.

Characteristics and Features of Stateless Session Beans. Stateless Session Bean Life Cycles. A Stateless Schedule Bean Application.

7. Developing Stateful Session Beans.

Characteristics of SFSBs. When to Use SFSBs. The SFSB Life Cycle. Implementing a Shopping Cart Application.

8. Introduction to Entity Beans.

Overview. Entity Bean Characteristics. Types of Entity Beans. Life Cycle of an Entity Bean. Entity Bean Elements. Rules for Implementing the Entity Bean Class. Rules for Method Implementation. Comparing BMP and CMP Entity Beans. Concurrent Access in Entity Beans. Differences between Session and Entity Beans. Object Identity, Handle, and Primary Key. New Features of CMP 2.0 Entity Beans.

9. Developing Bean-Managed Entity Beans.

BMP Characteristics. Bean-Managed Persistence. BMP Sample Application.

10. CMP 2.0: Abstract Persistence Model and EJB QL.

CMP 2.0 Entity Bean Architecture. EJB Query Language. Rules for Writing CMP 2.0 Entity Bean Classes. Rules for Writing Abstract Accessor Methods. Rules for Writing Dependent Value Classes. Rules for Writing ejbSelect Methods. Responsibilities in CMP Entity Bean Development. Comparing BMP and CMP Entity Beans. The Primary Key for CMP 2.0 Entity Beans.

11. Developing CMP 2.0 Entity Beans.

Characteristics of CMP 2.0 Entity Beans. Advantages of CMP Entity Beans over BMP Entity Beans. CMP 2.0 Entity Bean Sample Application.

12. Java Message Service.

Introduction to Java Message Service. JMS Architecture. Messaging Domain Models. The JMS Programming Model. JMS Integration with EJBs.

13. Developing Message-Driven Beans.

Characteristics of MDBs. Elements of MDBs. The Life Cycle of MDBs. Comparing MDBs with Session and Entity Beans. Rules for Writing the MDB Class and Its Methods. MDB EJB Sample Application: RosterMDB. RosterApp Deployment Descriptors.

III. ADVANCED TOPICS.

14. Transactions.

An Introduction to Transactions and Their Benefits. The Transaction Model. ACID Properties of a Transaction. Transaction Attributes. Implementing Transactions Programmatically or Declaratively. Transaction Behavior of SFSB, BMP, and CMP Entity Beans. Initiating a Transaction. Bean-Managed versus Container-Managed Transaction Demarcation. Isolation Levels. Transaction Roles and Responsibilities.

15. Enterprise JavaBean Security.

Understanding the EJB Security Model. Roles in Implementing EJB Security. Implementing Security Declaratively. Implementing Security Programmatically. Declarative versus Programmatic Security. Implementing Resource Manager Security. Security Applicability and Restrictions. Security Interoperability. Roles and Responsibilities in Implementing Security.

16. EJB Design Patterns, Interoperability, and Performance.

Introduction to EJB Design Patterns. Data Access Object. Value Object. Value Object Assembler. Value List Handler. Service Locator. Session Façade. Business Delegate. Additional Patterns. EJB Interoperability. EJB Performance Issues.

17. Migrating EJB 1.1 Applications to the EJB 2.0 Container.

Migration Options and Approaches. EJB 1.1 Shortcomings. Migrating EJB 1.1 Applications to EJB 2.0.

18. Assembling the J2EE Online Registration Application.

Design Goals. Applying Design Patterns. Refactoring Existing EJBs. Assembling and Deploying the Application. Final Thoughts.

19. Installing and Running Sun Reference Implementation J2SDKEE 1.3.

Installation Requirements. Installation Overview in Brief. Setting up the Development Environment. Setting up the Application Environment. Preparing the J2SDKEE for Operation.

Index.

Preface

Preface

What Are Enterprise JavaBeans (EJB)?

If you've picked up this book and are reading this page, it's probably because you're curious about or interested in Enterprise JavaBeans (EJB), Java 2 Enterprise Edition, or Java. Or perhaps you just liked the cute giraffe on the cover with its backdrop of Mt. Kilimanjaro and wondered what a giraffe was doing on a cover of a J2EE book.

This book is about Enterprise JavaBeans 2.0. EJB is a component model for building scalable, reusable, portable, transactional, and distributed enterprise business applications. Well-designed EJBs encapsulate discrete business logic, and EJBs that encapsulate different kinds of business logic can be assembled to form a complete business application. For example, one could take discrete EJBs that implement user authentication, credit card authorization, shopping cart, order fulfillment, inventory management, and customer relationship management tasks and assemble them into one integrated application, then add the Web front end and ... presto! You have an e-commerce application, are ready for an IPO (well, that was true back in 1999 and early 2000), and can afford to buy a two-bedroom mansion in Silicon Valley. We'll worry about profitability later.

Why Should You Buy This Book?

There are several good books on EJBs, and I'm sure there will be more in the future. Most current EJB books fall into two basic categories—standalone EJB books that focus solely on EJB and do a good job at it but usually lack context, and books that attempt to cover everything—all the J2EE technologies, CORBA, and even (in some cases) COM/DCOM, in one humongous tome. These latter books have plenty of breadth but usually lack depth.

This book, Developing EJB 2.0 Components, the first book in a three-book series, focuses exclusively on the practical aspects of how to implement EJB 2.0. It is an attempt to bring the right balance between depth and breath within the broader context of the Java 2 Enterprise Edition platform. The book incorporates a unique perspective from my experience as a J2EE developer and as an instructor who teaches Java programmers—nationally, internationally for Netscape, and currently for Sun—how to develop J2EE applications. The second book in the series, Developing Web Components and Web Services, will focus exclusively on the presentation and user-interaction aspects of the J2EE technologies. The third (as yet untitled) book will focus exclusively on the J2EE infrastructure technologies. Together, these three titles will provide the audience with the necessary practical knowledge, depth, and breadth to write robust J2EE applications.

So you must be wondering, "Why should I buy this book?" Following are some good reasons (my reasons, of course), but you be the judge.

Go the Whole Nine Yards

Let's face it: EJB has a steep learning curve. Implementing EJB applications can be complex, and knowing how to write an EJB component is just half of the challenge. After coding and compiling the EJB components, you need to package, assemble, and then deploy them—no trivial tasks for a beginning EJB developer. Unlike most EJB books, Developing EJB 2.0 Components not only has chapters that discuss the theory, the APIs, and the rules on writing various types of EJBs and their methods, but it also has a separate chapter that discusses step-by-step implementation details followed by packaging and deployment steps and information on how to run the sample application. This information is complete with a copious number of diagrams and screen captures of the steps to guide you to a successful completion for each type of EJB. If my instructor-lead training experience is any indication, most rookie EJB developers will appreciate my effort to show you how to "go the whole nine yards" (to borrow an expression from American football), or in other words, to implement a complete solution.

Respect Your Intelligence

One of the hardest tasks in writing a book like this is setting the level at which to write the sample applications. On one hand, they shouldn't be so long and complicated that they distract the attention of the audience from fundamental EJB concepts in the process of trying to figure out complicated and nifty algorithms. At the other extreme, the sample applications shouldn't be so simple that they add little or no value to the learning process. My view is that I respect your intelligence and don't need to impress you with complex examples, so I've taken the middle path. The sample applications are not too complicated and not too long, so you can focus on the fundamentals of EJB without being too simplistic. Once you've mastered the concepts, you can take the sample application and use it to add real-world business complexity to your own applications. Most of the examples implement discrete business logic per EJB, and the last chapter takes all the EJBs you've implemented in the previous chapters and assembles them into an integrated EJB application, applying EJB design patterns and best practices. I hope I've been successful with this approach.

Advanced EJB Concepts...When You're Ready for Them

I've purposely deferred discussing advanced and complex issues such as transactions, security, and design patterns in Part 3 of the book so as to focus on the fundamentals of EJBs. Once you've mastered the fundamentals of EJB 2.0, you can then dive into more advanced concepts in Part 3. In that section, we concentrate on how to implement EJB transactions, EJB security, EJB design patterns, and strategies for migrating from EJB 1.1 to EJB 2.0, with complete code examples.

Repetition is the Key to Learning

The approach this book takes is first to discuss the concepts, characteristics, APIs, and rules on how to write specific EJB in an introductory chapter and then follow up with an implementation chapter that repeats the key concepts and rules during step-by-step implementation of a sample code example. I believe the discussion of the EJB fundamentals, followed by reinforcement through repetition of key concepts with example code, helps reduce the learning curve.

What This Book Doesn't Cover

I've told you all the great reasons why you should buy this book, so in the interest of fairness, I'll be up front and tell you that in some cases, you might not want to buy it. Here's why.

Vendor Neutrality

This book doesn't discuss packaging, assembling, and deploying using BEA's Weblogic, IBM's Websphere, Sun's iPlanet, or any other brand-name application server. The EJB implementation details are standard, so they're applicable to all application servers. This book focuses on packaging, assembling, and deploying EJB applications using Sun's J2EE Reference Implementation's deployment tool (deploytool), so the instructions are specific to that tool. The main reason I chose J2SDKEE RI is the resource requirements—it requires less than 15 MB of drive space, features ease of installation, runs with 128 MB of RAM, and is free. Most brand-name application servers require 100 MB of disk space and a minimum of 256 MB of RAM (or more), and installations can be challenging.

Not a Java Programming Book

This book doesn't teach you Java programming—only how to write business applications using EJBs.

Servlet, JSP, SQL, JDBC, UML, or CORBA Not Covered

This book assumes that the reader has real-world Java programming experience and also has familiarity with HTML, servlet, JSP, SQL, JDBC, and CORBA. I use UML diagrams and assume you have basic familiarity with such diagrams.

Audience for This Book

This book is primarily geared toward helping new EJB programmers and existing EJB 1.1 programmers learn how to write business logic in EJB 2.0. The ideal reader should have at least one year of Java programming experience and be familiar with HTML, servlet, JSP, SQL, rmi, and JDBC.

How the Book Is Organized

The book consists of eighteen chapters and is organized in three parts.

Part 1: Overview

The first part of this book consists of two introductory chapters that give an introductory, non-technical overview of the Java 2 Enterprise Edition and Enterprise JavaBeans 2.0. Audiences who will benefit from this section are novice Java programmers and nonprogrammers (such as technical managers, project managers, and so forth) who can read these two chapters and get a good grasp of the fundamentals of J2EE (1.3) and EJB (2.0) technologies. The information in these chapters will help them communicate effectively with EJB programmers.
  • Chapter 1: Introduction to Java 2 Enterprise Edition 1.3—This chapter is a basic, nontechnical introduction to Java 2 Enterprise Edition. It discusses the various Java technologies required by the J2EE 1.3 specification and how they all fit together.
  • Chapter 2: Introduction to Enterprise JavaBeans 2.0—This chapter is an introduction to Enterprise JavaBeans 2.0 and discusses the basics of Enterprise JavaBeans without overwhelming the reader with technical details.

Part 2: Developing EJBs

The second part of this book is geared toward Java programmers and EJB programmers who are interested in learning how to implement EJB 2.0. The chapters in this section deal with theory, followed by a step-by-step guide to implementing, packaging and deploying session, entity, and message-driven beans.

  • Chapter 3: Overview of Sample Applications—This chapter offers a high-level implementation overview of sample applications of stateless and stateful session beans, bean-managed persistent and container-managed persistent entity beans, and message-driven beans.
  • Chapter 4: The EJB Client View—This chapter discusses the local and remote client view of EJB and rules for implementing remote and local interfaces and their advantages and disadvantages.
  • Chapter 5: Introduction to Session Beans—Here, you'll be introduced to characteristics, APIs, and details of session beans.
  • Chapter 6: Developing Stateless Session Beans—This chapter covers the life cycle of stateless session beans and provides a step-by-step guide to implementing, packaging, assembling, and deploying a stateless session bean sample application.
  • Chapter 7: Developing Stateful Session Beans—This chapter describes the life cycle of stateful session beans and provides a step-by-step guide to implementing, packaging, assembling, and deploying a stateful session bean sample application.
  • Chapter 8: Introduction to Entity Beans—This chapter discusses the basic characteristic of entity beans, their life cycle, API, and rules for writing entity beans.
  • Chapter 9: Developing Bean-Managed Entity Beans—This chapter povides a step-by-step guide to implementing, packaging, assembling, and deploying a BMP entity bean sample application.
  • Chapter 10: CMP 2.0: Abstract Persistence Model and EJB QL—This chapter helps you understand the concepts behind the abstract persistence schema and the EJB Query language.
  • Chapter 11: Developing CMP 2.0 Entity Beans—These pages offer a step-by-step guide to implementing, packaging, assembling, and deploying a CMP entity bean sample application.
  • Chapter 12: Java Message Service—This chapter discusses the JMS API, messaging models, and how to use JMS APIs.
  • Chapter 13: Developing Message-Driven Beans—This chapter is a step-by-step guide to implementing, packaging, assembling, and deploying a message-driven bean sample application.

Part 3: Advanced Topics

The final section in the book discusses advanced EJB concepts, including transaction, security, EJB design patterns, and migration issues.

  • Chapter 14: Transactions—This chapter discusses how to implement programmatic and declarative transactions in different types of EJBs.
  • Chapter 15: Enterprise JavaBean Security—This chapter discusses security concepts and how to implement programmatic and declarative security in EJBs.
  • Chapter 16: EJB Design Patterns, Interoperability, and Performance—This chapter discusses common EJB design patterns and issues with performance and interoperability in EJB 2.0.
  • Chapter 17: Migrating EJB 1.1 Applications to the EJB 2.0 Container—This chapter discusses issues involved in migrating EJB 1.1 beans to EJB 2.0 containers. It includes details and steps for migration of a sample application.
  • Chapter 18: Assembling the J2EE Online Registration Application—The final chapter takes some of the discrete EJBs components developed in Part 2 of the book, refactors them if necessary, applies appropriate design patterns, and creates a complete application. It also discusses some of the implementation issues.

Appendix

At the back of the book, you will find instructions on how to download, install, and set up Sun's J2SDKEE 1.3 Reference Implementation. For the latest updates, please go to the companion Web site at http://www.J2EEBootCamp.com and download Appendix.pdf.

Companion Web Site

To keep the book within reasonable number of pages, the book lists no examples in their entirety but instead takes code snippets from the sample examples to elucidate key concepts during the discussion. The complete source code, along with compiled classes and deployable ear files, are available for download from the companion Web site, http://www.J2EEBootCamp.com. I encourage you to return here for the latest on bug fixes, new articles, new sample examples, and my public speaking engagements.

Feel free to send comments and suggestions to pvt@j2eebootcamp.com, and I'll do my best to respond within a few days.

What's a Giraffe Doing on the Front Cover of an EJB Book?

I'm an avid adventure traveler, and as a server-side Java consultant working in Silicon Valley, I've been able to travel two months a year for the past several years, thanks to the Internet boom (ah, those good old days!). I always had a vague notion of writing a Java book someday, and it became a real-life goal during a long trip across East Africa-to be precise, at the top of Mt. Kilimanjaro on January 1, 2000 at the first sunrise of the millennium. So the picture on the cover of the book is my tribute to the majestic Mt. Kilimanjaro (the highest mountain in Africa), its amazing wildlife, and the diverse cultures and peoples of Africa.

AcknowledgmentsTo put it positively (and mildly), writing this book has been one of the most challenging experiences of my life. I know you've read such statements by other authors-and so have I-but it really is a challenge, trust me. Even though the book has only my name on it, there are many talented people who've played significant roles in making this book possible. Without their assistance, this book would not have become a reality.At Prentice Hall, I would like to express my gratitude to executive editor Greg Doench for accepting the J2EE book series proposal and bringing it to fruition. My thanks also go to marketing manager Debby vanDijk and acquisition editor Eileen Clark for all their efforts toward the completion of the book. I would also like to thank developmental editor Jim Markham for helping me with the development and structure of the book.Thanks also go to production coordinator, editor, and compositor Sybil Ihrig of Helios Productions, technical reviewer Rob Gordon, and editors Casey Andrysiak and Elizabeth Hayes for their meticulous reviews and suggestions regarding the content and style of the book. At Sun Press, I wish thank Michael Alread and Rachel Borden for their efforts in expediting production of the book.I would also like to express my thanks to three excellent authors-Phillip Heller (The Complete Java Certification), Marty Hall (Core Servlet and JavaServer Pages), and Peter Haggar (Practical Java Programming Guide) for their initial encouragement with my book. The acknowledgment list would be incomplete without expressing my deep appreciation to Jason Fish, business development manager at Sun Educational Services, for introducing me to Greg Doench at Prentice Hall and thus starting the ball rolling on the this book. Thanks, Jason.-Pravin Tulachan

Updates

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership