Using JDO with Other Types of EJBs


The application developer can use JDO when building session beans, some types of entity beans, and message-driven beans. The JDO Learning Tools have several examples of session beans and one example of an entity bean. The examples all implement the QuoteServer interface defined in the com/ysoft/jdo/book/sayings/ service directory under the bookcode-home directory. The quote service harkens back to an earlier day—well before online stock quotes—when it was nifty to have a facility somewhere on the network to issue famous (and sometimes not so famous) quotations on demand.

Chapter 6 describes in detail the important points about the design of the quote server examples. The complete set of examples provides a template for building any EJB that uses JDO.

Building the Quote Server EJBs

There are five build targets for the quote server EJBs.

  • sayings-stateless-cmt

  • sayings-stateless-bmt

  • sayings-stateful-cmt

  • sayings-stateful-bmt

  • sayings-entity

Each of the quote server builds overwrites the EJB created by any of the other quote server builds. Consequently, if you want to test all of them, you must do so sequentially. Each of them uses the same data schema, and as a result, the famous quotations that you add with one will be visible to the others.

To build the first target, execute the following command at the command line in the bookants directory under the bookcode-home directory:

 ant -Dschema=generate sayings-stateless-cmt 

You should see more than a hundred lines of output that ends with something like the output shown in Listing 11-2.

Listing 11-2: Expected End of Output from Building the sayings-stateless-cmt Target

start example
 sayings-ejb:      [copy] Copying 1 file to E:\Bookcode\build\com\ysoft\jdo\book\sayings\service       [jar] Building jar: E:\Bookcode\serverjars\quoteserver.jar       [jar] Building jar: E:\Bookcode\clientjars\quoteserverclient.jar      [echo] returned from com/ysoft/jdo/book/sayings/build.xml      [copy] Copying 1 file to E:\jboss304\server\default\deploy      [echo] creating runQuoteServer.bat      [echo] returned from ants/jboss.xml BUILD SUCCESSFUL Total time: 41 seconds 
end example

The -Dschema=generate option forces the build to generate the SQL schema for the quote server application. You need to create the schema only once, unless, of course, you modify the persistent fields. For Kodo, the build scripts will alter the schema for you. For the other implementations, SQL scripts are created in files that you can use to create the schema by hand.

Each of the builds creates a runQuoteServer.bat file in the bookcode-home directory that invokes the QuoteServerClient found in the com.ysoft.jdo.book.sayings.client package. The client's only interface is the command line. It can retrieve a quote or store a quote. It can also loop getting quotes every so often. After building one of the targets, go to the bookcode-home directory and type the following command for more information:

 runQuoteServer -help 

Using the Quote Server

After building any of the quote server targets, you may need to bounce JBoss for the reason described earlier in this chapter. Executing the command file runQuoteServer.bat will cause the QuoteServerClient to display one quote from the quote server EJB before terminating. For testing, it is better to cause the client to hit the bean at least three times. For this reason, use the following command:

 runQuoteServer -loop 3 

This will cause the client to display three quotes from the quote server before terminating.

To start, there are no quotes in the datastore, so you will need to add several quotes. For example, execute the following command to add the first quote:

 runQuoteServer -quote "A stitch in time saves nine" -source "Poor Richard's Almanac" 




Using and Understanding Java Data Objects
Using and Understanding Java Data Objects
ISBN: 1590590430
EAN: 2147483647
Year: 2005
Pages: 156
Authors: David Ezzio

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net