The J2EETM Tutorial
Home
TOC
Index
PREV TOP NEXT Search
Feedback

Resource Adapter Tutorial

This tutorial shows 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/savingsaccount/SavingsAccountBean.java file so that it accesses the Cloudscape database through the resource adapter. The SavingsAccountBean.java file is also used in another example; see Running the SavingsAccountEJB Example

Setting Up

  1. Start the J2EE server.
       j2ee -verbose
     
    
  2. 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 and all subsequent Windows commands on a single line.)
       deploytool -deployConnector 	
       %J2EE_HOME%\lib\connector\blackbox-tx.rar localhost
     
    
  2. 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
       j2eeadmin -addConnectorFactory 	
       eis/MyBlackBoxTx blackbox-tx.rar
     
    
  3. Verify that the resource adapter has been deployed.
       deploytool -listConnectors localhost
     
    
    The deploytool utility 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 should first read the instructions in Chapter 2.
  2. Locate the SavingsAccountBean.java source code, which resides in the j2eetutorial/examples/src/ejb/savingsaccount directory.
  3. Edit the SavingsAccountBean.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 savingsaccount directory.
    1. Go to j2eetutorial/examples.
    2. Type ant savingsaccount.
  5. Replace the new SavingsAccountBean.class file in the existing SavingsAccountApp.ear file.
    1. In the GUI deploytool, open the j2eetutorial/examples/ears/SavingsAccountApp.ear file.
    2. On the General tab of the SavingsAccountJAR, click Edit.
    3. In the Available Files field, locate the j2eetutorial/examples/build/ejb/SavingsAccountBean.class file.
    4. Drag and drop the SavingsAccountBean.class file from the Available Files field to the Contents field.
    5. Click OK.
  6. Change the resource factory reference.
    1. Select the Resource Refs tab of SavingsAccountEJB.
    2. Select the item whose Coded Name entry is jdbc/SavingsAccountDB.
    3. Click Delete.
    4. Click Add.
    5. Enter the values specified in Table 17-4.

      Table 17-4 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 SavingsAccountBean.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 Refs tab.
  7. Save the SavingsAccountApp application (FileSave).
  8. Deploy the SavingsAccountApp application.
    1. Select ToolsDeploy.
    2. In the Introduction dialog box, select Return Client Jar.
    3. In the JNDI Names dialog box, verify that the JNDI names in Table 17-5 have been specified.

      Table 17-5 JNDI Names
      Component or Reference Name
      JNDI Name
      SavingsAccountEJB
      MySavingsAccount
      MyEIS
      eis/MyBlackBoxTx
      ejb/SimpleSavingsAccount
      MySavingsAccount
  9. To run the application, follow the directions in the section Running the Client.
Home
TOC
Index
PREV TOP NEXT Search
Feedback