agenda
play

Agenda Fuzzy Wuzzy Differences between regular client DB access - PowerPoint PPT Presentation

The Beginner s Guide To EJB s with JBoss: Quick and Free Cedrick W. Johnson Catylist, Inc. javadude@cedrick.net Agenda Fuzzy Wuzzy Differences between regular client DB access Introductions and Entity access EJB Lingo


  1. The Beginner ’ s Guide To EJB ’ s with JBoss: Quick and Free Cedrick W. Johnson Catylist, Inc. javadude@cedrick.net

  2. Agenda � Fuzzy Wuzzy � Differences between regular client DB access Introductions and Entity access � EJB Lingo � CMP & BMP Side by side � Entity Bean Defined � Entity Bean Intricacies � Types of Entity � Performance Increases Beans: � Review � Fine � Resources � Coarse � Demonstration � O/E, etc … .

  3. About The Presenter � Cedrick Johnson � Cavenger Systems CTO, co-founder (old co.) � Technology Evangelist and 100% Geek

  4. Some EJB “ Lingo ” � Session Beans � Entity Beans � A business process � A data object (noun) (verb) � CMP � Stateful and � BMP Stateless � Finder Methods � Value Objects � EJB-QL (NEW IN 2.0 � Local Interfaces TOO!!!!) (NEW IN 2.0!)

  5. Entity Bean Defined � A bean that is used to represent a ROW of data within a database � BMP and CMP Entity Beans � BMP = harder, but allows for more control over your SQL code � CMP = easier, but can sometimes be TOO easy � A REUSABLE “ component ” of your software application that allows for access to a data resource

  6. Types of Entity Beans: Fine- Grained � Usually a client accesses these beans via each of the bean ’ s accessor methods. � Client calls each of the get/set methods for reading/manipulating data � Fine for small applications or for beginners

  7. Types of Entity Beans: Coarse Grained � A client accesses these beans by using a Value Object, an object that contains the fields that represent the EJB ’ s accessor methods � Client makes ONE call, gets the VO, then makes changes to the VO and resubmits � More suitable for performance-critical applications (as we will see later)

  8. Comparison: Entity Beans vs. Traditional DB Access Methods Traditional Entity Connections to the DB are � Each client eats up a DB � handled by the container connection Business logic can now � � Business logic resides reside in an server-side EJB on either client or DB = reusability � Single point of failure, Clustering provides � redundancy little or no reusable Somewhat complicated to components � begin learning/implementing properly

  9. CMP and BMP Differences Container Bean � No client SQL Code � More control over (faster to develop) queries � Plug and play with � Semi-Plug and play database with DB � No DB access code � Less new learning to deal with (reuse and extend old JDBC code/components)

  10. How is a EB mapped to a row? � Container obtains all the rows in a database, then creates a Remote interface “ handle ” to that row in the database. � 100 Rows, 100 “ handles ” � 1000 Rows, 1000 “ handles ”

  11. How do you add new rows with Entity Beans? � Clients can call the create() method on the Entity Bean ’ s REMOTE interface … This tells the container to invoke ejbCreate() within your EJB to perform the operations needed. MyEntityRemote.create(new Integer(1), “Hello”); Container MyEntityEJBImpl.ejbCreate(new Integer(1), “Hello”);

  12. How do you modify existing rows with Entity Beans? � Usually you need to find the data, then set the attributes on the retrieved row. Container manages the update � For better performance, use a Value Object MyEJB ejb = home.findByPrimaryKey(1); ejb.setName(“Alfred”);

  13. Modifying Existing Rows with a Value Object public PersonVO getPerson() { PersonVO lPerson = null; MyEJBRemote ejb = null; try { ejb = ejbHome.findByPrimaryKey(1); lPerson = ejb.getPersonVO(); } catch ……. return lPerson; }

  14. Are We Awake????

  15. Modifying Existing Rows with a Value Object ID NAME Client Application ejb.findByPrimaryKey(1);

  16. Modifying Existing Rows with a Value Object PersonVO ID NAME New VO() ID = 1 NAME = Alfred Client Application ejb.findByPrimaryKey(1);

  17. Modifying Existing Rows with a Value Object PersonVO ID NAME ID = 1 NAME = Alfred set() get() Client Application

  18. Modifying Existing Rows with a Value Object PersonVO ID NAME ID = 1 NAME = Alfred set() get() Client Application ejb.updateUser(1);

  19. Modifying Existing Rows with a Value Object PersonVO ID NAME ID = 1 NAME = Alfred set() get() Client Application

  20. Modifying Existing Rows with a Value Object ID NAME Values are now persisted in the database Client Application

  21. Modifying Existing Rows with a Remote Interface ID NAME Client Application ejb.findByPrimaryKey(1);

  22. Modifying Existing Rows with a Remote Interface ID NAME MyEJB Remote Client Application ejb.findByPrimaryKey(1);

  23. Modifying Existing Rows with a Remote Interface MyEJB ID NAME MyEJB Remote ID = 1 NAME = Alfred Client Application ejb.findByPrimaryKey(1);

  24. Modifying Existing Rows with a Remote Interface MyEJB ID NAME MyEJB Remote ID = 1 NAME = Alfred Client Application

  25. Modifying Existing Rows with a Remote Interface MyEJB ID NAME MyEJB Remote ID = 1 NAME = Alfred Client Application ejb.create(1, “ CHANGEME ” )

  26. Modifying Existing Rows with a Remote Interface ID NAME Client Application ejb.create(1, “ CHANGEME ” )

  27. Modifying Existing Rows with a Remote Interface MyEJB ID NAME MyEJB Remote ID = 1 NAME = CHANGEME Client Application ejb.findByPrimaryKey(1);

  28. EJB Performance YES! EJB ’ s are slow compared � � Use Value Objects to other methods of access � Use Local Interfaces BUT: Optimization is key to � achieving maximum � Lazy Instantiation performance and scalability If you use EJB ’ s, you must � � Session or Message architect systems from the Driven Bean ground up with proper design decisions, else it WILL be slow. fa ç ades, etc.

  29. EJB Performance � Serialization � Use the transient keyword for fields not being serialized � Smaller transport (value) objects that transmit only data you need � “ Coarse Grained ” Network calls � Garbage Collection � Null out references to objects that are no longer needed � Cached Row Sets and a Updater EJB � Client gets a row set, disconnects (Disconnected DS) performs operations, then “ publishes ” that RS to a listener EJB which performs the necessary DB updates/checking

  30. CMP Optimized SE+VO (Local Interface) vs CMP FG Entity 50 45 40 35 30 Time (seconds) 25 FG CMP 20 SE+VO CMP (L) 15 10 5 0 1 2 3 4 5 6 7 2.1 1.7 3.7 6.6 12.3 24.5 48.9 FG CMP 0.25 0.66 1.5 3.8 6.7 14.2 24.4 SE+VO CMP (L) Iterations

  31. CMP Optimized Remote Interface SE+VO vs. FG Entity 50 45 40 35 30 Time (seconds) 25 FG CMP 20 SE+VO CMP (R) 15 10 5 0 1 2 3 4 5 6 7 2.1 1.7 3.7 6.6 12.3 24.5 48.9 FG CMP 0.39 1.05 2.27 4.6 9.9 19.2 36.6 SE+VO CMP (R) Iterations

  32. Review � Why do we use EJB? � EJB is NOT all there � What is an entity bean is to J2EE � Entity Bean Types � Evaluate project needs � Differences between DAO and EJB data � Not needed for small access applications, usually � CMP & BMP: Side by � Investigate and Side learn!! � Performance Issues

  33. Resources To Get You Started JBuilder 5/6 (NOW WITH UML!!!) � http://www.borland.com/jbuilder � Sybase EAServer 4.1 Developer Edition � http://www.sybase.com/products/easerver � JBoss Open Source App Server � http://www.jboss.org � Orion App Server � BEA Weblogic App Server � http://www.bea.com � Eclipse IDE � www.eclipse.org � Your local EJB nut � The presenter �

  34. Resources To Get You Started (Continued) The ServerSide � http://www.theserverside.com � The Middleware Company � http://www.middlewarecompany.com � JGuru Forums � http://www.jguru.com � AspectJ � http://www.aspectj.org � EJB Performance Measurements – November 2001 CJUG � Presenter- Maciej Zawadski http://www.urbancode.com �

  35. Demonstration JBoss 3.0 Application Server JBoss Druid - CMP Generator Eclipse IDE No cards up my sleeve

Recommend


More recommend