The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

Resource Adapter Tutorial

This tutorial shows you how to deploy the black box resource adapter stored in the blackbox-tx.rar file. To test the resource adapter, you will modify the examples/src/ejb/account/AccountEJB.java file so that it accesses the Cloudscape database through the resource adapter. The AccountEJB.java file is also used in another example. For more information, see Tips for Running the AccountEJB Example

Setting Up

  1. Start the J2EE server.
    j2ee -verbose 
    
  2. In another terminal window, set the J2EE_HOME environment variable to the directory in which you've installed this release.
  3. Follow the instructions in the section, Setting Up the Database.

Deploying the Resource Adapter

  1. Deploy a black box resource adapter that is packaged in the blackbox-tx.rar file.

UNIX:

deploytool -deployConnector \
$J2EE_HOME/lib/connector/blackbox-tx.rar localhost 

Windows:

(Enter the following command on a single line.)

deploytool -deployConnector 
%J2EE_HOME%\lib\connector\blackbox-tx.rar localhost 
  1. Add a connection factory for the resource adapter. The JNDI name for the connection factory is eis/MyBlackBoxTx.

UNIX:

j2eeadmin -addConnectorFactory \
eis/MyBlackBoxTx blackbox-tx.rar 

Windows:

(Enter the following command on a single line.)

j2eeadmin -addConnectorFactory 
eis/MyBlackBoxTx blackbox-tx.rar 
  1. Verify that the resource adapter has been deployed.
    deploytool -listConnectors localhost 
    

The deploytool displays these lines:

Installed connector(s):
Connector Name: blackbox-tx.rar

Installed connection factories:
Connection Factory JNDI Name: eis/MyBlackBoxTx 

Testing the Resource Adapter

  1. If you are new to the J2EE SDK, you may want to review the instructions in Getting Started.
  2. Locate the AccountEJB.java source code, which resides in the examples/src/ejb/account directory.
  3. Edit the AccountEJB.java source code, changing the value assigned to the dbName variable as follows:
    private String dbName = "java:comp/env/MyEIS"; 
    
  4. Compile the source code in the account directory:
    1. Go to examples/src.
    2. Type ant account.
  5. Run the New Enterprise Bean Wizard of the deploytool by selecting File-> New Enterprise Bean. Although the wizard displays many dialog boxes, for this example only the following dialog boxes require input.
  6. General Dialog Box
    1. Select the Entity radio button.
    2. In the Enterprise Bean Name field, enter AccountBean.
  7. Entity Settings Dialog Box
    1. Select the radio button for bean-managed persistence.
  8. Resource References Dialog Box:
    1. Click Add.
    2. Enter the values specified in the following table.

      Table 36 Resource References Values
      Field
      Value
      Coded Name
      MyEIS
      Type
      javax.sql.DataSource
      Authentication
      Container
      JNDI Name
      eis/MyBlackBoxTx
    The eis/MyBlackBoxTx JNDI name matches the name of the connection factory that you added in step 2 of Deploying the Resource Adapter. The MyEIS value of the Coded Name field corresponds to this line in the AccountEJB.java source code:
    private String dbName = "java:comp/env/MyEIS"; 
    
    Although it is included in the source code, the java:comp/env/ subcontext is implicit in the Coded Name field of the Resource References dialog box.
  9. Transaction Management Dialog Box:
    1. For the business methods, in the Transaction Type column select Required. The business methods are debit, credit, getFirstName, getLastName, and getBalance.
  10. Exit the wizard by clicking Finish.
  11. Create a J2EE application client.
    1. Select New->Application Client
    2. Name the client AccountClient.
    3. Add the ejb/SimpleAccount enterprise bean reference.
  12. Select Tools->Deploy Application.
    1. In the Introduction dialog box, select Return Client Jar.
    2. In the JNDI Names dialog box, verify that the JNDI names in the following table have been specified.

      Table 37 JNDI Names
      Comp. Name or
      Ref. Type
      JNDI Name
      AccountBean
      MyAccount
      MyEIS
      eis/MyBlackBoxTx
      ejb/SimpleAccount
      MyAccount
  13. To run the application, follow the directions in Running the J2EE Application.
Home
TOC
PREV TOC NEXT Search
Feedback