Auto World setup instructions

Before setting up the Auto World sample, you must first Import the sample. This opens a wizard that imports the projects in your workspace.

The following two sample projects are added to your workspace:

  • AutoWorld20ExampleEAR: an enterprise application
  • AutoWorld20Example: an EJB module

The AutoWorld20Example project includes a DB2 backend folder with EJB mappings to tables designed for IBM DB2 Universal Database. These setup instructions provide the basic steps for exporting the database tables onto IBM DB2 Universal Database, running the Auto World application on the WebSphere Application Server V6.0 test environment, and testing the enterprise beans using the Universal Test Client.

Prerequisite: This sample uses the DB2 UDB SAMPLE database. Have your database administrator install the SAMPLE database using the DB2 First Steps application.

Note: To run this sample against a different database backend other than DB2, you will need to create new mappings between the enterprise beans and database tables. To run the sample on a different application server than is described here, you need to modify these steps for your particular server. See the product Help for more information.

After importing the Auto World sample projects, complete the steps in each of the following sections:

Deploy the tables on DB2

  1. Using the DB2 Control Center, view the SAMPLE database. Make a note of the schema for the DEPARTMENT table.
  2. In the Project Explorer, expand Databases > SAMPLE.
  3. Right-click the NULLID entry and select Rename.
  4. Change the name to match the schema for the DEPARTMENT table, as noted above.
  5. Press Enter.
  6. Right-click the SAMPLE node and click Deploy. The Deploy wizard opens.
  7. Click Next and select the Generate fully qualified names check box.
  8. Click Next and define your connection to DB2.
  9. Click Finish. If a 'Confirm export results' dialog box opens, click Commit changes. A connection to the SAMPLE database in DB2 is created and the tables are created using the definition in the Tables.ddl file.

Enable JDBC 2.0 on DB2 Universal Database V7.2 or earlier:

If you are using DB2 Universal Database Version V7.2 or earlier, you need to enable JDBC 2.0 by running the usejdbc2.bat file. This step is not necessary for DB2 Universal Database V8.

  1. Stop all DB2 processes.
  2. From a command prompt run the usejdbc2.bat batch file in <DB2_INSTALL_PATH>\SQLLIB\java12 where <DB2_INSTALL_PATH> is the path where you installed DB2.
  3. Restart DB2.

Important: If you are denied access when running the usejdbc2.bat file, you have not stopped all of the DB2 processes.

Deploy the EJB project in preparation for running it on the server

  1. In the Project Explorer, expand the EJB projects category.
  2. Right-click the AutoWorld20Example project, and select Deploy. Deployment code is generated and added to your EJB project.

Specify deployment information for the AutoWorld20ExampleEAR enterprise application

  1. In the Project Explorer, expand the the AutoWorld20ExampleEAR project and double-click the deployment descriptor to open the Application Deployment Descriptor editor.
  2. Click the Deployment tab.
  3. In the Datasources section, define a new JDBC provider.
    1. Click the Add button next to the table of JDBC providers.
    2. The Create a JDBC Provider wizard opens.
    3. In the Database type list, select IBM DB2.
    4. In the JDBC provider type list, select DB2 Legacy CLI-based Type 2 JDBC Driver.
    5. Click Next.
    6. In the Name field, enter a name for your JDBC provider.
    7. In the Class path section, remove the existing entry.
    8. Click Add External JARs and add the path pointing to your db2java.zip file (for example, C:\Program Files\IBM\SQLLIB\java\db2java.zip).
    9. Click Finish.
  4. Define the data source for this new JDBC provider.
    1. With this new JDBC provider selected, click the Add button next to the data sources table. The Create a Data Source wizard opens.
    2. Select DB2 Legacy CLI-based Type 2 JDBC Driver, and click Next.
    3. In the JNDI name field, enter Sample.
    4. Click Finish.
    5. With this new data source selected in the data sources table, select the databaseName property in the resource properties table, and click Edit.
    6. In the Value field, enter SAMPLE, and click OK.
    7. Save your changes to the Application Deployment Descriptor.

Start the WebSphere v6.0 server

  1. In the Servers view, right-click the WebSphere v6.0 server where you want to run the application.
  2. Select Start. The Status section of the Servers view indicates when the server is started.

    Note: If there are no servers created, you can define a server by right-clicking in the Servers view and selecting New > Server.

Run the AutoWorld20Example EJB module on the server

  1. In the Project Explorer, right-click the AutoWorld20Example EJB project and click Run > Run on Server. The Server Selection dialog opens.
  2. Choose the existing WebSphere v6.0 server that you defined earlier, and click Next.
  3. Make sure your AutoWorld20ExampleEAR project is in the Configured projects list, then click Finish.

    The EAR file is published on the server and the Universal Test Client opens.

Test the enterprise beans using the Universal Test Client

If the Universal Test Client does not open when you run the project on the server, you can right-click the server in the Servers view and select Run universal test client. To reset the Universal Test Client, right-click the server and select Restart universal test client.

The following steps show how to perform a few quick tests of the beans:

  1. In the Universal Test Client, click JNDI Explorer.
  2. Expand the [Local EJB beans] > autoworld > ejbgroup folders to locate the Auto World beans.
  3. Test the vehicle bean by creating a new vehicle:
    • Click Vehicle (autoworld.ejbgroup.VehicleLocalHome). An entry for the VehicleLocalHome interface is added to the EJB beans section in the left navigation area.
    • Expand VehicleLocal > VehicleLocalHome and click the VehicleLocal create(int) method.
    • Enter 1 as the integer value for the new vehicle, and click Invoke. The method executes and creates a new vehicle object with a key value of 1.
    • Click Work with object to add the vehicle object to the list of beans that you are testing.
  4. Test the garage bean by adding a new garage:
    • Click JNDI Explorer.
    • Click Garage (autoworld.ejbgroup.GarageLocalHome). An entry for the GarageLocalHome interface is added to the EJB beans section in the left navigation area.
    • Expand GarageLocal > GarageLocalHome and click the GarageLocal create(int) method.
    • Enter 1 as the integer value for the new garage, and click Invoke. The method executes and creates a new garage object with a key value of 1.
    • Click Work with object to add the garage object to the list of beans that you are testing.
  5. Invoke the setGarage method on the vehicle 1 object to set the vehicle's garage to the new garage:
    • Under the EJB Beans list, expand the the VehicleLocal (autoworld.ejbgroup.VehicleKey@1) object.
    • Click void setGarage(GarageLocal).
    • In the drop-down menu, select GarageLocal (autoworld.ejbgroup.GarageKey@1).
    • Click Invoke. The method executes and sets the garage for vehicle 1 to be garage 1.
  6. Invoke the getGarage method on vehicle 1:
    • Under the EJB Beans list, expand the the VehicleLocal (autoworld.ejbgroup.VehicleKey@1) object.
    • Click GarageLocal getGarage().
    • Click Invoke. The results show that the garage for vehicle 1 is garage 1.