EJB Cookbook
Benjamin G. Sullins and Mark B. Whipple
  • May 2003
  • ISBN 9781930110946
  • 352 pages

A good buy for the more experienced J2EE-programmer.

C Vu magazine, June 2004

The EJB Cookbook is a resource for the practicing EJB developer. It is a systematic collection of EJB 'recipes'. Each recipe describes a practical problem and its background; it then shows the code that solves it, and ends with a detailed discussion.

Table of Contents detailed table of contents

preface

acknowledgments

about this book

author online

about the cover illustration

Part I Appetizers

1. Client code

1.1. Invoking a local EJB from another EJB

1.2. Invoking a remote EJB from another EJB

1.3. Accessing EJBs from a servlet

1.4. Invoking an EJB from a JavaServer Page

1.5. Invoking EJB business logic from a JMS system

1.6. Persisting a reference to an EJB instance

1.7. Retrieving and using a persisted EJB reference

1.8. Persisting a home object reference

1.9. Comparing two EJB references for equality

1.10. Using reflection with an EJB

1.11. Invoking an EJB from an applet

1.12. Improving your client-side EJB lookup code

2. Code generation with XDoclet

An XDoclet appetizer

2.1. Generating home, remote, local, and local home interfaces

2.2. Adding and customizing the JNDI name for the home interface

2.3. Keeping your EJB deployment descriptor current

2.4. Creating value objects for your entity beans

2.5. Generating a primary key class

2.6. Avoiding hardcoded XDoclet tag values

2.7. Facilitating bean lookup with a utility object

2.8. Generating vendor-specific deployment descriptors

2.9. Specifying security roles in the bean source

2.10. Generating and maintaining method permissions

2.11. Generating finder methods for entity home interfaces

2.12. Generating the ejbSelect method XML

2.13. Adding a home method to generated home interfaces

2.14. Adding entity relation XML to the deployment descriptor

2.15. Adding the destination type to a message-driven bean deployment descriptor

2.16. Adding message selectors to a message-driven bean deployment descriptor

Part II Main courses

3. Working with data

3.1. Using a data source

3.2. Creating EJB 2.0 container-managed persistence

3.3. Using different data sources for different users

3.4. Using a database sequence to generate primary key values for entity beans

3.5. Using a compound primary key for your entity beans

3.6. Retrieving multiple entity beans in a single step

3.7. Modeling one-to-one entity data relationships

3.8. Creating a one-to-many relationship for entity beans

3.9. Using entity relationships to create a cascading delete

3.10. Developing noncreatable, read-only entity beans

3.11. Invoking a stored procedure from an EJB

3.12. Using EJB-QL to create custom finder methods

3.13. Persisting entity data into a database view

3.14. Sending notifications upon entity data changes

3.15. Creating an interface to your entity data

3.16. Retrieving information about entity data sets

3.17. Decreasing the number of calls to an entity bean

3.18. Paging through large result sets

4. EJB activities

4.1. Retrieving an environment variable

4.2. Implementing toString() functionality for an EJB

4.3. Providing common methods for all your EJBs

4.4. Reducing the clutter of unimplemented bean methods

4.5. Sending an email from an EJB

4.6. Using the EJB 2.1 timer service

4.7. Sending a JMS message from an EJB

4.8. Using an EJB as a web service

4.9. Creating asynchronous behavior for an EJB client

4.10. Creating asynchronous behavior without message-driven beans

4.11. Insulating an EJB from service class implementations

4.12. Creating a batch process mechanism

5. Transactions

A transaction appetizer

5.1. Tuning the container transaction control for your EJB

5.2. Handling transaction management without the container

5.3. Rolling back the current transaction

5.4. Attempting error recovery to avoid a rollback

5.5. Forcing rollbacks before method completion

5.6. Imposing time limits on transactions

5.7. Combining entity updates into a single transaction

5.8. Managing EJB state at transaction boundaries

5.9. Using more than one transaction in a method

5.10. Managing EJB state after a rollback

5.11. Throwing exceptions without causing a rollback

5.12. Propagating a transaction to another EJB business method

5.13. Propagating a transaction to a nonEJB class

5.14. Starting a transaction in the client layer

5.15. Holding a transaction across multiple JavaServer Pages

5.16. Updating multiple databases in one transaction

6. Messaging

6.1. Sending a publish/subscribe JMS message

6.2. Sending a point-to-point JMS message

6.3. Creating a message-driven Enterprise JavaBean

6.4. Processing messages in a FIFO manner from a message queue

6.5. Insulating message-driven beans from business logic changes

6.6. Streaming data to a message-driven EJB

6.7. Triggering two or more message-driven beans with a single JMS message

6.8. Speeding up message delivery to a message-driven bean

6.9. Filtering messages for a message-driven EJB

6.10. Encapsulating error-handling code in a message-driven EJB

6.11. Sending an email message asynchronously

6.12. Handling rollbacks in a message-driven bean

7. Security

7.1. Finding the identity and role of the caller inside an EJB method

7.2. Assigning and determining EJB client security roles

7.3. Passing client credentials to the EJB container

7.4. Disabling methods for certain users

7.5. Assigning a role to an EJB

7.6. Preventing access to entity data

7.7. Using EJBs to handle simple authentication with an LDAP source

7.8. Securing a message-driven bean

Part III Desserts

8. Logging

A log4j appetizer

8.1. Formatting log messages

8.2. Improving logging performance

8.3. Using logging to generate reports

8.4. Sending log messages to a JMS topic

8.5. Logging to an XML file

8.6. Creating log file views for the web browser

8.7. Creating a centralized log file in a clustered environment

8.8. Tracking the lifecycle of an EJB

8.9. Using a different configuration at runtime

8.10. Sorting log messages by client

9. Deploying and unit testing

A deployment and testing appetizer

9.1. Compiling Enterprise JavaBeans

9.2. Building the ejb.jar file

9.3. Building Enterprise JavaBean stub classes

9.4. Creating a stateless session bean unit test

9.5. Creating a stateful session bean unit test

9.6. Creating an entity bean unit test

9.7. Automating test case execution

9.8. Executing test cases using a UI

Appendix A: Mixing it up: related recipes

Appendix B: Second helpings: additional resources

index

What's inside

  • EJB 2.1 features
  • CMP and BMP bean problems
  • EJB web service endpoints
  • Transactions and security
  • Solving EJB client problems
  • Testing EJB applications
  • Exception handling best practices
  • Messaging solutions
  • EJB code generation and logging

About the reader

This unique book is written for developers who want quick, clean, solutions to frequent problems—or simply EJB development ideas. Easy to find recipes range from the common to the advanced. How do you secure a message-driven bean? How do you generate EJB code? How can you improve your entity bean persistence layer?

About the author

Ben Sullins is a senior Java developer with extensive experience working with EJB. Mark Whipple has fifteen years' experience and a strong background in networked applications. He has been a member of several standards bodies, including the IETF. Ben and Mark are coauthors of Manning's JMX in Action. They both live in Dallas, Texas.


Buy
eBook $26.50 PDF only

FREE domestic shipping on three or more pBooks

This book provides a great reference for the average EJB developer. It provides recipes for most common tasks that an EJB developer would need.

Computing Reviews, November 2003

...Sullins and Whipple have written an amazingly pleasing book. I enjoyed both their writing style and the simplicity and clarity of the presentation. If you are managing servers, you will need to look at this exciting technology, and this book offers a great way to get into it. I am looking forward to using JMX for my next server project.

Computing Reviews, March 2003

...I am happy with the fact that the authors have included chapters on using XDoclet for EJB development and on unit testing EJBs with Cactus. The body of the book is, simply put, a compact reference for accomplishing recurring development tasks.

Lasse Koskela, JavaRanch.com