Enterprise JavaBeans, Second Edition

Book description

Enterprise JavaBeans (versions 1.1 and 1.0) is an important technology for server-side application development in Java. It offers a component architecture for developing distributed, multitiered enterprise applications. This model allows you to build complex, mission-critical systems using simple snap-together pieces that model individual business objects and processes. Enterprise JavaBeans (EJB) greatly simplifies the process of development by automatically taking care of system issues like object persistence and transaction management. This book provides a thorough introduction to EJB 1.1 and 1.0 for the enterprise software developer. It shows you how to develop enterprise Beans to model your business objects and processes. One powerful advantage of the EJB architecture is that it allows you to partition work appropriately between different parts of the system: the database provides persistence, your Beans model various business entities and the interactions between them, and your client application provides a user interface, but incorporates minimal business logic. The end result is a highly flexible system built from components that can easily be reused, and that can be changed to suit your needs without upsetting other parts of the system. Enterprise JavaBeans, 2nd Edition teaches you how to take advantage of the flexibility and simplicity that this powerful new architecture provides. This book covers:

  • Enterprise JavaBeans 1.1 and 1.0

  • Developing entity Beans and session Beans

  • XML Deployment Descriptors

  • Using the client-side API to use enterprise Beans

  • Transaction Management

  • Design Strategies

  • Introduction to J2EE

Table of contents

  1. Enterprise JavaBeans, 2nd Edition
    1. Dedication
    2. Preface
      1. What Is Enterprise JavaBeans?
      2. Who Should Read This Book?
      3. Organization
      4. Software and Versions
      5. Conventions
      6. Comments and Questions
      7. Acknowledgments
    3. 1. Introduction
      1. Setting the Stage
        1. Distributed Objects
        2. Server-Side Components
        3. Component Transaction Monitors
      2. Enterprise JavaBeans: Defined
      3. Distributed Object Architectures
        1. Rolling Your Own Distributed Object
      4. Component Models
      5. Component Transaction Monitors
        1. TP Monitors
        2. Object Request Brokers
        3. CTMs: The Hybrid of ORBs and TP Monitors
        4. Analogies to Relational Databases
      6. CTMs and Server-Side Component Models
        1. MTS
        2. EJB and CORBA CTMs
        3. Benefits of a Standard Server-Side Component Model
      7. Titan Cruises: An Imaginary Business
      8. What’s Next?
    4. 2. Architectural Overview
      1. The Enterprise Bean Component
        1. Classes and Interfaces
          1. The remote interface
          2. The home interface
          3. The bean class
          4. The primary key
          5. What about session beans?
        2. Deployment Descriptors and JAR Files
          1. EJB 1.0: Deployment descriptors
          2. EJB 1.1: Deployment descriptors
        3. The Unseen Pieces
          1. The EJB object
          2. The EJB home
          3. Deploying a bean
      2. Using Enterprise Beans
        1. Getting Information from an Entity Bean
        2. Modeling Workflow with Session Beans
          1. Stateless and stateful session beans
      3. The Bean-Container Contract
        1. The Container-Server Contract
      4. Summary
    5. 3. Resource Management and the Primary Services
      1. Resource Management
        1. Instance Pooling
          1. The entity bean life cycle
          2. Overview of state transitions
          3. Instance swapping
        2. The Activation Mechanism
      2. Primary Services
        1. Concurrency
          1. Reentrance
        2. Transactions
        3. Persistence
          1. Object-to-relational persistence
          2. Object database persistence
          3. Legacy persistence
        4. Distributed Objects
        5. Naming
        6. Security
          1. EJB 1.1: Role-driven access control
          2. EJB 1.0: Method-driven access control
      3. What’s Next?
    6. 4. Developing Your First Enterprise Beans
      1. Choosing and Setting Up an EJB Server
        1. Setting Up Your Java IDE
      2. Developing an Entity Bean
        1. Cabin: The Remote Interface
        2. CabinHome: The Home Interface
        3. CabinPK: The Primary Key
        4. CabinBean: The Bean Class
        5. EJB 1.1: The Deployment Descriptor
        6. EJB 1.0: The Deployment Descriptor
        7. cabin.jar: The JAR File
          1. EJB 1.1: Packaging the Cabin bean
          2. EJB 1.0: Packaging the Cabin bean
        8. Creating a CABIN Table in the Database
        9. Deploying the Cabin Bean
          1. EJB 1.1 deployment tools
          2. EJB 1.0 deployment tools
        10. Creating a Client Application
          1. EJB 1.1: Obtaining a remote reference to the home interface
          2. EJB 1.0: Obtaining a remote reference to the home interface
          3. Creating a new Cabin bean
      3. Developing a Session Bean
        1. TravelAgent: The Remote Interface
        2. TravelAgentHome: The Home Interface
        3. TravelAgentBean: The Bean Class
          1. EJB 1.1: TravelAgentBean
          2. EJB 1.0: TravelAgentBean
        4. EJB 1.1: TravelAgent Bean’s Deployment Descriptor
        5. EJB 1.0: The TravelAgent Beans’ Deployment Descriptor
        6. EJB 1.1: The JAR File
        7. EJB 1.0: The JAR File
        8. Deploying the TravelAgent Bean
        9. Creating a Client Application
    7. 5. The Client View
      1. Locating Beans with JNDI
      2. The EJB Client-Side API
        1. EJB 1.1: Java RMI-IIOP Conformance Requirement
        2. EJB 1.1 and 1.0: The Java RMI Programming Model
          1. EJB 1.1: Java RMI-IIOP type restrictions
          2. EJB 1.1: Explicit narrowing using PortableRemoteObject
        3. The Home Interface
          1. Removing beans
          2. Bean metadata
          3. EJB 1.1: The HomeHandle
          4. Creating and finding beans
        4. The Remote Interface
        5. EJBObject, Handle, and Primary Key
          1. Getting the EJBHome
          2. Primary key
          3. Comparing beans for identity
          4. Removing beans
          5. The bean handle
          6. EJB 1.1: HomeHandle
        6. Inside the Handle
    8. 6. Entity Beans
      1. Container-Managed Persistence
        1. The Remote Interface
          1. Set and get methods
        2. The Primary Key
          1. Compound primary keys
          2. Single-field key
          3. EJB 1.1: Undefined primary keys
        3. The Home Interface
          1. The find methods
        4. Java RMI Return Types, Parameters, and Exceptions
        5. The ShipBean Class
        6. Implementing the javax.ejb.EntityBean Interface
        7. The EntityContext
        8. The Create Methods
          1. ejbCreate( )
          2. ejbPostCreate( )
          3. ejbCreate() and ejbPostCreate( ) sequence of events
          4. Using ejbLoad() and ejbStore( ) in container-managed beans
          5. EJB 1.1: Deploying the ShipBean
          6. EJB 1.0: Deploying the ShipBean
        9. The Client Application
      2. Bean-Managed Persistence
        1. Making the ShipBean a Bean-Managed Entity
        2. Exception Handling
        3. EntityContext
        4. EJB 1.1: EJBContext
        5. EJB 1.0: EJBContext
        6. Obtaining a Connection to the Database
          1. EJB 1.1: Using JDBC in EJB
          2. EJB 1.0: Using JDBC in EJB
        7. The ejbCreate( ) Method
        8. The ejbLoad( ) and ejbStore( ) Methods
        9. The ejbRemove( ) Method
        10. ejbFind( ) Methods
        11. EJB 1.1: Deploying the Bean-Managed Ship Bean
        12. EJB 1.0: Deploying the Bean-Managed Ship Bean
      3. The Life Cycle of an Entity Bean
        1. Does Not Exist
        2. The Pooled State
        3. The Ready State
          1. Transitioning from the Pooled state to the Ready State via creation
          2. Transitioning from the Pooled state to the Ready State via a find method
          3. Transitioning from the Pooled state to the Ready State via activation
          4. Transitioning from the Ready State to the Pooled state via passivation
          5. Transitioning from the Ready State to the Pooled state via removal
        4. Life in the Ready State
        5. End of the Life Cycle
    9. 7. Session Beans
      1. The Stateless Session Bean
        1. Downloading the Missing Pieces
        2. The ProcessPayment Bean
          1. PAYMENT: The database table
          2. ProcessPayment: The remote interface
          3. Dependent classes: The CreditCard and Check classes
          4. PaymentException: An application exception
          5. ProcessPaymentHome: The home interface
          6. ProcessPaymentBean: The bean class
          7. EJB 1.1: Accessing environment properties
          8. EJB 1.1: EJBContext
          9. EJB 1.1: The ProcessPayment bean’s deployment descriptor
          10. EJB 1.0: The ProcessPayment bean’s deployment descriptor
      2. The Life Cycle of a Stateless Session Bean
        1. Does Not Exist
        2. The Method-Ready Pool
          1. Transitioning to the Method-Ready Pool
          2. Life in the Method-Ready Pool
          3. Transitioning out of the Method-Ready Pool: The death of a stateless bean instance
      3. The Stateful Session Bean
        1. The TravelAgent Bean
          1. TravelAgent: The remote interface
          2. TravelAgentHome: The home interface
          3. Taking a peek at the client view
          4. TravelAgentBean: The bean class
          5. Why use a Reservation entity bean?
          6. listAvailableCabins( ): Listing behavior
          7. EJB 1.1: The TravelAgent deployment descriptor
          8. EJB 1.0: The TravelAgent deployment descriptor
      4. The Life Cycle of a Stateful Session Bean
        1. Does Not Exist
        2. The Method-Ready State
          1. Transitioning to the Method-Ready state
          2. Life in the Method-Ready state
          3. Transitioning out of the Method-Ready state
          4. EJB 1.1 timeouts
          5. EJB 1.0 timeouts
        3. Passivated State
          1. EJB 1.1 system exceptions
    10. 8. Transactions
      1. ACID Transactions
        1. Is the TravelAgent Bean Atomic?
        2. Is the TravelAgent Bean Consistent?
        3. Is the TravelAgent Bean Isolated?
        4. Is the TravelAgent Bean Durable?
      2. Declarative Transaction Management
        1. Transaction Scope
        2. Transaction Attributes
          1. EJB 1.1: Setting a transaction attribute
          2. EJB 1.0: Setting a transaction attribute
        3. Transaction Attributes Defined
        4. Transaction Propagation
      3. Isolation and Database Locking
        1. Dirty, Repeatable, and Phantom Reads
          1. Dirty reads
          2. Repeatable reads
          3. Phantom reads
        2. Database Locks
        3. Transaction Isolation Levels
          1. EJB 1.1 transaction isolation control
          2. EJB 1.0 transaction isolation control
        4. Balancing Performance Against Consistency
          1. EJB 1.1: Controlling isolation levels
          2. EJB 1.0: Controlling isolation levels
      4. Non-Transactional Beans
      5. Explicit Transaction Management
        1. Transaction Propagation in Bean-Managed Transactions
        2. Heuristic Decisions
        3. UserTransaction
        4. Status
        5. EJBContext Rollback Methods
      6. EJB 1.1: Exceptions and Transactions
        1. Application Exceptions Versus System Exceptions
          1. System exceptions
          2. Application exceptions
      7. EJB 1.0: Exceptions and Transactions
        1. Container-Initiated Transactions
        2. Client-Initiated Transactions
        3. Bean-Managed Transactions
        4. Unchecked Exceptions
      8. Transactional Stateful Session Beans
        1. The Transactional Method-Ready State
          1. Transitioning into the Transactional Method-Ready state
          2. Life in the Transactional Method-Ready state
    11. 9. Design Strategies
      1. Hash Codes in Compound Primary Keys
        1. Well-Distributed Versus Unique Hash Codes
      2. Passing Objects by Value
        1. Dependent Objects
        2. Validation Rules in Dependent Objects
        3. Bulk Accessors
          1. Rules-of-thumb for bulk accessors
        4. Entity Objects
      3. Improved Performance with Session Beans
        1. Network Traffic and Latency
        2. Resource Consumption
        3. Striking a Balance
        4. Listing Behavior
          1. Implementing lists as arrays of structures
          2. Implementing lists as ResultSets
      4. Bean Adapters
      5. Implementing a Common Interface
        1. Why the Bean Class Shouldn’t Implement the Remote Interface
        2. The Business Interface Alternative
      6. Entity Beans Without Create Methods
      7. Entity Bean Relationships
        1. Simple Associations
          1. Maintaining the database mapping
          2. Mapping serializable to VARBINARY
          3. Preserving the primary key
          4. Preserving the handle
          5. Native Java persistence
        2. Complex Entity Relationships
          1. One-to-many database mapping
          2. Mapping serializable to VARBINARY
          3. Native Java persistence
      8. Object-to-Relational Mapping Tools
      9. When Entity Beans Are Not an Option
        1. Emulating Entity Beans with Session Beans
        2. Limiting Session Beans to Workflow
          1. Direct database access with JDBC
          2. Direct access with object-to-relational mapping tools
      10. Avoid Chaining Stateful Session Beans
    12. 10. XML Deployment Descriptors
      1. What Is an XML Deployment Descriptor?
      2. The Contents of a Deployment Descriptor
      3. The Document Header
      4. The Descriptor’s Body
      5. Describing Beans
        1. Session and Entity Beans
        2. Specifying Primary Keys
          1. Deferring primary key definition
        3. Environment Entries
        4. References to Other Beans
        5. References to External Resources
        6. Security Roles
      6. Describing Bean Assembly
        1. Specifying a Bean’s Transactional Attributes
        2. Specifying Security Roles and Method Permissions
          1. Assigning roles to methods
        3. Identifying Specific Methods
          1. Wildcard declarations
          2. Named method declarations
          3. Specific method declarations
          4. Remote/home differentiation
      7. The ejb-jar File
        1. The client-jar File
    13. 11. Java 2, Enterprise Edition
      1. Servlets
      2. Java Server Pages
      3. Web Components and EJB
      4. J2EE Fills in the Gaps
        1. J2EE Application Client Components
        2. Guaranteed Services
        3. Connectivity and Interoperability
      5. Fitting the Pieces Together
      6. Future Enhancements
    14. A. The Enterprise JavaBeans API
      1. Package: javax.ejb
        1. CreateException
        2. DuplicateKeyException
        3. EJBContext
        4. EJBException (1.1)
        5. EJBHome
        6. EJBMetaData
        7. EJBObject
        8. EnterpriseBean
        9. EntityBean
        10. EntityContext
        11. FinderException
        12. Handle
        13. HomeHandle (1.1)
        14. NoSuchEntityException (1.1)
        15. ObjectNotFoundException
        16. RemoveException
        17. SessionBean
        18. SessionContext
        19. SessionSynchronization
      2. Package: javax.ejb.deployment (EJB 1.0 Only)
        1. AccessControlEntry
        2. ControlDescriptor
        3. DeploymentDescriptor
        4. EntityDescriptor
        5. SessionDescriptor
    15. B. State and Sequence Diagrams
      1. Entity Beans
        1. Life Cycle State Diagram of the Entity Bean
        2. Sequence Diagrams for Container-Managed Persistence
        3. Sequence Diagrams for Bean-Managed Persistence
      2. Session Beans
        1. Stateless Session Beans
        2. Stateful Session Beans
        3. EJB 1.1: Interactions Between Exceptions and Transactions
    16. C. EJB Vendors
      1. Commercial Products
      2. Open Source Projects
    17. D. New Features in EJB 1.1
      1. Entity Beans
      2. Session Beans
      3. XML Deployment Descriptors
      4. The Default JNDI Context
        1. RMI over IIOP Narrowing
      5. Security
      6. Looking Ahead to EJB 2.0
    18. Index
    19. Colophon

Product information

  • Title: Enterprise JavaBeans, Second Edition
  • Author(s): Richard Monson-Haefel
  • Release date: September 2001
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781565928695