Before you start
A while back, I wrote...
"A while back, I wrote a tutorial on EJB components in a previous version of WebSphere Studio. At the time I knew enough about EJB components to fully grasp what they were for, why they made J2EE development easier for Java™ developers (particularly servlet and bean developers) and, most importantly, why EJB developers were paid so well and why I didn't want any part of it... "
I rambled on a bit longer about how EJB development was historically tedious, complex, and a bit mystifying to those not skilled in the art and how the tooling included in the latest development tools made the whole process considerably more point-and-click-like.
That second tutorial, Easier, breezier EJB components: WebSphere Studio V5.1 simplifies EJB component development (the sequel to Easy Breezy EJB components), went rather well, I would say, based on the e-mails I received from people quickly becoming more fluent in the technology than I and describing how they wanted to expand on the exercise rather than asking for clarification.
Now, enter stage left, the latest IBM® integrated development environment (IDE), IBM Rational® Application Developer for WebSphere® Software and, with that, the long awaited (at least by me and those that hold the mortgage on my house) third tutorial in the series, Easiest, Breeziest EJB components.
For today's exercise, let me set the stage. For those of you who are familiar with the various IBM WebSphere Studio IDEs, our newly acquired friends at Rational have taken on the responsibility of improving on some of our development tools -- namely WebSphere Studio. If you are familiar with the Rational toolset, you are aware that their shtick is in model-driven development (among some other interesting things). As it happens, people tend to enjoy dragging and dropping elements to visually develop rather than type actual code. Thus, Rational's approach seems a great fit within Studio, and you will find in many areas within the new tools some swanky new ways to model your application components and then run wizards to automatically chunk out the code. EJB development is certainly included.
What you will find in this tutorial is how these latest tools make life so much easier than days of old.
I probably should point out one important aspect of enterprise development -- in case you are somewhat new to this -- the "model" layer.
By now you are likely familiar with the notion of the standard model-view-controller architecture promoted by an industry-wide J2EE practice. It is widely accepted that the front end of an application may change frequently. This might be as simple as tweaking the color scheme of the HTML pages your users see, to something a little more complex, as in adding new features. Parts that change less frequently are the parts that make up the actual data used by your system. In addition, the back-end data might be reused by many different areas of your application. Replication -- how the data is pulled from a data source -- or replicating any part of your application -- is considered bad form because in time you may need to change how that part works and, thus, necessarily need to change the same code in multiple areas.
None of this should be news to you. But this is at the heart of a model-view-controller architecture. By separating the view (HTML, JSPs, the parts the user sees) from the controlling business logic (servlets, JavaBeans, the stuff that does a great deal of the work) from the model or back-end data (user data, stuff pulled from a database perhaps), you can easily replace or reuse parts in very efficient and flexible ways. By separating, I mean do not include Java code in your JSPs that call a database directly. Some other JSP may need to call the same database for the same information, thus requiring you to replicate the call to the database. This will help you avoid the potential for hosing a key piece of business logic because it was embedded in a block of HTML code that was marked for removal.
EJB components are the model in an enterprise application. By packaging the way data is pulled from a data source, not only do you isolate it to components not touched by other areas of your development team as described above, but you also gain the benefit of being able to easily reuse those components by many areas of your application, as well as by other applications throughout (or beyond) your enterprise.
Quite frankly, in a simple case -- one that this tutorial illustrates -- the tools in WebSphere Studio make EJB development less coding and more administration. I don't mean to diminish the importance or even the potential complexity of EJB development -- far from it. Abstracting out the data connections from your application to a series of reusable objects is likely no lighthearted task. The power and flexibility of EJB components is ultimately balanced with potential performance and environment factors that need to be carefully weighed. This tutorial assumes that you have already decided to use them and does not really discuss these issues in depth.
You will simply look at the tools within Rational Application Developer that help you create your new EJB components. The beans you develop may likely be similar to some of what you will ultimately develop on your own, but as you can imagine, you may be working with a far more complicated architecture.
This tutorial is for lazy developers who want big bucks, as well as Java application developers with some basic knowledge of DB2® Universal Database.
To complete this tutorial, you need Rational Application Developer, IBM DB2 UDB V8.2, and a couple of scripts I wrote to get your database rolling.
- Rational Application Developer for WebSphere Software. This download is listed as Rational Web Developer Windows-Full (Rational Web Developer v6.0 for Windows FULL includes Agent Controller for remote deployment to Websphere application servers).
- DB2 Universal Database v8.1 or higher
- EBMusic.ddl
- EBMusicDataDump.ddl
Download and install the two applications as normal in the default directories. Save each of the ddl files to C:\temp.

