Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF EJB - Coverage of non exam topics

 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathy & Bert,
I know you have said that your book is just about in the "heavy object which could be used as a lethal weapon" category, so therefore you had to limit the scope of your book, but I was wondering ....
What coverage do you give to the sections of the EJB specification that are not on the exam? Do you ignore them, just mention them in passing, give quick and dirty explanations, or ???
For example, Bean Managed Persistance (there are times in real life where it might be necessary to use BMP) - is there any coverage of this?
Regards, Andrew
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Andrew,
The exam objectives overlap *almost* 100% with the spec, with the big exception being BMP. We left it out of the book (although we talk in the book about the main differences, and why the almost complete switch to CMP happened with the CMP changes in 2.0). At this point, the *official* position is that virtually nobody is creating EJB 2.0 BMP components, although there may be a LOT of "legacy" BMP beans from pre-2.0 days. But since we're assuming that our readers are *starting* from EJB 2.0, and that the only reason to learn BMP is for older apps and/or older containers, we just didn't cover it. We originally considered having an appendix on it, but just couldn't get up enough enthusiasum
Virtually all benchmarks have found CMP to outperform BMP, and in fact that was true even in 1.1, but there were other reasons not to use CMP until 2.0 -- mainly the lack of support for container-managed relationships.
But that's about the only area that's in the spec that's not in our book, and it's in the spec largely to support folks who already have older EJB applications using BMP.
We don't mean to say that there is NEVER a reason to use BMP with 2.0, but these would be very special cases, and not worth taking up the space it would take to do it correctly. But since you mentioned it, Andrew, now it makes me want to put the BMP stuff on the web site.
So here's my BMP in a really short short version:
BMP means that YOU and not the Container are doing the actual database access -- in other words, YOU do the INSERT, YOU do the DELETE, YOU do the UPDATE, and YOU do the SELECTS. Plus, you have to lookup the resource manager (your DataSource) and get the connection yourself.
The cool thing about entity beans, though, is that even if you DO use BMP, it is still the Container that tells you WHEN to do each of those things. And figuring out WHEN the bean needs to synchronize with the database, and vice-versa is the tricky part, so you are still way ahead of the game when you use entity beans, even with BMP. The lifecycle callbacks are pretty simple:
1) ejbCreate() -- here you must do the INSERT, and the difference between CMP and BMP is that with BMP you MUST return the primary key, rather than null. This is the Container's ONLY way to know what the primary key is!!
2) ejbLoad() -- this is the Container kicking you and telling you to do a SELECT on the database, and refresh/populate the bean's instance variables with the underlying data from the database.
3) ejbStore() -- this is the Container kicking you and telling you to do an UPDATE on the database, because the transaction may be ending and the database needs to be told about changes to the bean's state. If the bean is supposed to be representing an underlying entity, and someone called a business method that changed the bean's state (like, setAddress(...)), the database needs to have the new address!
4) ejbRemove() -- you have to do the actual DELETE of this entity, and any entities that you've decided (to keep referential integrity with the database) you must also delete. For example, if someone is removing an Order bean, it will be your responsibility to also go in and call remove() on all the LineItem beans. This is one of the best parts of CMP 2.0 -- the ability to have automatic relationship maintenance, including cascading deletes.
So those are the key things. The only other thing I'd mention is that the *best* place to do the JNDI lookup on the DataSource is setEntityContext(), since you do it only once, and that lookup is expensive to perform (but not to keep a reference). Usually, the *best* place to get and release the database connection is in each and every business method (including the callbacks) that USE the connection. Because getting and releasing the connection is *not* very expensive (remember, you're most likely just getting it from a pool and releasing it back to the pool), while KEEPING the connection for any longer than you need to can hurt scalability.
OK, that's it for BMP. Which, of course, is not on the exam
cheers,
Kathy
 
Amer Khan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wonderful explanation!
Nice & sweet!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathy & Bert,
(Wow - missed the response to my own thread :roll: - must learn to use the notification options)
Thanks for that Kathy. Very clear now.
Regards, Andrew
 
qadir sabri
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy
Very Clear!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic