Mastering Enterprise JavaBeans™ and the Java 2 Platform, Enterprise Edition - Roman E
..pdfContents |
|
xi |
|
CORBA’s Many Services |
315 |
|
The Naming Service |
315 |
|
The Event Service |
315 |
|
The Object Transaction Service |
316 |
|
The Concurrency Control Service |
316 |
|
The Security Service |
316 |
|
CORBA Components |
316 |
|
RMI over IIOP |
317 |
|
The Need for RMI-CORBA Interoperability |
317 |
|
Combining RMI with CORBA |
319 |
|
Benefits of RMI over IIOP |
321 |
|
Problems That Arise When Combining RMI with IIOP |
323 |
|
Steps to Take for RMI and CORBA to Work Together: |
|
|
An Overview |
326 |
|
RMI-IIOP Client with a CORBA Object Implementation |
326 |
|
CORBA Client with an RMI-IIOP Object Implementation |
328 |
|
The RMI-IIOP API |
329 |
|
javax.rmi |
330 |
|
Bootstrapping with RMI over IIOP |
331 |
|
The Big Picture: CORBA and EJB Together |
332 |
|
Benefits of CORBA/EJB Interoperability |
333 |
|
CORBA/EJB Interoperability Scenarios |
334 |
|
Example Code |
335 |
|
CORBA EJB Client Example |
336 |
|
Summary |
341 |
Part IV: |
J2EE in the Real World: A Sophisticated |
|
|
E-Commerce Deployment |
343 |
|
|
|
Chapter 12 J2EE in the Real World: Designing an E-Commerce |
|
|
|
Object Model |
345 |
|
A Preview of the Final Product |
346 |
|
Scoping the Technical Requirements |
348 |
|
Object Model for the Business Logic Tier |
350 |
|
Object Model for the Presentation Tier |
355 |
|
Summary |
360 |
Chapter 13 J2EE in the Real World: Implementing Our E-Commerce |
|
|
|
Entity Beans |
361 |
|
The Customer Entity Bean |
362 |
|
Customer.java |
362 |
|
CustomerBean.java |
362 |
|
CustomerHome.java |
368 |
Go back to the first page for a quick link to buy this book online!
xii |
|
M A S T E R I N G E N T E R P R I S E J A V A B E A N S |
|
|
|
CustomerPK.java |
369 |
|
|
The Deployment Descriptor |
370 |
|
|
The Order Line Item Entity Bean |
373 |
|
|
OrderLineItem.java |
374 |
|
|
OrderLineItemBean.java |
375 |
|
|
OrderLineItemHome.java |
383 |
|
|
OrderLineItemPK.java |
385 |
|
|
The Deployment Descriptor |
386 |
|
|
The Order Entity Bean |
387 |
|
|
Order.java |
387 |
|
|
OrderBean.java |
389 |
|
|
OrderHome.java |
396 |
|
|
OrderPK.java |
397 |
|
|
OrderException.java |
398 |
|
|
The Deployment Descriptor |
398 |
|
|
Summary |
400 |
|
|
Chapter 14 J2EE in the Real World: Implementing Our E-Commerce |
|
|
|
Session Beans |
401 |
|
|
The Quote Line Item Stateful Session Bean |
403 |
|
|
QuoteLineItem.java |
403 |
|
|
QuoteLineItemBean.java |
404 |
|
|
QuoteLineItemHome.java |
408 |
|
|
The Deployment Descriptor |
408 |
|
|
The Quote Stateful Session Bean |
410 |
|
|
Quote.java |
411 |
|
|
QuoteBean.java |
413 |
|
|
QuoteHome.java |
425 |
|
|
QuoteException.java |
426 |
|
|
The Deployment Descriptor |
427 |
|
|
The Pricer Stateless Session Bean |
427 |
|
|
Pricer.java |
428 |
|
|
PricerBean.java |
429 |
|
|
PricerHome.java |
434 |
|
|
PricerException.java |
434 |
|
|
The Deployment Descriptor |
436 |
|
|
The Bank Teller Stateless Session Bean |
437 |
|
|
Teller.java |
438 |
|
|
TellerHome.java |
440 |
|
|
TellerBean.java |
440 |
|
|
TellerException.java |
448 |
|
|
The Deployment Descriptor |
448 |
|
|
Summary |
450 |
Go back to the first page for a quick link to buy this book online!
|
Contents |
|
xiii |
|
Chapter 15 J2EE in the Real World: Combining Servlets with |
|
|
|
Enterprise JavaBeans |
451 |
|
|
The Role of Servlets in an EJB Deployment |
451 |
|
|
Alternatives to Servlets |
452 |
|
|
Implementing Our Servlets |
453 |
|
|
The Login Servlet |
454 |
|
|
The Web Storefront Servlet |
461 |
|
|
The Online Catalog Servlet |
464 |
|
|
The Product Base Servlet |
470 |
|
|
The Product Detail Servlet |
473 |
|
|
The Quote Viewing Servlet |
476 |
|
|
The Purchasing Servlet |
486 |
|
|
The Servlet Properties |
492 |
|
|
Running the Complete E-Commerce System |
495 |
|
|
Starting the Business Logic Tier |
495 |
|
|
Starting the Presentation Tier |
495 |
|
|
Starting the Thin Client |
495 |
|
|
Optimizations and Design Strategies |
496 |
|
|
Unique Primary Key Generation |
496 |
|
|
Reducing Network Round Trips: Lazy-Loading Beans |
498 |
|
|
Identifying Entity Bean Synchronization Needs |
498 |
|
|
Entity Bean versus Session Bean Design |
499 |
|
|
Fine-Grained versus Coarse-Grained Entity Beans |
500 |
|
|
Finding a Large Number of Entity Beans |
500 |
|
|
Summary |
501 |
|
|
Introduction to Appendices |
503 |
|
|
|
|
|
|
Appendix A Understanding Java Remote Method Invocation (RMI) |
505 |
|
|
Remote Method Invocations |
506 |
|
|
RMI Architecture |
509 |
|
|
RMI and Interface versus Implementation |
509 |
|
|
Stubs and Skeletons |
510 |
|
|
Bootstrapping and the RMI Registry |
512 |
|
|
RMI URLs |
512 |
|
|
Looking Up a Remote Object |
513 |
|
|
RMIC—The RMI Compiler |
514 |
|
|
Object Serialization and Parameter Passing |
515 |
|
|
Passing by Value |
515 |
|
|
Object Serialization |
516 |
|
|
How Objects Are Serialized |
516 |
|
|
What Should You Make Transient? |
518 |
|
|
Uses of Object Serialization |
519 |
Go back to the first page for a quick link to buy this book online!
xiv |
|
M A S T E R I N G E N T E R P R I S E J A V A B E A N S |
|
|
|
How RMI Simulates Pass by Reference |
519 |
|
|
Exporting Your Remote Objects |
522 |
|
|
A Simple Example |
523 |
|
|
The IFlip Interface |
523 |
|
|
The Flip Class |
524 |
|
|
The Client |
526 |
|
|
Compiling the Program |
528 |
|
|
Running the Program |
528 |
|
|
Dealing with Remote Exceptions |
528 |
|
|
RMI’s Remote Exception limitations |
529 |
|
|
RMI Tips |
531 |
|
|
Advanced RMI |
531 |
|
|
RMI Example: A Message Queue for Distributed Logging |
533 |
|
|
RMI Example: Exploiting Distributed Garbage Collection |
553 |
|
|
RMI, CORBA, and EJB |
556 |
|
|
RMI or CORBA? |
556 |
|
|
RMI and EJB |
557 |
|
|
EJB Objects |
557 |
|
|
Home Objects |
558 |
|
|
Summary |
559 |
|
|
Appendix B Understanding the Java Naming and Directory |
|
|
|
Interface (JNDI) |
561 |
|
|
Naming and Directory Services |
562 |
|
|
Problems with Naming and Directories |
563 |
|
|
Enter JNDI |
565 |
|
|
Benefits of JNDI |
565 |
|
|
JNDI Overview |
566 |
|
|
JNDI Architecture |
566 |
|
|
Available Service Providers |
567 |
|
|
Understanding the Concepts behind JNDI Programming |
570 |
|
|
Naming Concepts |
571 |
|
|
Directory Concepts |
577 |
|
|
Programming with JNDI |
577 |
|
|
Setting Up the Required Software |
577 |
|
|
The JNDI Packages |
578 |
|
|
Basic JNDI Steps |
578 |
|
|
Exploring the javax.naming Package |
580 |
|
|
Example: An Interactive Browser |
582 |
|
|
Advanced JNDI: Combining JNDI with JDBC |
593 |
|
|
What Is a JDBC DataSource? |
594 |
|
|
Storing Java Objects in Directories |
595 |
Go back to the first page for a quick link to buy this book online!
Contents |
|
xv |
Implementing Our JNDI-JDBC Code |
596 |
|
Advanced JNDI: Combining JNDI with EJB |
601 |
|
JNDI and EJB Home Objects |
601 |
|
Other Uses of JNDI |
602 |
|
Advanced JNDI: Combining JNDI with Java RMI |
602 |
|
IFlip.java |
605 |
|
Flip.java |
605 |
|
Summary |
611 |
|
Appendix C Understanding the Extensible Markup Language (XML) |
613 |
|
Business Needs for XML |
614 |
|
Electronic Commerce |
614 |
|
Inadequacies with Existing Technology |
614 |
|
XML |
617 |
|
Benefits of XML |
617 |
|
XML Compared to EDI |
618 |
|
XML Compared to SGML |
619 |
|
XML Compared to HTML |
619 |
|
XML Concepts |
619 |
|
Prolog |
620 |
|
XML Elements |
621 |
|
XML Entities |
623 |
|
CDATA Sections |
623 |
|
Well-Formed Documents |
623 |
|
XML DTDs |
624 |
|
XML Summary |
629 |
|
XML and EJB |
629 |
|
XML Deployment Descriptors |
629 |
|
XML as an On-The-Wire Data Format |
630 |
|
Summary |
632 |
|
Appendix D Understanding EJB 1.1 |
635 |
|
Portable Deployment Descriptors |
635 |
|
One Deployment Descriptor Per Ejb-Jar File |
636 |
|
EJB 1.1 XML Deployment Descriptor Example |
636 |
|
Entity Bean Support Mandated |
639 |
|
RMI-IIOP API Standardized |
639 |
|
Everything JNDI |
640 |
|
How to Look Up Home Objects from Client Code |
641 |
|
How to Look Up Home Objects from within a Bean |
642 |
|
How to Look Up Resource Factories |
645 |
|
How to Look Up Environment Properties |
648 |
|
How to Look Up the JTA UserTransaction Interface |
650 |
Go back to the first page for a quick link to buy this book online!
xvi M A S T E R I N G E N T E R P R I S E J A V A B E A N S
Bean References Done Right |
651 |
Passivation and Activation Improvements |
651 |
Persistence Improvements |
652 |
Transactions Clarified and Enhanced |
653 |
Entity Beans Must Use Container-Managed Transactions |
653 |
Changes in Declarative Transactions |
653 |
Security Updates |
655 |
Security Context Propagation Changes |
655 |
Java 2 Security Model Updates |
657 |
Step by Step: Adding Programmatic Security to an EJB 1.1 |
|
System |
657 |
Step by Step: Adding Declarative Security to an EJB 1.1 System |
661 |
New Home Handles |
664 |
Other Important Changes in EJB 1.1 |
664 |
For More Information |
666 |
Beyond EJB 1.1 |
666 |
Summary |
667 |
Appendix E Making a Purchase Decision |
669 |
EJB Specification Compliance |
669 |
Entity Bean Support |
670 |
Persistence |
671 |
Bean-Managed Persistence |
671 |
Container-Managed Persistence |
671 |
Choosing a CORBA-based versus an RMI-based |
|
EJB Product |
672 |
Usage of RMI-IIOP API |
672 |
Accessibility of JTA via JNDI |
673 |
Protocol Issues |
673 |
Integrated Tier Support |
673 |
In-Memory Data Cache |
674 |
Scalability |
674 |
High Availability |
675 |
Security |
675 |
IDE Integration |
675 |
Intelligent Load Balancing |
676 |
Stateless Transparent Fail-over |
676 |
Clustering |
676 |
Clean Shutdown |
677 |
Go back to the first page for a quick link to buy this book online!
Contents |
|
xvii |
Real-time Deployment |
677 |
|
Distributed Transactions |
677 |
|
Existing Enterprise System Integration |
678 |
|
Asynchronous Messaging Support |
678 |
|
Integration with Bean Providers |
678 |
|
Specialized Services |
678 |
|
Non-Technical Criteria |
679 |
|
Summary |
680 |
|
Appendix F EJB Quick Reference Guide |
681 |
|
Session Bean Diagrams |
682 |
|
Stateless Session Bean Diagrams |
683 |
|
Stateful Session Bean Diagrams |
685 |
|
Entity Bean Diagrams |
688 |
|
EJB API Reference |
692 |
|
CreateException |
692 |
|
DuplicateKeyException |
692 |
|
EJBContext |
692 |
|
EJBException |
694 |
|
EJBHome |
694 |
|
EJBMetaData |
695 |
|
EJBObject |
696 |
|
EnterpriseBean |
697 |
|
EntityBean |
697 |
|
EntityContext |
701 |
|
FinderException |
701 |
|
Handle |
701 |
|
HomeHandle |
702 |
|
NoSuchEntityException |
702 |
|
ObjectNotFoundException |
702 |
|
RemoveException |
703 |
|
SessionBean |
703 |
|
SessionContext |
704 |
|
SessionSynchronization |
705 |
|
Transaction Reference |
706 |
|
Index |
709 |
Go back to the first page for a quick link to buy this book online!
P R E FA C E
s I write these words, I can’t help but think back to an inflection point that oc- Acurred in my life almost a year and half ago. I remember sitting in my cubicle at Trilogy Software Inc., an e-commerce company down in Austin, TX, lost in deep middleware thoughts. My challenge was to devise an interesting load-balancing
strategy for our in-house application server, which we called the backbone.
The backbone was a superb software system. It was cleanly written, easy to use, and boasted some very high-end features. Features such as distributed object support, object-relational mapping, and extensible domain object modeling. It had almost anything you needed for Internet development. It was a worthy investment for Trilogy to have.
I was part of a task force to add enterprise features to this backbone. Features such as transaction control, security, and load-balancing. Our goal was to improve the backbone into a product worthy of large-scale deployments.
So that day, after hours of racking my brain, I finally finished crafting what I believed to be a highly creative and optimal load-balancing strategy. Looking for feedback, I decided to walk down to my friend Court Demas’ office. Court is one of those developers that can really pick apart almost any design and expose its flaws. He has a unique quality that only a few developers I know have.
Walking into Court’s office, I was expecting a typical developer-level conversation, and that’s what I received. We turned the design inside and out, marking up my freshly printed hard-copy with scribbles and other unintelligible comments that only we could understand. Finally, satisfied that we had reached a conclusion, I thanked Court and walked toward the door, prepared to implement the changes we had agreed upon.
But I didn’t make it that far. Court said something to me that would change my way of thinking. He said something that baffled and confused me at first, but would eventually result in a complete paradigm shift and career move for me. What did Court say? Nothing profound. But simply, “You know Ed, this stuff is really what Enterprise JavaBeans is for.”
At first, I had no idea what he was talking about. Enterprise JavaBeans? What’s that? Something like regular JavaBeans? I had no idea. Eventually, Court managed
xix
Go back to the first page for a quick link to buy this book online!
xx |
|
M A S T E R I N G E N T E R P R I S E J A V A B E A N S |
to explain to me what EJB was. And once he explained it, I knew that Trilogy had to do a 180-degree turn, or Trilogy would lose their competitive advantage.
You see, EJB is a specification for a server-side component marketplace. EJB enables you to purchase off-the-shelf components from one vendor, combine them with components from another vendor, and run those components in an application server written by yet a third vendor. This means companies could collaborate on the server-side. EJB enables you to buy, rather than build, elements of server-side applications.
The EJB value proposition had strong ramifications for Trilogy. EJB represented a way for Trilogy to get out of this middleware business, and concentrate on their e-commerce strategic efforts. This would mean discarding the backbone completely in favor of a third party vendor’s architecture. Not only would this reduce Trilogy’s maintenance costs, but it would solidify their software suite, since their middleware would now be written by professionals who had been in the business for twenty years. This proposition would eventually lead to an entirely new business unit forming at Trilogy.
So I decided to start researching EJB and pushing for Trilogy to adopt it. I went to the Sun Microsystems Web page and downloaded the EJB 1.0 specification in PDF form and printed it out. Back then, the specification was about a third of the size it’s grown to today.
Understanding the specification turned out to be much more challenging than downloading it. The specification was written for system-level vendors, and was not meant to be a tutorial for end developers. The section on entity beans, for example, took me a good two months to really grasp, as the notion of persistent components was new to me.
This arduous struggle with understanding the EJB specification is what eventually lead me to write this book for you. This book represents everything I wish I had when I first started a year and a half ago. So what is this book about? This is not a book on EJB propaganda. Well, it may be more accurate to tell you what this book is not about. This is not a book on how to write EJB code on any single application server. This is not a nice book that paints a perfect picture of the EJB world. This is not an advertisement for any particular EJB product, nor a campaign to rid the world of Microsoft.
The goal of this book is to help you. I want you to be able to craft solid, secure, and scalable server-side deployments. As you read this book, you’ll learn how to design, implement, and deploy EJB solutions. This book covers both the vision and the reality of EJB, and is written from an independent developer’s perspective. I hope it will prepare you for the challenges you will face.
I wish the grass was greener and I could write a book on how clean and portable EJB is, but the truth is that this technology is not perfect, and you should
Go back to the first page for a quick link to buy this book online!
Preface xxi
know exactly what the imperfections are. I will expose you to the gruesome and incompatible parts of EJB, and also explain how the industry is solving these problems.
Indeed, the newer specifications (especially EJB 1.1) improve portability and incompatibilities tremendously. I hope that by the time you’re done reading this book, you are convinced that the vision of EJB is solid, and the future is very bright.
To give you as much exposure to EJB as possible, almost every new concept in this book is complemented by a brand-new enterprise bean. This is not a book with a single code example that flows for the entire text, because that would give you a very narrow view of the kinds of domain models you can build with EJB. So prepare yourself, because together we will develop thirteen enterprise beans over the course of this book. We’ll also write other small modules, such as servlet code, JNDI code, RMI code, XML code, and more, to give you a taste for the Java 2 Platform, Enterprise Edition (J2EE) suite.
My hope is that I can save you time and energy, and aid you in designing wellcrafted server-side deployments. But this is merely the beginning. The EJB marketplace is just getting started, and there’s a whole lot more work ahead to do. I encourage you to take an active role in the middleware industry, and to work with me taking EJB to the next level. Feel free to e-mail me your experiences, tips, and design strategies, and I’ll post them on the book’s accompanying Web site to share with others. Our goal is to increase our knowledge of EJB as a community, and together we can do it.
Sincerely,
Ed Roman
On an airplane home from the PLoP (Pattern Languages of Programming) conference, 1999
Go back to the first page for a quick link to buy this book online!