WebLogic Server 6.1 Code Examples, BEA Systems, Inc.

Package examples.ejb20.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:
          Description

Interface Summary
Artist  
ArtistHome  
Band  
BandHome  
FanClub  
FanClubHome  
MusicLibrary  
MusicLibraryHome  
Recording  
RecordingHome  
 

Class Summary
ArtistBean  
BandBean  
BandInfo  
BandPK  
Client  
FanClubBean  
FanClubPK  
MusicLibraryBean  
RecordingBean  
RecordingInfo  
RecordingPK  
 

Package examples.ejb20.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 Enterprise JavaBeans written to the EJB 2.0 specification.

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

The example demonstrates:

Pre-Built Examples

The EJB 2.0 examples included in the WebLogic Server 6.1 distribution are not shipped pre-built. To run these examples, you must build the example following the specific examples instructions.

Client application

TheClientapplication 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 sourcecode files.

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

The following four sections cover what to do:

  1. Build the example
  2. Set up the example
  3. Configure the server
  4. Run the example

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:
        $ant

The script will build the example and place the files in thecorrect locations in your WebLogic Server distribution:

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

Additional information on using the build scriptsis found in Building Enterprise JavaBean examples

Set up the example

You will need to set up the persistent storage of theEJBeans. You will use a database for the persistent storage of the entity EJBeans. Each instance of an EJBean is written to a row in a table. Although most of the EJB examples in this release use the evaluation copy of the Cloudscape database, included with WebLogic Server, however, you will NEED to use Oracle to create the tables for this example. You must create these tables using the oracle.ddl file supplied with this example's package. These tables must exist in the database and be accessible before you can successfully build the example. Use the following instructions to create your tables:

  1. Use the Java Schema utility and the Oracle ddl (oracle.sql) supplied with this example to create your tables. This utility is part of WebLogic Server. For more information, see Utility package.
  2. Use the following command to create your tables:

    java utils.Schema"jdbc:weblogic:oracle"weblogic.jdbc.oci.Driver-u rob-p young.\oracle.sql

    where "jdbc:weblogic:oracle" is the URL for your database; weblogic.jdbc.oci.Driver is the name of the driver; u is the user ID; p is the password; and oracle.sql is the ddl file supplied with this example.

The following tables 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

Note that the persistent storage is completely invisible to theclient; the actual storage is handled automatically by the containerand not by the EJBean. All database properties, such as the loginname and password, are defined in the connection pool. A preconfigured Oracle connection pool is included in the example server.

Configure the server

  1. Start the WebLogic Server.

  2. Start the Administration Console.

  3. Click to expand the Deployments node in the left pane and select EJB.

    A list of EJBs deployed on the server displays.

  4. Choose the appropriate deployment unit from the list.

  5. Select the Target tab in the right pane.

  6. Verify that the examplesServer is chosen as the target for the EJB.

  7. Setup a connection pool in the Administration Console .

    For your convenience, a sample connection pool, called oraclePool is included with this example. You can use this connection pool for this EJB example, however, you will need to make the following modifications:

    In this example, the fileRealm for the access control list (ACL) is preconfigured to allowaccess for everyone.

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

Run the example

  1. Set the classpath as follows to add the Client.jar in the build directory to the classpath:
     set CLASSPATH=%CLASSPATH%;.\BandEJBClient.jar

  2. 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:
    $ java examples.ejb20.bands.Client

    If you're not running the WebLogic Server with its default settings,you will have to run the client using:

    $ java examples.ejb20.bands.Client "t3://WebLogicURL:Port"

    where:

    WebLogicURL
    Domain address of the WebLogic Server
    Port
    Port that is listening for connections(weblogic.system.ListenPort)

  3. 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-31Band Name: Beastie Boys Band Founder: Mike Diamond startDate: 1981-12-31Band Name: Britney Spears Band Founder: Britney Spears startDate: 1997-12-31Band Name: Seth's Saxophone All-Stars Band Founder: Saxophone Seth startDate: 1998-11-12Added these Recordings...Recording: Title: Duke Band: Genesis Recording Date: 1982-03-05Recording: Title: Invisible Touch Band: Genesis Recording Date: 1985-03-05Recording: Title: Sounds of Science Band: Beastie Boys Recording Date: 1997-03-05Recording: Title: Licensed To Ill Band: Beastie Boys Recording Date: 1990-03-05Recording: Title: Paul's Boutique Band: Beastie Boys Recording Date: 1989-03-05Recording: Title: Britney's First Album Band: Britney Spears Recording Date: 1999-03-05Recording: Title: Saxophone Seth Plays the Blues Band: Seth's Saxophone All-Stars Recording Date: 2001-03-23Printing out Fan-Club Write-Up for each BandWrite-up for band: Genesis is: Genesis Fan ClubWrite-up for band: Beastie Boys is: Beastie Boys Fan ClubWrite-up for band: Britney Spears is: Britney Spears Fan ClubWrite-up for band: Seth's Saxophone All-Stars is: Seth's Saxophone All-Stars Fan ClubGood bye...

There's more...Read more about:


Documentation is available at
http://e-docs.bea.com/wls/docs61

Copyright © 2001 BEA Systems, Inc. All Rights Reserved.