Creating tables and data sources automatically to test CMP beans for WebSphere Application Server v6.0

The table and data source creator provides an automated way to test CMP enterprise beans without needing to worry about the persistence mechanism or how to configure a data source. You can test CMP beans as easily as session beans without having to create a data source or database tables. The table and data source creator automatically captures the following: userid, password, alias, host name, port, path to the JDBC drivers, whether to drop tables first or not, and whether to create data sources only and not tables.

The following database systems are supported, with restrictions as stated: Prerequisite tasks:
  1. Create an enterprise application project.
  2. Create a Version 2.x EJB project in the enterprise application project you just created.
    Restriction: Do not set a default server for this project. There is a known problem where this task may not run properly if a default server is set on the project. For further details, refer to the release notes on the topic "Problems using the Run on Server task when a project defines a default server".
  3. Create 2.x CMP beans in the EJB projects that correspond to the enterprise application project you just created.
  4. Generate top-down mappings, selecting one of the following as the target database:
    • Cloudscape v5.1
    • Cloudscape v5.0
    • DB2 v8.2
    • DB2 v8.1
    • Oracle v10g
    • Oracle v9i
    • Microsoft SQL Server 2000
  5. Open the EJB Deployment Descriptor editor by completing the following steps:
    1. In the Project Explorer view, expand EJB Projects folder.
    2. Expand your EJB project folder.
    3. Right-click the deployment descriptor folder and select Open.
  6. Verify a backend ID is specified for your EJB project by completing the following steps:
    1. In the Overview page, scroll down to the WebSphere Bindings section.
    2. Click the Refresh button beside the Current field.
    3. Ensure a backend ID is specified in the Current field. For example, DB2UDBNT_V8_1.
    4. Save your changes and close the deployment descriptor editor.
Note: Close the server editor before you create the tables and data sources, or the data sources will not automatically be created.

To test your CMP beans with the table and data source creator:

  1. In the Project Explorer view, right-click the bean and select Run > Run on Server. The Server Selection wizard opens.
  2. In the Define a New Server page, choose an existing or create a WebSphere Application Server v6.0 and then click Next.
  3. In the Add and Remove projects, add the EAR project to the server and then click Next.
  4. In the Select Tasks page, enable the Create tables and data sources check box and then click Finish. After clicking the Finish button, you need to wait a few moments as the workbench runs the following events:
    • generates deployment code for the EJB module
    • starts the server
    • adds projects to the server
    • opens the Universal Test Client
  5. For DB2, Oracle and Microsoft SQL Server 2000: A Connection Settings dialog box appears. A database connection is required for creating data source and table creation. Specify the following database connection parameters:
    1. In the User field, type your userid to access the database.
    2. In the Password field, type your password to access the database.
    3. In the Confirm password field, type your password again.
    4. In the Alias field, type your database alias.
    5. In the Host name field, type the host name of the database server.
    6. In the Port field, type the port number that will be used to connect to the database.
    7. In the Jar Files Path field, specify the path to the database JDBC drivers.
    Note: If your project has DB2, Oracle, and Microsoft SQL Server 2000 as current backends, the connection settings dialog box will have fields for all of these backends.
  6. For DB2, Oracle and Microsoft SQL Server 2000: If you have done a top-down mapping when creating your EJBs, the Create database_vendor tables and Drop database_vendor tables first check boxes are pre-selected. If the tables already exist or if you do not want to create tables, clear the Create database_vendor tables check box.

    If you have done a bottom-up mapping, the Create database_vendor tables check box is by default cleared, so you can automatically create a data source if you do not want to create tables.

  7. If you are performing this task again:
    • For Cloudscape, the tables are recreated but the data source remains the same.
    • For DB2, Oracle and Microsoft SQL Server 2000, the table recreation depends on your selection for Create database_vendor tables and Drop database_vendor tables first check boxes. If you want to keep the original tables created when you first ran this task ensure both check boxes are clear. If you want to drop and recreate the tables and delete your original tables, enable both check boxes.
  8. After filling-out the Connection Settings dialog box, click Create to start the table and data source creation.
  9. For each backend defined in the EJB project, the Table and Data Source Creator dialog box reports the following details:
    • The project name of the EJB project
    • The database vendor
    • The backend ID used
    • The data source creation status: Indicates whether a data source is added to the EJB project.
    • The table creation status: If the status of the table creation is not successful, refer to the list of operations performed for table creation to identify the problem.
    • The list of operations performed for table creation: Contains a list of the SQL operations and any exceptions thrown when performing the table creation.
  10. (Optional) If you want to verify the creation of the data source, complete the following:
    • For WebSphere Application server v5.x, you can open the server editor and see that the data source and resource properties were created.
    • For WebSphere Application Server v6.x, you can open the application deployment descriptor or the WebSphere administrative console to see that the data source and resource properties were created.
  11. (Optional) Use the Universal test client to test the CMP bean.
Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.