Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Richard Monson-Haefel, Bill Burke, Sacha Labourey
Enterprise JavaBeans, Fourth Edition
Enterprise JavaBeans, 4th Edition
Preface
Author’s Note
What Is Enterprise JavaBeans?
Who Should Read This Book?
Organization
Part I: The Technical Manuscript
Part II: The JBoss Workbook
Software and Versions
Conventions
Comments and Questions
Acknowledgments
I. Lay of the Land
1. Introduction
Server-Side Components
Enterprise JavaBeans Defined
Distributed Object Architectures
Component Models
Competing Component Models: Microsoft’s .NET Framework
Benefits of a Standard Server-Side Component Model
Asynchronous Messaging
Java Message Service
Message-Driven Beans and J2eeCA 1.5
Web Services
Titan Cruises: An Imaginary Business
What’s Next?
2. Architectural Overview
The Enterprise Bean Component
Classes and Interfaces
Naming conventions
The remote interface
The remote home interface
The bean class
The primary key
What about session beans?
What about message-driven beans?
Deployment Descriptors and JAR Files
EJB 2.1: Deployment descriptor
EJB 2.0: Deployment descriptor
EJB 2.1 and 2.0: Elements of the XML deployment descriptor
EJB Objects and EJB Home
The EJB object
The EJB home
Deploying a bean
Using Enterprise Beans
Getting Information from an Entity Bean
Modeling Taskflow with Session Beans
Stateless and stateful session beans
Message-Driven Beans
The Bean-Container Contract
Summary
3. Resource Management and the Primary Services
Resource Management
Instance Pooling
The entity bean life cycle
Instance swapping
Message-driven beans and instance pooling
The Activation Mechanism
J2EE Connector Architecture
J2EE Connectors 1.0 for EJB 2.0 and 2.1
J2EE Connectors 1.5 for EJB 2.1
Primary Services
Concurrency
Concurrency with session and entity beans
Reentrance
Concurrency with message-driven beans
Transactions
Persistence
Object-to-relational persistence
Object database persistence
Legacy persistence
Container-managed versus bean-managed persistence
Distributed Objects
Asynchronous Enterprise Messaging
EJB 2.1 : Timer Service
Naming
Security
Role-driven access control
Unchecked methods
The runAs security identity
Primary Services and Interoperability
IIOP
SOAP and WSDL
What’s Next?
4. Developing Your First Enterprise Beans
Choosing and Setting Up an EJB Server
Setting Up Your Java IDE
Developing an Entity Bean
Cabin: The Remote Interface
CabinHome: The Remote Home Interface
CabinBean: The Bean Class
Container-managed fields
The callback methods
The Deployment Descriptor
EJB 2.1: The Cabin EJB’s deployment descriptor
EJB 2.0: The Cabin EJB’s deployment descriptor
EJB 2.1 and 2.0: Defining the XML elements
cabin.jar: The JAR File
Creating a CABIN Table in the Database
Deploying the Cabin EJB
Creating a Client Application
Creating a new Cabin EJB
Developing a Session Bean
TravelAgentRemote: The Remote Interface
TravelAgentHomeRemote: The Remote Home Interface
TravelAgentBean: The Bean Class
The TravelAgent EJB’s Deployment Descriptor
EJB 2.1: Deployment descriptor
EJB 2.0: Deployment descriptor
EJB 2.0 and 1.1: Defining the XML elements
Deploying the TravelAgent EJB
Creating a Client Application
5. The Remote and Local Client View
Locating Beans with JNDI
The Remote Client API
Java RMI-IIOP
Java RMI return types, parameters, and exceptions
Return types and parameters
Java RMI-IIOP type restrictions
Explicit narrowing using PortableRemoteObject
The Remote Home Interface
Removing beans
Bean metadata
The HomeHandle
Creating and finding beans
Home methods
The Remote Interface
EJBObject, Handle, and Primary Key
Getting the EJBHome
Primary key
Comparing beans for identity
Removing beans
The enterprise bean Handle
HomeHandle
Inside the Handle
The Local Client API
The Local Interface
The Local Home Interface
Deployment Descriptor
Using the Local Client API
When to Use Local Component Interfaces
Are Local Component Interfaces Necessary?
6. CMP: Basic Persistence
The Abstract Programming Model
Abstract Persistence Schema
Container Tools and Persistence
The Customer EJB
The Customer Table
The CustomerBean
The Remote Interface
The Remote Home Interface
The XML Deployment Descriptor
The EJB JAR File
Deployment
The Client Application
Persistence Fields
Dependent Value Classes
Relationship Fields
7. CMP: Entity Relationships
The Seven Relationship Types
Abstract Persistence Schema
Database Modeling
One-to-One, Unidirectional Relationship
Relational database schema
Abstract programming model
Abstract persistence schema
One-to-One, Bidirectional Relationship
Relational database schema
Abstract programming model
Abstract persistence schema
One-to-Many, Unidirectional Relationship
Relational database schema
Abstract programming model
Abstract persistence schema
The Cruise, Ship, and Reservation EJBs
Many-to-One, Unidirectional Relationship
Relational database schema
Abstract programming model
Abstract persistence schema
One-to-Many, Bidirectional Relationship
Relational database schema
Abstract programming model
Abstract persistence schema
Many-to-Many, Bidirectional Relationship
Relational database schema
Abstract programming model
Abstract persistence schema
Many-to-Many, Unidirectional Relationship
Relational database schema
Abstract programming model
Abstract persistence schema
Co-Location and the Deployment Descriptor
Cascade Delete and Remove
8. CMP: EJB QL
Declaring EJB QL
The Query Methods
Find Methods
Select Methods
EJB QL Examples
Simple Queries
Simple Queries with Paths
The IN Operator
Using DISTINCT
The WHERE Clause and Literals
The WHERE Clause and Input Parameters
The WHERE Clause and Operator Precedence
The WHERE Clause and CDATA Sections
The WHERE Clause and Arithmetic Operators
The WHERE Clause and Logical Operators
The WHERE Clause and Comparison Symbols
The WHERE Clause and Equality Semantics
The WHERE Clause and BETWEEN
The WHERE Clause and IN
The WHERE Clause and IS NULL
The WHERE Clause and IS EMPTY
The WHERE Clause and MEMBER OF
The WHERE Clause and LIKE
Functional Expressions
Functional expressions in the WHERE clause
EJB 2.1: Aggregate functions in the SELECT clause
COUNT (identifier or path expression)
MAX( path expression), MIN( path expression)
AVG( numeric ), SUM( numeric)
DISTINCT, nulls, and empty arguments
EJB 2.1: The ORDER BY Clause
Problems with EJB QL
The OBJECT( ) Operator
Lack of Support for Date
Limited Functions
Multiple SELECT Expressions
GROUP BY and HAVING
Subqueries
Dynamic Queries
9. Bean-Managed Persistence
The Remote Interface
Set and Get Methods
The Remote Home Interface
The Primary Key
The ShipBean
Obtaining a Resource Connection
Exception Handling
The ejbCreate( ) Method
The ejbLoad( ) and ejbStore( ) Methods
The ejbRemove( ) Method
The ejbFind( ) Methods
The Deployment Descriptor
10. The Entity-Container Contract
The Primary Key
Single-Field Primary Keys
Compound Primary Keys
Undefined Primary Keys in CMP
The Callback Methods
setEntityContext( ) and unsetEntityContext( )
ejbCreate( )
ejbCreate( ) and ejbPostCreate( ) Sequence of Events
Using ejbLoad( ) and ejbStore( ) in Container-Managed Persistence
Using ejbLoad( ) and ejbStore( ) in Bean-Managed Persistence
ejbPassivate( ) and ejbActivate( )
ejbRemove( )
ejbHome( )
EntityContext
EJBContext
JNDI ENC
The Life Cycle of an Entity Bean
Does Not Exist
The Pooled State
The Ready State
Transitioning from the Pooled state to the Ready state via creation
Transitioning from the Pooled state to the Ready state via a query method
Transitioning from the Pooled state to the Ready state via activation
Transitioning from the Ready state to the Pooled state via passivation
Transitioning from the Ready state to the Pooled state via removal
Life in the Ready State
End of the Life Cycle
11. Session Beans
The Stateless Session Bean
The ProcessPayment EJB
The database table (PAYMENT)
The remote interface (ProcessPaymentRemote)
Dependent objects (CreditCardDO and CheckDO classes)
An application exception (PaymentException)
The home interface (ProcessPaymentHomeRemote)
The bean class (ProcessPaymentBean)
Accessing environment properties (JNDI ENC)
The ProcessPayment EJB’s deployment descriptor
Local component interfaces
The Life Cycle of a Stateless Session Bean
Does Not Exist
The Method-Ready Pool
Transitioning to the Method-Ready Pool
Life in the Method-Ready Pool
Transitioning out of the Method-Ready Pool: The death of a stateless bean instance
The Stateful Session Bean
Getting Set Up for the TravelAgent EJB
The TravelAgent EJB
The remote interface (TravelAgent)
Dependent object (TicketDO)
The home interface (TravelAgentHomeRemote)
Taking a peek at the client view
TravelAgentBean: The bean class
JNDI ENC and EJB references
Remote EJB references in the JNDI ENC
Local EJB references in the JNDI ENC
The bookPassage( ) method
Why use a Reservation entity bean?
Listing behavior (listAvailableCabins( ))
The TravelAgent deployment descriptor
The Life Cycle of a Stateful Session Bean
Does Not Exist State
Method-Ready State
Transitioning to the Method-Ready state
Life in the Method-Ready state
Transitioning out of the Method-Ready state
Passivated State
System exceptions
12. Message-Driven Beans
JMS and Message-Driven Beans
JMS as a Resource
Reimplementing the TravelAgent EJB with JMS
TopicConnectionFactory and Topic
TopicConnection and TopicSession
TopicPublisher
Message types
XML deployment descriptor
EJB 2.1: Declaring a JMS Resource
EJB 2.0: Declaring a JMS Resource
JMS Application Client
JMS Is Asynchronous
JMS Messaging Models
Publish-and-subscribe
Point-to-point
Which messaging model should you use?
EJB 2.1: The Unified JMS API
Entity and Session Beans Should Not Receive Messages
Learning More About JMS
JMS-Based Message-Driven Beans
The ReservationProcessor EJB
The ReservationProcessorBean Class
MessageDrivenBean interface
MessageDrivenContext
MessageListener interface
Taskflow and integration for B2B (onMessage( ) )
Sending messages from a message-driven bean
XML Deployment Descriptor
EJB 2.1: Deployment descriptor for MDBs
EJB 2.0: Deployment descriptor for MDBs
Message selector
Acknowledge mode
EJB 2.1: <messaging-type>
EJB 2.1: <message-destination-type>
EJB 2.0: <message-driven-destination>
Subscription durability
The ReservationProcessor Clients
The reservation message producer
The ticket message consumer
The Life Cycle of a Message-Driven Bean
Does Not Exist
The Method-Ready Pool
Transitioning to the Method-Ready Pool
Life in the Method-Ready Pool
Transitioning Out of the Method-Ready Pool: The Death of an MDB Instance
Connector-Based Message-Driven Beans
EJB 2.1: Message Linking
13. Timer Service
Titan’s Maintenance Timer
Timer Service API
The TimerService Interface
Exceptions
The Timer
Cancelling timers
Identifying timers
Retrieving other information from timers
The TimerHandle object
Exceptions
Transactions
Entity Bean Timers
Stateless Session Bean Timers
Using a Stateless Session Timer
Message-Driven Bean Timers
Problems with the Timer Service
A very little bit about cron
Improving the Timer Service
Message-driven bean timers: Standard configuration properties
Other problems with Timer API
Final Words
14. EJB 2.1: Web Service Standards
Web Services Overview
XML Schema and XML Namespaces
XML Schema
XML Namespaces
SOAP 1.1
SOAP Messaging Modes
Exchanging SOAP Messages with HTTP
Now You See It, Now You Don’t
WSDL 1.1
The <definitions> Element
The <portType> and <message> Elements
The <types> Element
The <binding> and <service> elements
UDDI 2.0
From Standards to Implementation
15. EJB 2.1 and Web Services
Accessing Web Services with JAX-RPC
Generating JAX-RPC Stubs from WSDL
Using JAX-RPC Generated Stubs
The <service-ref> Deployment Element
The JAX-RPC Mapping File
EJB Endpoints
The WSDL Document
The Endpoint Interface
No Home Interface
The Stateless Bean Class
The Deployment Files
ejb-jar.xml file
WSDL file
JAX-RPC mapping file
webservices.xml file
16. Transactions
ACID Transactions
Is the TravelAgent EJB Atomic?
Is the TravelAgent EJB Consistent?
Is the TravelAgent EJB Isolated?
Is the TravelAgent EJB Durable?
Declarative Transaction Management
Transaction Scope
Transaction Attributes
Setting a transaction attribute
Transaction attributes defined
Container-managed persistence and transaction attributes
Message-driven beans and transaction attributes
EJB endpoints and transaction attributes
Transaction Propagation
Collection-Based Relationships and Transactions
Isolation and Database Locking
Dirty, Repeatable, and Phantom Reads
Dirty reads
Repeatable reads
Phantom reads
Database Locks
Transaction Isolation Levels
Balancing Performance Against Consistency
Controlling isolation levels
Nontransactional Beans
Explicit Transaction Management
Transaction Propagation in Bean-Managed Transactions
Message-driven beans and bean-managed transactions
Heuristic Decisions
UserTransaction
Status
EJBContext Rollback Methods
Exceptions and Transactions
System Exceptions Versus Application Exceptions
System exceptions
Application exceptions
Transactional Stateful Session Beans
The Transactional Method-Ready State
Transitioning into the Transactional Method-Ready state
Life in the Transactional Method-Ready state
17. J2EE
Servlets
JavaServer Pages
Web Components and EJB
Filling in the Gaps
J2EE Application Client Components
Guaranteed Services
Fitting the Pieces Together
18. XML Deployment Descriptors
The ejb-jar File
The Contents of a Deployment Descriptor
The Document Headerand Schema Declarations
The Descriptor’s Body
Describing Enterprise Beans
Session and Entity Beans
Message-Driven Beans
EJB 2.1 elements
EJB 2.0 elements
Specifying Primary Keys
Deferring primary key definition
Environment Entries
References to Other Beans
Remote references
Local references
References to External Resources
Additional administered objects
Shareable resources
The <service-ref> Deployment Element (EJB 2.1)
Security Roles
Declaring EJB QL Elements
Describing Relationships
Describing Bean Assembly
Specifying a Bean’s Transaction Attributes
Specifying Security Roles and Method Permissions
Assigning roles to methods
Unchecked methods
The runAs security identity
Exclude list
Identifying Specific Methods
Wildcard declarations
Named method declarations
Specific method declarations
Remote/home/local differentiation
19. EJB Design in the Real World
Pre-Design: Containers and Databases
Container Capabilities
Database Capabilities
Design
Business Entity Identification
Technical Architecture
EJB Identification
Identifying entity beans
Identifying session beans
Identifying message-driven beans
EJB Details
Stateless versus stateful session beans
Container-managed versus bean-managed persistence
Local versus remote interfaces
Fleshing Out the Design
Minimize transaction scope
Don’t confuse EJB types
Special Circumstances
Returning entity data from EJBs
Sequential processing with EJBs
Exceptions
Identifying application exceptions
Design the exception hierarchy
Wrap subsystem exceptions
Base and Utility Classes
Base classes
Utility classes
Should You Use EJBs?
When to Use EJBs
When Not to Use EJBs
Alternatives to EJB
JDBC
Java Data Objects
Others
Wrapping Up
II. JBoss Workbook
20. Introduction
Contents of the JBoss Workbook
Online Resources
Acknowledgments
21. JBoss Installation and Configuration
About JBoss
Installing JBoss Application Server
Discovering the JBoss Directory Structure
JBoss Configuration Files
Deployment in JBoss
A Quick Look at JBoss Internals
Microkernel Architecture
Hot Deployment
Net Boot
Detached Invokers
Exercise Code Setup and Configuration
Exercises Directory Structure
Environment Setup
22. Exercises for Chapter 4
Exercise 4.1: A Simple Entity Bean
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Deconstructing build.xml
Examine the JBoss-Specific Files
jboss.xml
Examine and Run the Client Applications
Client_1.java
Managing Entity Beans
Exercise 4.2: A Simple Session Bean
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
jboss.xml
ejb-jar.xml
jboss.xml
Examine and Run the Client Application
Client_3.java
TravelAgentBean.java
23. Exercises for Chapter 5
Exercise 5.1: The Remote Component Interfaces
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Examine and Run the Client Applications
Exercise 5.2: The EJBObject, Handle, and Primary Key
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Examine and Run the Client Applications
Exercise 5.3: The Local Component Interfaces
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
ejb-jar.xml
jboss.xml
Examine and Run the Client Applications
24. Exercises for Chapter 6
Exercise 6.1: Basic Persistence in CMP 2.0
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
jbosscmp-jdbc.xml
The <defaults> section
The <enterprise-beans> section
Examine and Run the Client Applications
Exercise 6.2: Dependent Value Classes in CMP 2.0
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Examine and Run the Client Applications
Exercise 6.3: A Simple Relationship in CMP 2.0
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
jbosscmp-jdbc.xml
Examine and Run the Client Applications
AddressBean.java
25. Exercises for Chapter 7
Exercise 7.1: Entity Relationships in CMP 2.0, Part 1
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Examine and Run the Client Applications
Client_71a
Client_71b
Client_71c
Exercise 7.2:Entity Relationships in CMP 2.0, Part 2
Start Up JBoss
Initialize the Database
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Examine and Run the Client Applications
Client_72a
Client_72b
Client_72c
Client_72d
Client_72e
Client_72f
Exercise 7.3: Cascade Deletes in CMP 2.0
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Examine and Run the Client Applications
26. Exercises for Chapter 8
Exercise 8.1: Simple EJB QL Statements
Start Up JBoss
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Initialize the Database
Examine and Run the Client Applications
Client_81a
Client_81b
Client_81c
Exercise 8.2: Complex EJB QL Statements
Start Up JBoss
Build and Deploy the Example Programs
Examine the JBoss-Specific Files
Initialize the Database
Examine and Run the Client Applications
Client_82a
Client_82b
Client_82c
Client_82d
Client_82e
Client_82f
Client_82g
Client_82h
Client_82i
Client_82j
Client_82k
Client_82m
Client_82n
JBoss Dynamic QL
Advanced JBoss QL
27. Exercises for Chapter 9
Exercise 9.1: A BMP Entity Bean
Start Up JBoss
Initialize the Database
Examine the EJB Standard Files
ejb-jar.xml (part I)
ejb-jar.xml (part II)
Examine the JBoss-Specific Files
jboss.xml
ShipBean.java
ejb-jar.xml
jboss.xml
Build and Deploy the Example Programs
Examine the Client Application
Client_91.java
Run the Client Application
Creating the database table
Testing the BMP bean
Analyzing the effects of transactions and commit options
jboss.xml
Possible optimizations
Dropping the database table
28. Exercises for Chapter 11
Exercise 11.1: A Stateless Session Bean
Examine the EJB
ProcessPaymentRemote.java
CheckDO.java
ProcessPaymentBean.java
Examine the EJB Standard Deployment Descriptor
ejb-jar.xml
ProcessPaymentBean.java
ProcessPaymentBean.java
Examine the JBoss Deployment Descriptors
jboss.xml
Start Up JBoss
Build and Deploy the Example Programs
Initialize the Database
Examine the Client Applications
Client_111a
Client_111b
Exercise 11.2: A Stateful Session Bean
Examine the EJB
Examine the EJB Standard Deployment Descriptor
ejb-jar.xml
Examine the JBoss Deployment Descriptor
jboss.xml
jbosscmp-jdbc.xml
Start Up JBoss
Build and Deploy the Example Programs
Initialize the Database
Examine the Client Applications
Client_112a
Client_112b
Client_112c
29. Exercises for Chapter 12
Exercise 12.1: JMS as a Resource
Start Up JBoss
Initialize the Database
Create a New JMS Topic
Adding a JMS Topic through a configuration file
jbossmq-titantopic-service.xml
Adding a JMS Topic through the JMX HTTP connector
Examine the EJB Standard Files
ejb-jar.xml
Examine the JBoss-Specific Files
jboss.xml
Build and Deploy the Example Programs
Examine the Client Applications
JmsClient_1.java
Run the Client Applications
Exercise 12.2: The Message-Driven Bean
Start Up JBoss
Initialize the Database
Create a New JMS Queue
Adding a JMS queue through a configuration file
jbossmq-titanqueues-service.xml
Adding a JMS queue through the JMX HTTP connector
Examine the EJB Standard Files
ejb-jar.xml
Examine the JBoss-Specific Files
jboss.xml
Build and Deploy the Example Programs
Examine the Client Applications
JmsClient_ReservationProducer.java
JmsClient_TicketConsumer.java
Run the Client Applications
30. Exercises for Chapter 13
Exercise 13.1: EJB Timer Service
Clean the Database
Build and Deploy Example Programs
Examine the Service Code
ShipBean.java
ShipMaintenanceBean.java
Examine the Client Code
Run the Example
31. Exercises for Chapter 15
Exercise 15.1: Web Services and EJB 2.1
Initialize Your Environment
Clean the Database
Build and Deploy Example Programs
build.xml
Examine the Server Model
TravelAgentEndpoint.java
ejb-jar.xml
travelagent_mapping.xml
webservices.xml
Examine the Client Model
TravelAgentClientBean.java
ejb-jar.xml
travelagent.wsdl
Run the Client Application
A. Database Configuration
Set Up the Database
Basic Setup
titandb-ds.xml
Examine the JBoss-Specific Files
jbosscmp-jdbc.xml
Start Up JBoss
Build and Deploy the Example Programs
Examine and Run the Client Applications
Index
Colophon
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Enterprise JavaBeans, 4th Edition
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset