xvi Introduction Forces:A set of paragraphs explaining the context and problem in greater detail,explaining many of the forces at work that requires a solution.Here the reader will fully understand the need for this pattern. Solution:One or two sentences that introduce the pattern as the solution to the problems described above. Solution Description:Paragraphs describing the solution,including pros,cons, high-level and low-level explanation of the pattern,and implementation issues in EJB. Related Patterns The related patterns may cross-reference other patterns in the book,or else point vou toward the same or similar patterns in other sources,which are detailed in the"References"section of this book. What sets Alexandrian form and the style used in this book apart from most other popular software patterns books is the structuring the pattem data.One of thegoo experienced architects and newcomers to read a pattern and understand it fully.The way that I tried to realize this is by writing a pattern in a fluid,pros format,in which the reader is led through the problem and the solution,with all the necessary points explained step by step,with language as simple as pos sible.The emphasis is on learning the pattern in a simple and pleasant fashion With non-Alexandrian styles,the patterns are broken up into separate sec- tions,using point form descriptions within each section.My own opinion of these styles is that they tend to focus on packing as much info into each point as possible,making it difficult to casually read and learn,as the information tends to be categorized in a manner more suitable for reference purposes than for end-to-end reading.Such patterns books are great for reference purposes but the goal of this book is to teach patterns to the experienced architect as well as inexperienced developer,and soa format that lends itself to learning was chosen,and Alexandrian form seemed best suited for that purpose. How This Book Is Organized This book is organized into twoparts.Part One,"EJB Pattern Language,"is the EJB patterns catalog,detailing 20 patterns.Part Two,"Best Practices for EJB Design and Implementation,"provides support chapters that teach best prac tices in other topics,such as applying the patterns and actually implementing EJB-based systems.The goal is to give the reader not just a catalog of patterns
Forces: A set of paragraphs explaining the context and problem in greater detail, explaining many of the forces at work that requires a solution. Here the reader will fully understand the need for this pattern. Solution: One or two sentences that introduce the pattern as the solution to the problems described above. Solution Description: Paragraphs describing the solution, including pros, cons, high-level and low-level explanation of the pattern, and implementation issues in EJB. Related Patterns The related patterns may cross-reference other patterns in the book, or else point you toward the same or similar patterns in other sources, which are detailed in the “References” section of this book. What sets Alexandrian form and the style used in this book apart from most other popular software patterns books is the use of prose over point form for structuring the pattern data. One of the goals of this book is to enable both experienced architects and newcomers to read a pattern and understand it fully. The way that I tried to realize this is by writing a pattern in a fluid, prose format, in which the reader is led through the problem and the solution, with all the necessary points explained step by step, with language as simple as possible. The emphasis is on learning the pattern in a simple and pleasant fashion. With non-Alexandrian styles, the patterns are broken up into separate sections, using point form descriptions within each section. My own opinion of these styles is that they tend to focus on packing as much info into each point as possible, making it difficult to casually read and learn, as the information tends to be categorized in a manner more suitable for reference purposes than for end-to-end reading. Such patterns books are great for reference purposes, but the goal of this book is to teach patterns to the experienced architect as well as inexperienced developer, and so a format that lends itself to learning was chosen, and Alexandrian form seemed best suited for that purpose. How This Book Is Organized This book is organized into two parts. Part One, “EJB Pattern Language,” is the EJB patterns catalog, detailing 20 patterns. Part Two, “Best Practices for EJB Design and Implementation,” provides support chapters that teach best practices in other topics, such as applying the patterns and actually implementing EJB-based systems. The goal is to give the reader not just a catalog of patterns, xvi Introduction
Introduction xvii but to give the reader the tools needed to take knowledge of these patterns and get work done.Also included in Part Two is a chapter on Alternatives to Entity Beans,which gives an EJB developer's perspective on using Java Data Objects (DO)to persist an object model,and a chapter on more fine-grained design tips and strategies that were too small to qualify as full patterns. I would recommend that you read through the patterns in Part One before proceeding to Part Two.If you are more of a hands-on type,you can start read- ing through the first few chapters of Part Two and refer to the patterns in Part One when they are mentioned. Who Should Read This Book? In order for this book to get into difficult and technically in-depth discussions on advanced EJB topics,it was assumed that the reader would have a good understanding of the fundamentals of EJB before reading this book.In partic ular,I recommend reading Ed Roman's Mastering Enterprise JavaBeans,Second Edition (Wiley 2001),which is a great book for learning both the fundamentals and advanced applications of EJB.EJB Design Patterns was originally meant to be a chapter in Ed Roman's book,but as the chapter kept growing in size,we decided to promote it into its own book.Another excellent way to gain the background for this book is to take the Mastering EJB class offered by The Middleware Company,or you can learn all the patterns in this book hands-on in The Middleware Company's EJB for Architects course. Although the book requires an understanding of EJB,it is not only for expe rienced architects.The tone of the book and the language used in the patterns is intended to be accessible to entry-level developers as well as architects.In particular,the following three mantras were used in this book's development: 1.Someone who has just read Ed Roman's Mastering EJB or another EJB book should be able to read through and grasp the concepts without too much difficulty. 2.The content is hardcore and technical enough to make the book a fascinating read even for experts. 3.Each part of the book should answer more questions than it raises. These three rules were taken to heart in writing this book.Rule 3 is designed to keep us providing the necessary background required to explain a difficult topic,but not so much that there would be duplication with an introductory text on EJB(Rule 1).Rule 2 kept our focus on discussing the most useful and important topics not usually covered in other books of this nature
but to give the reader the tools needed to take knowledge of these patterns and get work done. Also included in Part Two is a chapter on Alternatives to Entity Beans, which gives an EJB developer’s perspective on using Java Data Objects (JDO) to persist an object model, and a chapter on more fine-grained design tips and strategies that were too small to qualify as full patterns. I would recommend that you read through the patterns in Part One before proceeding to Part Two. If you are more of a hands-on type, you can start reading through the first few chapters of Part Two and refer to the patterns in Part One when they are mentioned. Who Should Read This Book? In order for this book to get into difficult and technically in-depth discussions on advanced EJB topics, it was assumed that the reader would have a good understanding of the fundamentals of EJB before reading this book. In particular, I recommend reading Ed Roman’s Mastering Enterprise JavaBeans, Second Edition (Wiley 2001), which is a great book for learning both the fundamentals and advanced applications of EJB. EJB Design Patterns was originally meant to be a chapter in Ed Roman’s book, but as the chapter kept growing in size, we decided to promote it into its own book. Another excellent way to gain the background for this book is to take the Mastering EJB class offered by The Middleware Company, or you can learn all the patterns in this book hands-on in The Middleware Company’s EJB for Architects course. Although the book requires an understanding of EJB, it is not only for experienced architects. The tone of the book and the language used in the patterns is intended to be accessible to entry-level developers as well as architects. In particular, the following three mantras were used in this book’s development: 1. Someone who has just read Ed Roman’s Mastering EJB or another EJB book should be able to read through and grasp the concepts without too much difficulty. 2. The content is hardcore and technical enough to make the book a fascinating read even for experts. 3. Each part of the book should answer more questions than it raises. These three rules were taken to heart in writing this book. Rule 3 is designed to keep us providing the necessary background required to explain a difficult topic, but not so much that there would be duplication with an introductory text on EJB (Rule 1). Rule 2 kept our focus on discussing the most useful and important topics not usually covered in other books of this nature. Introduction xvii
xviii Introduction What's on the Web Site? The book's companion Web site,www.theserverside.com/patterns/ejbpat terns,contains the book's running/compiling source code examples,as well as a readers'discussion forum.This Web site will also hopefully be continuously evolving,with more patterns added to it over time from the community. Summary This book is a a patterns book unlike any other patterns book.Not only will you learn valual and fundamental patterns that will help you improve the qual ity of the EJB-based applications you write,but you will also learn how to take the knowledge of these patterns and apply them in a use-case driven manner. You'll also learn many best practices for actually implementing an application once it's desig If this bo ontributes to your career and the quality of the projects yo work on,then I will feel happy that it helped.If the book benefits your overall quality of life by streamlining your projects,then its mission will have been accomplished tenfold!
What’s on the Web Site? The book’s companion Web site, www.theserverside.com/patterns/ejbpatterns, contains the book’s running/compiling source code examples, as well as a readers’ discussion forum. This Web site will also hopefully be continuously evolving, with more patterns added to it over time from the community. Summary This book is a patterns book unlike any other patterns book. Not only will you learn valuable and fundamental patterns that will help you improve the quality of the EJB-based applications you write, but you will also learn how to take the knowledge of these patterns and apply them in a use-case driven manner. You’ll also learn many best practices for actually implementing an application once it’s designed. If this book contributes to your career and the quality of the projects you work on, then I will feel happy that it helped. If the book benefits your overall quality of life by streamlining your projects, then its mission will have been accomplished tenfold! xviii Introduction
Acknowledgments I would like to thank Ed Roman and Agnieszka Zdaniuk,for without their confidence and belief in me,this book would not have been possible. I would like to thank Florin and Carmen Marinescu,for having taught me myand Mork bll or alling me to make more time for the book by helping me deal with some of my other responsibilities in life. Text Contributors I would like to thank Randy Stafford for his contribution of Chapter 7 on Code/Pattern Idea Contributors Richard Monson-Haefel for the notion of using Rowsets for Data Transfer. Jonathan Weedon of Borland,for his contribution of a source code example upon which the Sequence Blocks pattern is based. Doug Bateman for the initial suggestion of using Stored Procedures for Auto-Generated Keys. Steve Woodcock for the idea and code contribution of the UUID for EJB pattern. Stuart Charlton for the Generic Attribute Access idea. Patterns Guidance I would like to thank Markus Voelter,Ralph Johnson,and especially Bobby Woolf,without whose early suggestions on patterns style this book would have been pretty confusing. xix
Acknowledgments I would like to thank Ed Roman and Agnieszka Zdaniuk, for without their confidence and belief in me, this book would not have been possible. I would like to thank Florin and Carmen Marinescu, for having taught me what matters from an early age. Special thanks to Aravind Krishnaswamy and Mark Turnbull, for allowing me to make more time for the book by helping me deal with some of my other responsibilities in life. Text Contributors I would like to thank Randy Stafford for his contribution of Chapter 7 on development process, and Craig Russell for his contribution of material on JDO in the alternatives to entity beans chapter. Code/Pattern Idea Contributors Richard Monson-Haefel for the notion of using Rowsets for Data Transfer. Jonathan Weedon of Borland, for his contribution of a source code example upon which the Sequence Blocks pattern is based. Doug Bateman for the initial suggestion of using Stored Procedures for Auto-Generated Keys. Steve Woodcock for the idea and code contribution of the UUID for EJB pattern. Stuart Charlton for the Generic Attribute Access idea. Patterns Guidance I would like to thank Markus Voelter, Ralph Johnson, and especially Bobby Woolf, without whose early suggestions on patterns style this book would have been pretty confusing. xix
Acknowledgments Reviewers EJB Design Patterns could never have been completed without the reviews, suggestions,corrections,and even questions of all the members of TheServer- Side.com JEE Community who reviewed my work over a period of eight months: Alex Tyurin,Alex Wologodzew,Allan Schweitz,Alun R.Butler,Andre Cesta, Andre Winssen,Andreas Kruiger,Andy Stevens,Andy Turner,Ankur Kumar, Anthony Catalfano,Anuj Vohra,Anup Kumar Maliyackel,Aparna Walawalkar, Ashim Chakraborty,Babur Begg,Ben Beazley,Bill Ennis,Billy Newport Blasius Lofi Dewanto,Bob Lee,Boris Melamed,Botnen Trygve,Brian Benton, Brian Dobby,Brian Walsh,Brian Weith,Carmine Scotto d'Antuono,Cecile Saint-Martin,Chad Vawter,Chandra Mora,Charles N.May,Colin He Constantin Gonciulea,Cristina Belderrain,Curt Smith,Dan Bereczki,Dan Zainea,Daniel F.Burke,Daniel Massey,Darrow Kirkpatrick,Dave David Ziegler,Dimitri Rakitine Eduard Skhisov,Emmanuel Valentin,Engstrom Anders,Erez Nahir,Faisal aveed,Fernando Bellas Permuy,FM Spruzen Simon,Forslof Mats,Frank Robbins,Frank Sampson,Frank Stefan,Fried Hoeben,Gabriela Chiribau, Ganesh Ramani,Geert Mergan,Gene McKenna,Geoff Soutter,Gjino Bledar, Gunnar Eikman,Hai Hoang,Heng Ngee Mok,Hildebrando Arguello,Hossein S.Attar,Howard Katz,Huu-An Nguyen,Iain McCorquodale,J.D.Bertron, James Hicks,James Kelly,Janne Nykanen,Jean Safar,Jean-Pierre Belanger Jeff Anderson,Jerome Beau,Jesper Andersen,John Ipe,Jonathan Asbell,Jorg Winter,Joseph Sheinis,Juan-Francisco Borras-Correa,Julian Chee,Junaid Bhatra,Justin Leavesley,Justin Walsh,Ken Hoying,Ken Sizer,Krishnan Subramanian,Kristin Love,Kyle Brown,Lance Hankins,Larry Yang,Laura Fang,Laurent Rieu,Leo Shuster,MHeling,Madhu Gopinathan,Mark Buchner, Mark L.Stevens Martin cciarini,Matt Mikulic Mattias Fagerstrom Mohan Radhakrishnan,Mohit Sehgal,Muhammad Farhat Kaleem,Muller Laszlo,Murray Knox,Nakamura Tadashi,Nicholas Jackson,Nick Minutello, Nick Smith,Niklas Eriksson,Oliver Kamps,Olivier Brand,Partha Nages swaran Patrick Caulfield,Paul Wadmore,Paulo Ferreira de Moura Jr.,Paulo Merson, Peter Miller.Pontus Hellgren.Raffaele Spazzoli Rais Ahmed.Raiesh Jayaprakash,Reg Whitton,Richard Dedeyan,Rick Vogel,Robert Melntosh Robert Nicholson,Robert O'Leary,Roger Rhoades,Roman Stepanenko, Samuel Santiago,Sashi Guduri,Scot McPhee,Scott Chen,Scott Stirling,Scott W.Ambler,Sebastien Couturiaux,Sergey Oreshko,Shorn Tolley,Simon Brown,Simon Harris,Simone Milani,Stefan Piesche,Stefan Tilkov,Stephan J. Schmidt,Steve Divers,Steve Hill,Steven Sagaert,Sun-Lai Chang,Tarek Hammoud,Taylor Cowan,Terry Griffey,Thanh C.Bryan,Therese Hermansson, Thierry Janaudy,Thomas Bohn,Toby Reyelts,Tom Wood,Tracy Milburn
Reviewers EJB Design Patterns could never have been completed without the reviews, suggestions, corrections, and even questions of all the members of TheServerSide.com J2EE Community who reviewed my work over a period of eight months: Alex Tyurin, Alex Wologodzew, Allan Schweitz, Alun R. Butler, Andre Cesta, Andre Winssen, Andreas Krüger, Andy Stevens, Andy Turner, Ankur Kumar, Anthony Catalfano, Anuj Vohra, Anup Kumar Maliyackel, Aparna Walawalkar, Ashim Chakraborty, Babur Begg, Ben Beazley, Bill Ennis, Billy Newport, Blasius Lofi Dewanto, Bob Lee, Boris Melamed, Botnen Trygve, Brian Benton, Brian Dobby, Brian Walsh, Brian Weith, Carmine Scotto d’Antuono, Cecile Saint-Martin, Chad Vawter, Chandra Mora, Charles N. May, Colin He, Constantin Gonciulea, Cristina Belderrain, Curt Smith, Dan Bereczki, Dan Zainea, Daniel F. Burke, Daniel Massey, Darrow Kirkpatrick, Dave Churchville, David E. Jones, David Ezzio, David Ziegler, Dimitri Rakitine, Dimitrios Varsos, Dion Almaer, Doal Miller, Don Schaefer, Donnie Hale, Eduard Skhisov, Emmanuel Valentin, Engström Anders, Erez Nahir, Faisal , aveed, Fernando Bellas Permuy, FM Spruzen Simon, Forslöf Mats, Frank Robbins, Frank Sampson, Frank Stefan, Fried Hoeben, Gabriela Chiribau, Ganesh Ramani, Geert Mergan, Gene McKenna, Geoff Soutter, Gjino Bledar, Gunnar Eikman, Hai Hoang, Heng Ngee Mok, Hildebrando Arguello, Hossein S. Attar, Howard Katz, Huu-An Nguyen, Iain McCorquodale, J.D. Bertron, James Hicks, James Kelly, Janne Nykanen, Jean Safar, Jean-Pierre Belanger, Jeff Anderson, Jérôme Beau, Jesper Andersen, John Ipe, Jonathan Asbell, Jörg Winter, Joseph Sheinis, Juan-Francisco Borras-Correa, Julian Chee, Junaid Bhatra, Justin Leavesley, Justin Walsh, Ken Hoying, Ken Sizer, Krishnan Subramanian, Kristin Love, Kyle Brown, Lance Hankins, Larry Yang, Laura Fang, Laurent Rieu, Leo Shuster, M Heling, Madhu Gopinathan, Mark Buchner, Mark L. Stevens, Martin Squicciarini, Matt Mikulics, Mattias Fagerström, Mohan Radhakrishnan, Mohit Sehgal, Muhammad Farhat Kaleem, Muller Laszlo, Murray Knox, Nakamura Tadashi, Nicholas Jackson, Nick Minutello, Nick Smith, Niklas Eriksson, Oliver Kamps, Olivier Brand, Partha Nageswaran, Patrick Caulfield, Paul Wadmore, Paulo Ferreira de Moura Jr., Paulo Merson, Peter Miller, Pontus Hellgren, Raffaele Spazzoli, Rais Ahmed, Rajesh Jayaprakash, Reg Whitton, Richard Dedeyan, Rick Vogel, Robert McIntosh, Robert Nicholson, Robert O’Leary, Roger Rhoades, Roman Stepanenko, Samuel Santiago, Sashi Guduri, Scot McPhee, Scott Chen, Scott Stirling, Scott W. Ambler, Sébastien Couturiaux, Sergey Oreshko, Shorn Tolley, Simon Brown, Simon Harris, Simone Milani, Stefan Piesche, Stefan Tilkov, Stephan J. Schmidt, Steve Divers, Steve Hill, Steven Sagaert, Sun-Lai Chang, Tarek Hammoud, Taylor Cowan, Terry Griffey, Thanh C. Bryan, Therese Hermansson, Thierry Janaudy, Thomas Bohn, Toby Reyelts, Tom Wood, Tracy Milburn, xx Acknowledgments