EJB™ 2.1 Kick Start

Book description

Not just another EJB book, EJB 2.1 Kick Start distinguishes itself in two key ways. First, author Peter Thaggard builds his examples from the new paradigms introduced in EJB 2.X rather than simply rewriting EJB 1.0 code. The changes in EJB 2.X programming--particularly in the areas of deployment descriptors and data persistence--require a new way of thinking about application architecture. The second distinction comes from the use of a project life-cycle approach.

Thaggard presents examples using the define-describe-build approach advocated by the thought leaders in object-oriented programming rather than simply laying out the features of the EJB specification. The result is a readable book that will successfully guide EJB programmers and those migrating from EJB 1/x.

Table of contents

  1. Copyright
    1. Dedication
  2. About the Author
  3. Acknowledgments
  4. We Want to Hear from You!
  5. Introduction
    1. Roadmap
    2. Prerequisites
  6. I. Fundamental EJB
    1. 1. The Status Quo
      1. The Problem with the Status Quo
      2. The Knight in Shining Armor: EJB
        1. A New Approach to Development
      3. The Business Plan
      4. BookEaz Business Plan
        1. Distinguishing Characteristics
        2. Features and Functions of the Business
      5. Use Cases Lite
        1. Analysis Phase One: Catalog the System’s Users
        2. Analysis Phase Two: Catalog Functionality
        3. Analysis Phase Three: Describe Functionality as Use Cases
        4. The Analysis Model
      6. Use Case Analysis of BookEaz
        1. Actor Dictionary
        2. Use Case Dictionary for BookEaz
          1. Shoppers’ Candidate Use Cases
          2. Administrators’ Candidate Use Cases
          3. Order Fulfillment’s Candidate Use Cases
          4. Email System’s Candidate Use Cases
        3. Building the Analysis Model
        4. The Use Case Document
          1. Use Case Documentation Format
      7. BookEaz Use Case Document
        1. Use Case 1: Perusing a Shopping Page
          1. Preconditions
          2. Primary Flow
        2. Use Case 2: Searching for a Book
          1. Preconditions
          2. Primary Flow
          3. Subflow 1: Search by Author
          4. Subflow 2: Search by Title
          5. Subflow 3: Search by Subject
          6. Subflow 4: Display Matching Books
          7. Subflow 5: Display “Search Failed” Message
        3. Use Case 3: Adding a Book to a Cart
          1. Preconditions
          2. Primary Flow
          3. Subflow 1: User Decides Against Adding Book to Cart
        4. Use Case 4: Reviewing Cart Contents
          1. Preconditions
          2. Primary Flow
          3. SubFlow 1: Shopper Indicates Desire to Remove a Book
          4. SubFlow 2: Shopper Alters Quantity
        5. Use Case 5: Checking Out
          1. Preconditions
          2. Primary Flow
          3. Subflow 1: Shopper’s Identity Is Known
          4. Subflow 2: Shopper’s Identity Is Not Yet Known
          5. Subflow 3: Gather Payment Information
          6. Subflow 4: Gather Shipping Information
          7. Subflow 5: Confirming Purchase
        6. Use Case 6: Maintaining the Inventory Database
          1. Primary Flow
          2. Subflow 1: Wholesale Database Updates
          3. Subflow 2: Creating a New Entry
          4. Subflow 3: Deleting an Entry
          5. Subflow 4: Modifying an Entry
          6. Alternative Flow 1: Unable to Complete a Database Operation
        7. Use Case 7: Forwarding an Order
          1. Preconditions
          2. Primary Flow
        8. Use Case 8: Sending an Email Notification
          1. Preconditions
          2. Primary Flow
      8. Conclusion
    2. 2. Designing a Solution Using EJB
      1. Logical Modeling: The Key to Designing EJB Systems
      2. Keeping It Strictly Business
      3. BookEaz Sequence Diagrams
        1. SD1.0: Perusing a Shopping Page
          1. Discoveries
        2. SD2.0: Searching for a Title
          1. Discoveries
          2. Entity Bean Definition
          3. Entity Bean Home Interface
          4. Entity Bean Remote Interface
          5. Entity Bean Implementation
          6. Distributing Behavior
          7. Making a Class an Entity Bean
        3. SD3.0: Adding an Item to a Cart
          1. Discoveries
          2. Variations on a Bean: Local Objects
        4. SD4.0: Reviewing Cart Contents
          1. Discoveries
        5. SD5.0: Checking Out
          1. Discoveries
          2. A Bean of a Different Flavor: Session Beans
          3. Session Bean Home Interface
          4. Session Bean Remote Interface
          5. Session Bean Implementation
        6. SD5.1: Detailed View of Checkout
          1. Discoveries
        7. SD6.0: Wholesale Database Updates
          1. Discoveries
        8. SD7.0: Forwarding an Order
          1. Discoveries
          2. Message-Driven Beans
          3. Java Message Service (JMS) and Message-Driven Beans
        9. SD8.0: Email Notification
          1. Discoveries
      4. Conclusion
    3. 3. Implementing a Solution Using EJB 2.0
      1. The EJB Runtime Environment
        1. EJB Containers and Application Servers
      2. Installing an Application Server and Deploying EJBs into It
      3. Divide and Conquer
        1. Two Flavors of Entity Beans: CMP Versus BMP
          1. Container Managed Persistence Beans
        2. Declaring Book’s Remote Interface
          1. Discussion
        3. Declaring Book’s Home Interface
          1. Discussion
        4. Implementing BookBean
          1. Discussion
        5. Compiling Book’s Java Code
          1. Prerequisites for Compiling
      4. The Rest of the Story: Deploying EJBs
        1. Deployment Tools
        2. Using deploytool to Deploy Book
          1. Step 1: Create an Application
          2. Step 2: Create the Book EJB
        3. BookEaz’s Database Administrator Client
        4. Compiling and Running BookAdministrator
      5. Conclusion
    4. 4. Complex Entity Beans and Local Objects
      1. Implementing Local Entity Beans
        1. Coding ShoppingItem
          1. ShoppingItem’s Local Interface Implementation
          2. ShoppingItemHome’s Implementation
          3. ShoppingItemBean’s Implementation
        2. Deploying Local Entities
          1. Compile ShoppingItem’s Constituents
          2. Add ShoppingItem to the Book EJB JAR
          3. Configure General Information About ShoppingItem
          4. Fill In the Entity Settings Dialog Box
          5. Bind ShoppingItem to a Datasource
          6. Deploy Shopping
      2. Complex Entity Bean Relationships
        1. Limits on Relationships
          1. ShoppingCart’s Relationship with ShoppingItem
          2. ShoppingItem’s Relationship with Book
      3. Implementing and Deploying ShoppingCart
        1. ShoppingCart’s Remote Interface Implementation
        2. ShoppingCartHome’s Implementation
        3. ShoppingCartBean’s Implementation
        4. Deploying ShoppingCart
          1. Compile the Code
          2. Add ShoppingCart to the Shopping JAR
          3. Configure General Information About ShoppingCart
          4. Fill in the Entity Settings Dialog Box
          5. Inform DeployTool of ShoppingCart’s Use of ShoppingItemHome
          6. Define the ShoppingCart-to-ShoppingItem Relationship
          7. Bind ShoppingCart to a Datasource
          8. Deploy Shopping
          9. Test ShoppingCart
        5. Installing Predeployed EJBs
          1. Download ejb-jar-ic2.jar
          2. Add Order’s JAR to the Container
          3. Modify Order and LineItem to Coexist with the Container
          4. Assign JNDI Names to Order and LineItem
      4. Conclusion
    5. 5. Session Beans and Message-Driven Beans
      1. Coding Checkout
        1. Checkout Remote Interface
        2. Checkout Home Interface
        3. Checkout Implementation
          1. Design Compromise: Getting a ShoppingCart’s ShoppingItems
          2. Getting Home
        4. Deploying Session Beans
          1. Compile Checkout’s Java Components
          2. Create a New JAR to House Checkout
          3. Inform DeployTool That Checkout Is a Session Bean
          4. Configure Checkout’s Transaction Management Responsibilities
          5. Add References to ShoppingItemHome and OrderHome
      2. Implementing Message-Driven Beans
        1. Beans of a Slightly Different Flavor
        2. Deploying Message-Driven Beans
          1. Step 1: Compile FulfillmentBean.java
          2. Step 2: Create Fulfillment.JAR
          3. Step 3: Set the Bean’s Type to MDB
          4. Step 4: Configure Transaction Management
          5. Step 5: Configuring FulfillmentBean’s Message Queue
      3. Conclusion
  7. II. Reference
    1. 6. All About Deployment
      1. Deployment Overview
        1. Deployment Units
        2. EAR File Contents
        3. References Between Components
        4. The ejb-jar.xml Deployment Descriptor File
          1. Header Elements
          2. Mandatory Element: <?xml>
          3. Optional Element: <!DOCTYPE>
          4. Mandatory Section: <ejb-jar>
          5. Mandatory Section: <enterprise-beans>
        5. Defining a Session Bean with <session>
          1. Optional Element: <description>
          2. Optional Element: <display-name>
          3. Optional Element: <small-icon>
          4. Optional Element: <large-icon>
          5. Mandatory Element: <ejb-name>
          6. Optional Element: <home>
          7. Optional Element: <remote>
          8. Optional Element: <local-home>
          9. Optional Element: <local>
          10. Optional Element: <service-endpoint>
          11. Mandatory Element: <ejb-class>
          12. Mandatory Element: <session-type>
          13. Mandatory Element: <transaction-type>
          14. Optional Section: <env-entry>
          15. Optional Section: <ejb-ref>
          16. Optional Section: <ejb-local-ref>
          17. Optional Section: <service-ref>
          18. Optional Section: <security-role-ref>
          19. Optional Section: <security-identity>
          20. Optional Section: <resource-ref>
          21. Optional Section: <resource-env-ref>
          22. Optional Section: <message-destination-ref>
        6. Defining an Entity Bean with <entity>
          1. Optional Element: <description>
          2. Optional Element: <display-name>
          3. Optional Element: <small-icon>
          4. Optional Element: <large-icon>
          5. Mandatory Element: <ejb-name>
          6. Optional Element: <home>
          7. Optional Element: <remote>
          8. Optional Element: <local-home>
          9. Optional Element: <local>
          10. Mandatory Element: <ejb-class>
          11. Mandatory Element: <persistence-type>
          12. Mandatory Element: <prim-key-class>
          13. Mandatory Element: <reentrant>
          14. Optional Element: <cmp-version>
          15. Optional Element: <abstract-schema-name>
          16. Optional Elements: <cmp-field>
          17. Optional Element: <primkey-field>
          18. Optional Section: <env-entry>
          19. Optional Section: <ejb-ref>
          20. Optional Section: <ejb-local-ref>
          21. Optional Section: <service-ref>
          22. Optional Section: <security-role-ref>
          23. Optional Section: <security-identity>
          24. Optional Section: <resource-ref>
          25. Optional Section: <resource-env-ref>
          26. Optional Section: <message-destination-ref>
          27. Optional Sections: <query>
        7. Defining a Message-Driven Bean with <message-driven>
          1. Optional Element: <description>
          2. Optional Element: <display-name>
          3. Optional Element: <small-icon>
          4. Optional Element: <large-icon>
          5. Mandatory Element: <ejb-name>
          6. Mandatory Element: <ejb-class>
          7. Optional Element: <messaging-type>
          8. Mandatory Element: <transaction-type>
          9. Optional Element: <message-selector>
          10. Optional Element: <acknowledge-mode>
          11. Mandatory Section: <message-driven-destination>
          12. Optional Section: <env-entry>
          13. Optional Section: <ejb-ref>
          14. Optional Section: <ejb-local-ref>
          15. Optional Section: <service-ref>
          16. Optional Section: <security-role-ref>
          17. Optional Section: <security-identity>
          18. Optional Section: <resource-ref>
          19. Optional Section: <resource-env-ref>
          20. Optional Section: <message-destination-ref>
        8. Describing Container Managed Relationships (CMR)
          1. Optional Section: <relationships>
          2. Mandatory Section: <ejb-relation>
          3. Optional Element: <description>
          4. “Virtually Mandatory” Element: <ejb-relation-name>
          5. Mandatory Section: <ejb-relationship-role>
          6. This Role and the Other Role
          7. Optional Element: <description>
          8. “Virtually Mandatory” Element: <ejb-relationship-role-name>
          9. Mandatory Element: <multiplicity>
          10. Optional Element: <cascade-delete/>
          11. Mandatory Section: <relationship-role-source>
          12. Mandatory Section: <cmr-field>
        9. Assembling EJBs: Security and Transactions
          1. Optional Section: <assembly-descriptor>
          2. Optional Section: <security-role>
          3. Optional Section: <method-permission>
          4. Mandatory Section: <method>
          5. Declaring Transactions with <container-transaction>
          6. Optional Section: <container-transaction>
          7. Optional Section: <message-destination>
      2. Conclusion
    2. 7. Entity Beans
      1. Compiling and Running Chapter 7’s Examples
      2. Remote/Local Interfaces
        1. Remote Interface Container-Supplied Methods
          1. EJBObject.getEJBHome()
          2. EJBObject.getHandle()method
          3. EJBObject.getPrimaryKey()method
          4. EJBObject.isIdentical()
          5. EJBObject.remove()method
        2. Remote Interface Getters, Setters, and Business Methods
        3. Local Interface Container-Supplied Methods
        4. Local Interface Getters, Setters, and Business Methods
      3. Remote and Local Home Interfaces
        1. Remote Home Interface Container-Supplied Methods
          1. EJBHome.getEJBMetaData()
          2. EJBHome.getHomeHandle()
          3. EJBHome.remove() Methods
        2. Create Methods
        3. Remote Home Interface Finder Methods
        4. Remote Home Interface Home Methods
        5. Local Home Interface’s Remove Method
        6. Local Home Interface’s Create, Finder, and Home Methods
      4. Entity Bean Implementations
        1. CMP Implementations
          1. CMP Implementations of Getters and Setters
          2. CMP Implementations of Business Methods
          3. CMP ejbcreate...() Methods
          4. CMP ejbPostCreate...() Methods
          5. CMP remove() Methods
          6. CMP ejbActivate() Methods
          7. CMP ejbPassivate() Methods
          8. CMP ejbLoad() Methods
          9. CMP ejbStore() Methods
          10. CMP setEntityContext() Methods
          11. CMP unsetEntityContext() Methods
          12. CMP Implementations of ejbTimeOut()
          13. CMP Implementations of Home Methods
          14. CMP select...() Methods
          15. CMP find...() Methods
        2. EJB QL “Lite”: Defining Finders and Selectors with EJB QL
          1. Abstract Schemas
          2. EJB QL Syntax
          3. The SELECT Clause
          4. The FROM Clause
          5. The WHERE clause
          6. The ORDER BY Clause
          7. For More Information
        3. BMP Implementations
          1. BMP Implementations of Attributes, Getters, and Setters
          2. BMP Implementations of Business Methods
          3. BMP create...() Methods
          4. BMP PostCreate() Methods
          5. BMP ejbRemove() Methods
          6. BMP ejbActivate() Methods
          7. BMP ejbPassivate() Methods
          8. BMP ejbLoad() Methods
          9. BMP ejbStore() Methods
          10. BMP setEntityContext() Methods
          11. BMP unsetEntityContext() Methods
          12. BMP Implementations of ejbTimeOut()
          13. BMP Implementations of Home Methods
          14. BMP select...() Methods
          15. BMP find...() Methods
    3. 8. Session Bean Reference
      1. Compiling and Running the Examples
      2. Stateful and Stateless Session Beans
      3. Session Bean Component Interface
        1. Session Bean Remote Interface Container-Supplied Methods
          1. Remote Versus Very Distant Clients
          2. The EJBObject.getEJBHome() Method
          3. The EJBObject.getHandle() Method
          4. The EJBObject.isIdentical() Method
          5. The EJBObject.remove() Method
        2. Business Method Declarations in Session Bean Remote Interfaces
        3. Local Interface Container-Supplied Methods
        4. Business Method Declarations in Session Bean Local Interfaces
      4. Business Method Declarations in Web Service Endpoint Interfaces
      5. Remote and Local Session Bean Home Interfaces
        1. Remote Home Interface Container-Supplied Methods
          1. The EJBHome.getEJBMetaData() Method
          2. The EJBHome.getHomeHandle() Method
          3. The EJBHome.remove() Method
        2. Create Methods
        3. The Local Home Interface’s remove() Method
        4. The Local Home Interface’s create...() Method
      6. Session Bean Implementations
        1. Business Method Implementations
        2. Session Bean ejbCreate...() Implementations
        3. Session Bean Life-Cycle Management Methods
          1. The setSessionContext() Method
          2. The ejbPassivate() Method
          3. The ejbActivate() Method
          4. The ejbRemove() Method
        4. Common Session Bean Implementation Practices
          1. Session Beans Manipulating Databases
          2. Session Beans Using Other Session Beans
          3. Acquiring Resources at Bean Creation Time
          4. Use Local Beans Whenever Possible
      7. Conclusion
    4. 9. Message-Driven Bean (MDB) Reference
      1. Queues and Topics
        1. MDB Structure
      2. The Two Interfaces of MDBs
        1. The onMessage() Method
        2. JAXM Message-Processing Methods
        3. Responding to Timer Service Events
        4. The ejbCreate() Method
        5. The ejbRemove() Method
        6. The setMessageDrivenContext() Method
        7. The MessageDrivenContext.setRollbackOnly() Method
        8. The boolean getRollbackOnly() Method
        9. The javax.transaction.UserTransaction getUserTransaction() Method
      3. MDB Best Practices
        1. Use MDBs to Interact with Legacy Systems
        2. Fire-and-Forget
      4. Conclusion
    5. 10. EJB 2.1 Web Service and Timer Service Support
      1. Web Services Overview
        1. Web Service Components
          1. Web Service Implementations
          2. Web Service Registries
          3. Web Service Descriptions
          4. Web Service Invocation Mechanism
          5. Web Service Message Format
      2. Implementing Web Services As Session Beans
        1. Web Service Endpoint Interface
        2. Session Bean Implementation
        3. Web Service Deployment Descriptor
      3. EJB 2.1 Timer Service
      4. Creating a Timed Object
        1. Registering Interest in Timed Events
        2. Receiving and Processing Timer Notifications
          1. EJB Type and Timer Behavior
      5. Conclusion
  8. III. Appendixes
    1. A. Introduction to UML for Analysis and Design
      1. Models and Diagrams
        1. Modeling Tools
      2. Documenting Analysis with Use Cases and Scenario Diagrams
        1. Sequence Diagrams: Showing the Order of Interactions
          1. Sequence Diagram Instances
          2. Messages
          3. Narrative
          4. Using Sequence Diagrams During the Design Phase
        2. Collaboration Diagrams
        3. Instance Diagrams
        4. Static and Dynamic Relationships
      3. Class Diagrams
        1. Classes
          1. Name Compartment and Stereotypes
          2. Attributes Compartment
          3. Operations Compartment
        2. Relationships
          1. Bidirectional Association
          2. Unidirectional Association
          3. Extends Relationship
          4. Implements Relationship
          5. Depends Relationship
      4. Conclusion
    2. B. Installing and Configuring the J2EE Reference Server
      1. Obtaining and Installing the Reference Server
        1. Installing the Reference Server on Windows
        2. Starting the Reference Server
        3. Using j2EEadmin to Configure the Reference Server
          1. Add Cloudscape’s JDBC Driver
          2. Add BookEaz’s BooksInCloudscape JDBC Datasource
    3. C. Installing and Configuring WebLogic Server
      1. Installing WebLogic Server 6.1, Service Pack 2
      2. Obtaining and Installing WebLogic Server 6.1
        1. Configuring Cloudscape for WebLogic Server 6.1
      3. Installing WebLogic Server 7.0
        1. Creating BookEazDomain in WebLogic Server 7.0
        2. Configuring PointBase 4.2 Database Server
        3. Configuring the Server via WebLogic’s Console
          1. Add the Database Cloudscape Connection Pool
          2. Add BookEaz’s Cloudscape JDBC Datasource
          3. Add FulfillmentBean’s JMS Connection Factory
          4. Add FulfillmentBean’s Message Queue
      4. Conclusion

Product information

  • Title: EJB™ 2.1 Kick Start
  • Author(s): Peter Thaggard
  • Release date: November 2002
  • Publisher(s): Sams
  • ISBN: 9780672321788