Topic
  • 2 replies
  • Latest Post - ‏2013-01-14T16:46:12Z by SystemAdmin
SystemAdmin
SystemAdmin
783 Posts

Pinned topic SubJobAnalyzer and SubJobCollector Example Code?

‏2013-01-11T17:18:04Z |
Hi,

I can understand the purpose and a usage scenario for these classes but have been unable to find any example code on how to use them properly or the JobStepContext. Does anyone have any examples or know of any out there maybe I have missed?

Any help would be appreciated - thanks!
Updated on 2013-01-14T16:46:12Z at 2013-01-14T16:46:12Z by SystemAdmin
  • sspavan
    sspavan
    60 Posts

    Re: SubJobAnalyzer and SubJobCollector Example Code?

    ‏2013-01-12T20:57:56Z  
    Hi,

    I have used JobStepContext for pass data between steps and to pass data from job to various classes of a step, never worked on SubJobAnalyzer and SubJobCollector.

    1. Step-2-Step communication
    In your step1 do the following to add data to job context

    JobStepContext ctx=JobStepContextMgr.getContext();
    PersistentMap hmap = PersistentMapFactory.createPersistentMap();
    hmap.setString("FName", "pavan");
    hmap.setString("LName","surey");
    ctx.setJobLevelUserData(hmap);

    In your step2 do the following to read the data from job context

    JobStepContext ctx=JobStepContextMgr.getContext();
    PersistentMap hmap = (PersistentMap)ctx.getJobLevelUserData();
    try {
    System.out.println("lname from hamp data " + hmap.getString("LName"));
    System.out.println("fname from hamp data " + hmap.getString("FName"));
    } catch (BatchContainerPersistentContextException e) {
    e.printStackTrace();
    }

    2. Pass data from job to various classes of a step

    My xjcl passes a property dateCard with a date, and I need that date information in different classes

    So in Processor I have below code to get dateCard from xjcl and add it to jobstepcontext
    JobStepContext ctx = JobStepContextMgr.getContext();
    String runDate = getProperties().getProperty("dateCard");
    props.setProperty("dateCard", dateCard.getDate());
    ctx.setProperties(props);

    In one of the classes I do the following to read data
    JobStepContext ctx = JobStepContextMgr.getContext();
    String runDate = ctx.getProperties().getProperty("dateCard");

    Hope this helps.

    Thanks,
  • SystemAdmin
    SystemAdmin
    783 Posts

    Re: SubJobAnalyzer and SubJobCollector Example Code?

    ‏2013-01-14T16:46:12Z  
    • sspavan
    • ‏2013-01-12T20:57:56Z
    Hi,

    I have used JobStepContext for pass data between steps and to pass data from job to various classes of a step, never worked on SubJobAnalyzer and SubJobCollector.

    1. Step-2-Step communication
    In your step1 do the following to add data to job context

    JobStepContext ctx=JobStepContextMgr.getContext();
    PersistentMap hmap = PersistentMapFactory.createPersistentMap();
    hmap.setString("FName", "pavan");
    hmap.setString("LName","surey");
    ctx.setJobLevelUserData(hmap);

    In your step2 do the following to read the data from job context

    JobStepContext ctx=JobStepContextMgr.getContext();
    PersistentMap hmap = (PersistentMap)ctx.getJobLevelUserData();
    try {
    System.out.println("lname from hamp data " + hmap.getString("LName"));
    System.out.println("fname from hamp data " + hmap.getString("FName"));
    } catch (BatchContainerPersistentContextException e) {
    e.printStackTrace();
    }

    2. Pass data from job to various classes of a step

    My xjcl passes a property dateCard with a date, and I need that date information in different classes

    So in Processor I have below code to get dateCard from xjcl and add it to jobstepcontext
    JobStepContext ctx = JobStepContextMgr.getContext();
    String runDate = getProperties().getProperty("dateCard");
    props.setProperty("dateCard", dateCard.getDate());
    ctx.setProperties(props);

    In one of the classes I do the following to read data
    JobStepContext ctx = JobStepContextMgr.getContext();
    String runDate = ctx.getProperties().getProperty("dateCard");

    Hope this helps.

    Thanks,
    Thanks sspavan, this helps a lot with understanding the JobStepContext!