WebSphere Extended Deployment, Version 6.0.x
             Operating Systems: AIX, HP-UX, Linux, Solaris, Windows, z/OS


Developing a simple batch application

This topic describes how to write a simple batch application.

Before you begin

Before starting this task, you must set up your environment.

About this task

This sample task assumes that the user is using Rational Application Developer (RAD). Other development tools can be used as well.

Procedure

  1. Create a new enterprise application project entitled PostingsSample2.
    1. Add a new Enterprise JavaBeans (EJB) project module. This creates a new EAR file and EJB project.
    2. Add BATCH_RUNTIME to the Java Build Path for the PostingsSample2EJB project.
    3. Assume that there is an existing Java class, AccountOp, a Java object that has two public interface methods, creditAccount(..) and debitAccount(..). These methods are called from the batch bean as appropriate. Import this class from the workspace, or write a batch calling class.
  2. Create the BatchStep class. The batch bean is an entity bean which inherits from an abstract Batch Step class. Do the following to create the abstract job step PostingSample2Step:
    1. In the PostingsSample2EJB project, create an abstract Java class PostingSample2Step that inherits from the BatchJobStepInterface.
    2. Add the BatchJobStepInterface.
    3. Make the class abstract.
  3. Create the Batch Bean (Entity EJB). These steps describe how to create the batch bean manually. The Batch Bean reuses the BatchJobStepLocalInterface, the BatchJobStepKey and the BatchJobStepLocalHome classes from the provided programming model; these classes are not recreated. Only the Batch Bean implementation is generated.
    1. In the PostingSample2EJB project, create a new CMP EJB, entitled PostingsSample2Data.
    2. For the local home interface class, select BatchJobStepLocalHomeInterface.
    3. For the local interface class, select BatchJobStepLocalInterface.
    4. Deselect the Use single key attribute type for the key class.
    5. For the key class, select BatchJobStepKey.
    6. Remove the CMP attribute ID.
    7. In the CMP attribute, add the two CMP attributes, jobID and stepID of type string.
    8. Add jobID as the name, and java.lang.String as the type. Select Key.
    9. Similarly, add stepID, type java.lang.String and make it the Key field.
    10. Select the BeanSuperclass. Create a matching type of PostingStep2. This creates the new EJB, but only the EJB Bean class displays in the projects. The local interface, home interface and the key class are picked up from the programming model provided classes.
    11. Editing the deployment descriptor. Make the following changes in the ejb-jar.xml for the PostingSample2Data.
      1. In the Bean tab, edit the CMP connection factory JNDI name to jdbc/lree, and the Container Authorization type to Per_Connection_Factory.
      2. In the Assembly tab, for the container transactions, make all methods of the PostingsSample2Data as Required.
      3. Edit the JNDI name under WebSphere bindings to ejb/com/ibm/ws/batch/sample/PostingsSample2Data.
    12. Save and close the deployment descriptor. As before, add the implementation for the EJB later.
  4. Create the Batch Job Session Bean The batch Job is a session bean that is declared in the deployment descriptor, but has no classes generated, because they are all part of the runtime.
    1. From the ejb-jar xml, in the Bean tab, click Add to create a new Session EJB, name it PostingsJob2.
    2. Change Transaction type to Bean.
    3. In the Bean class, remote home interface and remote interface, type the following strings:
      1. Bean class : com.ibm.ws.batch.BatchJobControllerBean
      2. Remote interface: com.ibm.ws.batch.BatchJobController
      3. Remote home interface: com.ibm.ws.batch.BatchJobControllerHome

      Note that no new class is generated; This is because all the classes exist in the runtime. We are only declaring the Job Session bean in the deployment descriptor.

    4. Edit the WebSphere bindings JNDI name to: ejb/com/ibm/ws/batch/PostingsSample2Job
    5. Add a reference to the PostingsSample2Job of type EJB reference.
    6. Select the PostingsSample2Data Bean and add the name: ejb/PostingsSample2Data

      Select the local reference type.

    7. Create the work Manager reference.
      1. In the references tab, on the PostingSample2Job bean, click Add. Select Resource Reference, and click Next.
      2. Name: wm/BatchWorkManager
      3. Type: Select commonj.work.WorkManager
      4. Authentication: Container
      5. Sharing Scope: Shareable
    8. Edit the Java Naming and Directory Interface (JNDI) name of the wm/BatchWorkManger to wm/default.
    9. Save and close the ejb-jar.xml.
  5. Creating the input batch data stream There can be zero, 1 or n input and/or output streams. In this example, there is one InputStream reading from a file and no output stream. Output is written to the console. The BDS classes are POJO. To create the input stream, complete the following steps:
    1. Create a new class in the com.ibm.ws.batch.sample package, called PostingsSample2InputStream.
    2. Implement the BatchDataStream Interface. This creates the new PostingSample2Input Stream class. You can add the implementations later.
  6. Create Posting2 Class to represent a record from the Input Stream. This class is the object representation of a record in the batch input stream. This is constructed while reading a record from the Input BDS, and passed on to the batch bean. This class is like a data or cargo bean that contains attributes and corresponding getters and setters, of the fields in the input stream.
    1. Create a new class named Posting2 that implements the Serializable interface. Implementations can be added to this later.
  7. Add implementations to the classes
    1. Now add implementations to the PostingSample2DataBean, PostingSample2Step and PostingSample2InputStream as in the attached class files. This example is kept simple from a processing standpoint to highlight the steps involved in developing a new batch application. After the implementation classes are added, you can deploy the EJB.

What to do next

In the administrative console navigation tree, expand Runtime Operations and select Job Management. Verify that in the panel on the right, there is an empty job table with no error messages.



Related concepts
Batch job steps
The batch programming model
Batch controller bean
Task topic    

Terms of Use | Feedback

Last updated: Nov 30, 2007 4:00:35 PM EST
http://publib.boulder.ibm.com/infocenter/wxdinfo/v6r0/index.jsp?topic=/com.ibm.websphere.xd.doc/info/scheduler/tbgridtutorial2.html