Announcement Announcement Module
Collapse
No announcement yet.
How do I set Parameters if they are not passed while invoking CommandLineJobRunner Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I set Parameters if they are not passed while invoking CommandLineJobRunner

    Requirement
    I am using query which use period and year as input parameters in select query for data extraction. The requirements is if these parameters are not passed then we need to calculate current month and year. I am using my wrapper class ExtractRunner which calls CommandLineJobRunner.

    I have tested below query and xml config using below class
    com.gs.hcm.gms.gl.batch.ExtractRunner ASDTest.xml asdDataFromIT period=01 year=2009

    <broperty name="queryString" value="select d from InvoiceDetail d where d.postingDate is not null and MONTH(d.postingDate) = #{jobParameters[period]} and YEAR(d.postingDate) = #{jobParameters[year]} "></broperty>

    Query
    If period and year parameters are not passed, how do i set them in ExtractRunner. I tried using below technique, but it doesn't work.
    System.setProperty("period", "12");
    System.setProperty("year", "2008");

    Logs
    12:13:46,968 ERROR [step.AbstractStep] Encountered an error executing the step: class java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '#' [select d from com.gs.hcm.gms.git.model.InvoiceDetail d where d.postingDate is not null and MONTH(d.postingDate) = #{jobParameters[period]} and YEAR(d.postingDate) = #{jobParameters[year]} ]
    java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '#' [select d from com.gs.hcm.gms.git.model.InvoiceDetail d where d.postingDate is not null and MONTH(d.postingDate) = #{jobParameters[period]} and YEAR(d.postingDate) = #{jobParameters[year]} ]
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwP ersistenceException(AbstractEntityManagerImpl.java :616)

  • #2
    You can just create a JobParameters object and put your values into it:

    Code:
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("some.key", something);
    return new JobParameters(parameters);

    Comment


    • #3
      Hi, I created JobParameter object. How I do I tie it to this Job? Sorry for coming back with such basic question.

      Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
      parameters.put("period",new JobParameter("12"));
      parameters.put("year",new JobParameter("2008"));
      JobParameters jobParameters = new JobParameters(parameters);

      Thanks for your help.

      Cheers,
      Manish G

      Comment


      • #4
        Since you have your own version of CommandLineJobRunner (ExtractRunner), you should just call:
        Code:
        launcher.run(job, jobParameters);

        Comment


        • #5
          Hi, Can you paste a sample to create a job obejct?

          ExtractRunner simply calls CommandLineJobRunner.main(args);

          Thanks,
          Manish G

          Comment


          • #6
            Look at CommandLineJobRunner.start(). This should be your model.

            Comment


            • #7
              Perfect help!

              Removed command line parameters and did my test run using below and looks good.

              String[] populateParams = {args[0],args[1],"period=12","year=2008"};
              CommandLineJobRunner.main(populateParams);

              Would add conditions to handle this at run time.

              Cheers,
              Manish G

              Comment

              Working...
              X