This exercise implements two standalone client applications to use the MusicCD entity bean and Inventory session bean which you developed and deployed in the previous exercises. Note: Due to a bug in the 1.0 release of the J2EE RI, these client programs will not run properly. The J2EE RI does not conform to the J2EE specification regarding the use of compound primary keys. The J2EE RI 1.0 only works properly with single-valued primary keys. In order to make this exercise work with the J2EE RI, you will have to use the upc field of the MusicCDBean class as the primary key and remove all mention of MusicCDPK in the MusicCD entity bean, the Inventory session bean, and the clients in this exercise. This bug will be fixed in the next J2EE RI release. Prerequisites
Skeleton Code
Tasks
Start the Cloudscape database server with the command-line command cloudscape -start.
Start the J2EE RI via the command-line command j2ee -verbose. Pay attention to the output to make sure that J2EE loads the MusicStoreDB datasource which you set up in the previous exercise, Setting up the Database.
Edit the MusicClient.java skeleton to obtain the JNDI context, and use this context to get a reference to the MusicCDHome.
Create a new MusicCD bean with the UPC code given in the skeleton, and set its fields to the values shown in the skeleton. Or if you have a favorite CD of your own, you can use that data.
Add code to find the MusicCD bean you just created in the database then print out the database values of the fields you set in the previous step.
Compile and run your client application.
Edit the MusicInventoryClient.java skeleton to obtain the JNDI context, and use this context to get a reference to the InventoryHome.
Create a new Inventory bean.
Create an instance of MusicData and fill it with information about CD's you want to insert into the database, then use the Inventory bean's business method to perform this task.
Compile and run your client application. Where help exists, the task numbers above are linked to the step-by-step help page. Solution Source
As a solution, provided are both the source code for the client applications, and the MusicStoreClient.jar file, which holds the container-generated stubs and skeletons and other things needed for a standalone-client to communicate with the J2EE server. Demonstration
MusicClient produces standard output similar to the following, depending on your choice of data: myhost> java -classpath %CLASSPATH%;MusicStoreClient.jar; \ %J2EE_HOME%\lib\j2ee.jar musicstore.MusicClient Title: Luna Nueva Artist: Diego Torres Type: Latin Price: 12.58 myhost> MusicInventoryClient should produce standard output similar to the following: myhost> java -classpath %CLASSPATH%;MusicStoreClient.jar; \ %J2EE_HOME%\lib\j2ee.jar musicstore.MusicInventoryClient Building new inventory... Submitting new inventory... New inventory added to database. myhost> Upon examination, the database should then reflect the added inventory. The exact contents of the database will of course depend on what CD information you inserted: ExercisesShort CourseCopyright 1996-2000 jGuru.com. All Rights Reserved. |