EJB CICS sample application task guide: Development

sga020


The EJB CICS sample application task guide

Develop an enterprise bean using VisualAge for Java

This section describes the task steps to create the enterprise bean which contains the business logic for EJB CICS sample application. We assume that you have completed all the tasks for setting up and configuring an enterprise bean environment in which to run the sample application. In addition we assume that you have:
  1. Installed the sample COBOL programs, DB2 components and CICS definitions that play the part of "existing" CICS COBOL applications in your system.
  2. Created the command beans which the enterprise bean will use to access data via the "existing" CICS COBOL applications.

The tasks involved in creating the enterprise bean are:

  1. Start up Visual Age for Java
  2. Add an EJB Group to contain the enterprise bean
  3. Add an enterprise bean to the EJB group
  4. Add business methods to the enterprise bean
  5. Add the business methods to the enterprise bean's remote interface
  6. Update the enterprise bean Deployment Descriptor

In the CICS EJB Sample application the enterprise bean is to be added to the project and package used to contain the command beans and data type classes.

Start up Visual Age for Java

  1. Click on Start Button->Programs->IBM VisualAge for Java for Windows V3.5->IBM VisualAge for Java.
  2. Select your project from the project list. Sample: CICSEJBSample.
  3. Expand the project to show its contents on the project tree.

Create an enterprise bean

EJBs are organized into EJB groups.

    Create an EJB Group

  1. Click on the EJB tab to add the EJB group for the sample enterprise bean.
  2. Select menu option EJB->Add->EJB Group...to start the Add EJB Group smartguide.
  3. Ensure that the correct Project is identified in the top field. If the project name is incorrect, click on the Browse button, then select your project. Sample: CICSEJBSample.
  4. Select the radio button labelled: Create a new EJB group named:.
  5. Enter a name for the new EJB group. Sample: CICSSample .

    Add EJB Group smartguide

  6. Click Finish.
    The EJB group is added to the project.

    Create an enterprise bean in the EJB Group

  7. Right click the CICSSample EJB group.
  8. From the menu for the group, select Add->Enterprise Bean... to start the Create Enterprise Bean smartguide.

    In the Create Enterprise Bean SmartGuide:

  9. Select the Create a new enterprise bean radio button.
  10. In the Bean name field, enter the name of the enterprise bean. Sample: CICSSample.
  11. Select Session bean from the Bean type drop down list.
  12. Ensure that the correct project and package names are specified.
    Sample project:CICSEJBSample
    Sample package: cics.sample
  13. The class field is completed automatically: CICSSampleBean.
  14. Leave Superclass blank.

    Create Enterprise Bean smartguide

  15. Click Finish.
    The new bean is added to the EJB group CICSSample in the cics.sample package.

    The Types pane shows the:

    VAJ Workbench EJB tab

    Add a business method to the enterprise bean

  16. Right click CICSSampleBean Types pane.
  17. From the menu select Add -> Method... to start the Create Method smartguide.

    In the Create Method window:

  18. Select the Create new method radio button.
  19. Enter the signature for the method in the text entry field. Sample: public int GetCustomerInfo.

    In the method signature:

    Add method smartguide panel: Specify method attributes

  20. Click Next.

    On the Attributes panel you can fine tune or change the method signature. No changes are required.

  21. Click Next.
    Use the Exceptions panel to add exceptions that the method should throw.
  22. Click on the Add button and add Exception.
  23. Click Finish. The method is added and shown in the Members pane of the EJB window.

  24. The code for the selected method is editable in the bottom pane. Copy the the following code and paste it into the getCustomerInfo method:

    
    /**
    	 * The (one and only) business method on this bean. Obtains customer data from
    	 * DB/2 via the COBOL programs.
    	 * @return cics.sample.CustomerData
    	 * @param custNo int
    	 */
    	public cics.sample.CustomerData getCustomerInfo(int custNo) throws Exception {
    
    		System.out.println("CICSSample: entered getCustomerInfo()");
    
    		System.out.println("CICSSample: creating connector command for COBOL program V2ACTDB");
    		cics.sample.V2ACTDBCommand accountConnect = new V2ACTDBCommand();
    		cics.sample.V2ACTDBCommarea accountInput = accountConnect.getCeInput();
    		accountInput.setCustno(custNo);
    
    		System.out.println("CICSSample: executing connector command");
    		try {
    			accountConnect.execute();
    		} catch (Throwable t) {
    			System.out.println("CICSSample: error returned from V2ACTDB command: " + t);
    			throw new Exception("Exception occurred invoking V2ACTDB program: " + t);
    		}
    
    		System.out.println("CICSSample: creating connector command for COBOL program V2CSTDB");
    		cics.sample.V2CSTDBCommand customerConnect = new V2CSTDBCommand();
    		cics.sample.V2CSTDBCommarea customerInput = customerConnect.getCeInput();
    		customerInput.setCustno(custNo);
    	  
    		System.out.println("CICSSample: executing connector command");
    		try {
    			customerConnect.execute();
    		} catch (Throwable t) {
    			System.out.println("CICSSample: error returned from V2CSTDB command: " + t);
    			throw new Exception("Exception occurred invoking V2CSTDB program: " + t);
    		}
    		
    		System.out.println("CICSSample: creating CustomerData class");
    		cics.sample.CustomerData cData = new cics.sample.CustomerData();
    		cics.sample.V2ACTDBCommarea accountOutput = accountConnect.getCeOutput0();
    		cics.sample.V2CSTDBCommarea customerOutput = customerConnect.getCeOutput0();
    		
    		System.out.println("CICSSample: moving values from V2ACTDB commarea into CustomerData");
    		cData.setBalance(accountOutput.getBalance());
    		cData.setAcctNo(accountOutput.getAcctno());
    		cData.setCustNo(accountOutput.getCustno());
    
    		System.out.println("CICSSample: moving values from V2CSTDB commarea into CustomerData");
    		cData.setLastName(customerOutput.getLastname());
    		cData.setFirstName(customerOutput.getFirstname());
    		cData.setAddress(customerOutput.getAddress1());
    		cData.setCity(customerOutput.getCity());
    		cData.setState(customerOutput.getState());
    		cData.setCountry(customerOutput.getCountry());
    
    		System.out.println("CICSSample: returning CustomerData");
    		return cData;
    	}
    
    

  25. Press Ctrl-S to save the code.

    Add the Business Method to the Remote Interface

    To make a business method available to a client you must add the business method to the enterprise bean remote interface.
  26. Right click on getCustomerInfo()in the Members pane.
  27. Select Add To -> EJB Remote Interface.

    The business method is added to the enterprise bean remote interface. This is indicated by the appearance of a symbol to the right of the method name.

    VAJ Workbench EJB tab: Members list

    Update the enterprise bean deployment descriptor

    The deployment descriptor properties specify attributes of the enterprise bean and its run time requirements.
  28. Right click on the enterprise bean CICSSample in the Enterprise Beans pane.
  29. Select Properties to open the Properties window.
    On the Bean tab:
  30. In the Enter the JNDI name for Bean Home field, enter the JNDI name for the enterprise bean. Sample: CICSSample .
  31. Set the attributes of the enterprise bean. For the sample:
    Property Value
    Transaction Attribute TX_SUPPORTS
    Run As Mode SYSTEM_IDENTITY
    State management attribute #STATELESS
    Session time out value 0

    Bean properties: Bean attributes tab

  32. No settings are required for the Environment tab.
  33. Click OK.
The enterprise bean is now complete.