[ Pobierz całość w formacie PDF ]
.e., it has no foreign keys), a subject I will address in the nextchapter.Dependent objects introduce some additional considerations, but I will look at thosewhen we start to code beans for tables with foreign keys, like the USERS table.For the timebeing, it's enough to know that this office structure is as simple as it gets.You need to storethe ID (an int), the city (a String), and the state (another String).As this bean is simple in nature, it is a perfect candidate for container-managed persistence(CMP).There are no special JDBC calls that need to be made, no multiple-table queries, andno explicit data caching that needs to be performed.In the absence of these special cases,CMP is almost always a better choice than bean-managed persistence (BMP).While CMPbeans are not truly portable yet, as each container generates specific implementation classesfor that product, the basic classes I'll look at in a CMP bean are portable.In other words, youwon't be able to take a complete JAR file (with implementation classes) from BEA Weblogicand deploy it on Lutris Enhydra, but you will be able to take the user-coded classes from thischapter and use them to generate classes for both BEA Weblogic and Lutris Enhydra.The57 Building Java"! Enterprise Applications Volume I: Architectureresultant JARs can then be deployed on the respective application servers.This adds a bit ofwork, but is as close to complete portability as is possible in today's EJB containers.It doesallow us to write vendor-neutral code and not have to focus on a specific application server inthis chapter.All these reasons add up to a good case for using CMP instead of BMP.Additionally, the EJB2.0 specification makes CMP an even more attractive solution, offering almost completeportability in all aspects of CMP entity beans.While the process of creating the "skeleton" classes for a CMP entitybean (the home and remote interfaces, the primary key, and theimplementation class) is vendor-neutral, the means of generatingcontainer classes and deploying into a specific application server varieswidely from product to product.In this book, I focus on BEA Weblogic,the most prevalent application server in use today, as it would beimpossible to cover the ever-growing number of application servers.However, it should be fairly trivial to take the instructions for theWeblogic server and relate them to your own application server.I've moved any steps specific to Weblogic to the appendixes, leavingonly vendor-neutral code in the chapters' content.This should make iteasier to see what is general code, and what is platform-specific.Appendix D, then, covers installation and setup of the Weblogicapplication server for this book.4.2.1 Adapters and Entity BeansIn preparing to code CMP entity beans, it turns out that most of the EJB callbacks that mustbe implemented are empty in almost all cases; the container will generate the code for thesecallbacks at deployment time.Instead of coding these methods into each entity beanimplementation, wasting time and space in these beans and generally adding a lot of clutter,you can create an adapter class to handle this task for you.This concept, initially presented inRichard Monson-Haefel's book, is used here for the clarity it provides in later code.Example 4-1 is a slightly modified version of Richard's EntityAdapter class, which providesdefault, empty implementations of the required entity bean callbacks.The entity beanimplementation classes in this chapter will extend this class, rather than implementing thejavax.ejb.EntityBean interface directly.58 Building Java"! Enterprise Applications Volume I: ArchitectureExample 4-1.The EntityAdapter Helper Classpackage com.forethought.ejb.util;import javax.ejb.EntityBean;import javax.ejb.EntityContext;public class EntityAdapter implements EntityBean {protected EntityContext entityContext;public void ejbActivate( ) {}public void ejbPassivate( ) {}public void ejbLoad( ) {}public void ejbStore( ) {}public void ejbRemove( ) {}public void setEntityContext(EntityContext entityContext) {this.entityContext = entityContext;}public void unsetEntityContext( ) {entityContext = null;}public EntityContext getEntityContext( ) {return entityContext;}}If you have any implementation classes that need to provide special behavior for a callback,you can override the adapter class; overriding still allows you to leave out any callbacks thatare not implemented, keeping code clean [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • personata.xlx.pl