Package examples.ejb20.relationships.bands

This example is a package that demonstrates the use of local interfaces; one-to-one, one-to-many, many-to-many relationships; client.jar; automatic primary key generation; and automatic table creation.

See:

 

Interface Summary

Artist  
ArtistHome  
Band  
BandHome  
FanClub  
FanClubHome  
MusicLibrary  
MusicLibraryHome  
Recording  
RecordingHome  
 

 

Class Summary

ArtistBean  
BandBean  
BandInfo  
BandPK  
Client This example demonstrates EJB relationships.
FanClubBean  
FanClubPK  
MusicLibraryBean  
RecordingBean  
RecordingInfo  
RecordingPK  
 

Package examples.ejb20.relationships.bands Description

This example is a package that demonstrates the use of local interfaces; one-to-one, one-to-many, many-to-many relationships; client.jar; automatic primary key generation; and automatic table creation. It uses EJBs written to the EJB 2.0 specification.

The example includes entity EJBeans called ArtistBean, BandBean, FanClubBean, and RecordingBean and a stateless session bean called MusicLibraryBean.

The example demonstrates:

  • Using an entity EJBean written to the EJB 2.0 specification
  • Using a stateless session EJBean written to the EJB 2.0 specification
  • Showing a one-to-one relationship between Fan Club and Band
  • Showing a one-to-many relationship between Band and Recording
  • Client application

Client application

The Client application performs these steps:
  1. Review the Music Library
  2. Provides a list of the bands in the Music Library
  3. Provides a list of recordings for each band in the Music Library
  4. Displays Fan Club information for each artist in the Music Library

To get the most out of this example, first read through the source code files.

Start with the XML deployment files ejb-jar.xml, weblogic-ejb-jar.xml and weblogic-cmp-rdbms-jar.xml to find the general structure of the EJBean, which classes are used for the different objects and interfaces, then look at Client code to see how the application works.

Pre-Built Examples

This EJB 2.0 example is not shipped pre-built. Before you can run this example, first create a table in Oracle, build the example following the instructions in Build the example, and then run the example using the instructions below.

The following four sections cover what to do:

  1. Set up the database
  2. Build the example
  3. Start the Examples server
  4. Run the example

Set up the database

This example is preconfigured to work with the PointBase database, included with the WebLogic Server distribution. As you'll use a database for the persistent storage of the entity EJBean, you'll need to set it up. The persistent storage is completely invisible to the client; the actual storage is handled by the EJBean directly and not the container.

With database persistence, each instance of an EJBean is written to a row in a table. If you want or need to run this example with Oracle, see Database SetUp for instructions.

The following tables, created using the table.ddl file supplied with this example's package must be created and exist in the database before you run example:

  1. fanclubs
  2. recordings
  3. artists
  4. bands
  5. band_artist
  6. artist_sequence

The persistent storage is completely invisible to the client; the actual storage is handled automatically by the container and not by the EJB.

Build the example

Set up your development shell as described in Setting up your environment.

We provide a build script for you to build the example:

The build script is build.xml.

Run the build script using the following Java ant command:

prompt> ant

The script builds the example and places the files in the correct locations in your WebLogic Server distribution:

  • Client.jar file: in SAMPLES_HOME\server\examples\build\clientclasses
  • EJB (in EAR file): in SAMPLES_HOME\domains\examples\applications\ejb20_relationship_bands.ear

Running the build script places the EJB in the %applications% directory, where it automatically deploys once the server is started. If you are already running the server and then build the EJB, it is automatically placed in this directory and instantly deployed.

Additional information on using the build scripts is found in More About Building Examples.

Start the Examples server

  1. Start the Examples server.

    If you need more information about how to use connection pools, read Using WebLogic JDBC: Using connection pools.

Run the example

  1. Run the client in a separate command line window. Set up your client as described in Setting up your environment, and then run the client by entering:
    prompt> ant run  

  2. You should receive output similar to this:
Welcome to the Hipster Music Library...

Added these bands...
Band Name: Genesis Band Founder: Peter Gabriel startDate: 1969-12-31
Band Name: Beastie Boys Band Founder: Mike Diamond startDate: 1981-12-31
Band Name: Britney Spears Band Founder: Britney Spears startDate: 1997-12-31
Band Name: Seth's Saxophone All-Stars Band Founder: Saxophone Seth startDate: 19
98-11-12


Added these Recordings...
Recording: Title: Duke Band: Genesis Recording Date: 1982-03-05
Recording: Title: Invisible Touch Band: Genesis Recording Date: 1985-03-05
Recording: Title: Sounds of Science Band: Beastie Boys Recording Date: 1997-03-0
5
Recording: Title: Licensed To Ill Band: Beastie Boys Recording Date: 1990-03-05
Recording: Title: Paul's Boutique Band: Beastie Boys Recording Date: 1989-03-05
Recording: Title: Britney's First Album Band: Britney Spears Recording Date: 19
99-03-05
Recording: Title: Saxophone Seth Plays the Blues Band: Seth's Saxophone All-Star
s Recording Date: 2001-03-23



Printing out Fan-Club Write-Up for each Band
Write-up for band: Genesis is: Genesis Fan Club
Write-up for band: Beastie Boys is: Beastie Boys Fan Club
Write-up for band: Britney Spears is: Britney Spears Fan Club
Write-up for band: Seth's Saxophone All-Stars is: Seth's Saxophone All-Stars Fan
 Club

Good bye...

There's more...

Read more about: