Announcement Announcement Module
Collapse
No announcement yet.
Passing multiple attributes between the steps in a job. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing multiple attributes between the steps in a job.

    Hi All,
    I wanted to pass the multiple attributes from one step to another in a job.

    I am able to pass a single variable or multiple attributes by adding code snippet in tasklet

    ExecutionContext executionContext = stepExecution.getExecutionContext();
    executionContext.put("someKey", "someValue");
    executionContext.put("someKey1", "someValue1");

    <bean id="promotionListener" class="org.springframework.batch.core.listener.Exe cutionContextPromotionListener" >
    <property name="keys" value="someValue"/> // for single value
    </bean>

    <property name="keys" value="someValue,someValue1"/> // for mutliple values

    Is there any way i can pass the excution context key values in the xml at the run time.


    Thanks for your help.

    Srikanth

  • srikanthrachala
    replied
    Thanks Gary, it helps.

    Regards,
    Srikanth.

    Leave a comment:


  • Gary Russell
    replied
    I am not sure I fully understand what you a looking for but, if you need something more sophisticated than a simple list of keys to promote, you can implement your own StepExecutionListener (just write a class that implements StepExecutionListener). Then, in the afterStep() method, promote whatever you want. You can iterate over the entrySet() to find all the keys, or just promote specific keys.

    Code:
    	public ExitStatus afterStep(StepExecution stepExecution) {
    		ExecutionContext stepContext = stepExecution.getExecutionContext();
    		ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext();
    
    ...
    
                    return null;
            }
    Just return null to leave he ExitStatus unchanged. Then, use your listener instead of the ECPL.

    HTH

    Leave a comment:


  • srikanthrachala
    replied
    Hi Gary,

    Sorry it was typo. your are correct that should be keynames

    <property name="keys" value="someKey,someKey1"/>.

    Is there anyway we can populate these key names in the xml at runtime, instead of specifying the keynames what we are going to use at compile time.

    I mean if we are adding some attributes to stepExecution context like

    ExecutionContext executionContext = stepExecution.getExecutionContext();
    executionContext.put("someKey", "someValue");
    executionContext.put("someKey1", "someValue1");
    ..
    executionContext.put("someKeyn", "someValuen");


    instead of putting the keys at compile time like

    <property name="keys" value="someKey,someKey1,.. someKeyn"/>

    can we populate the keynames in the value field in xml at runtime from stepExecutionContext object.

    something like

    <property name="keys" value="#{stepExecutionContext..........}"/>.


    Hope I am able to explain the problem.

    Thanks

    Srikanth.

    Leave a comment:


  • Gary Russell
    replied
    First of all, you need to supply the key, not the value, in the XML...

    Code:
    <bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener" >
        <property name="keys" value="someKey"/> // for single value
    </bean>
    If you want to promote multiple keys, just use

    Code:
    <bean id="promotionListener" class="org.springframework.batch.core.listener.ExecutionContextPromotionListener" >
    	<property name="keys">
    		<list>
    			<value>someKey</value>
    			<value>someKey1</value>
    		</list>
    	</property>
    </bean>
    Then these two keys (and their values) will be promoted.

    When in doubt, just look at the JavaDoc for the property...

    Code:
    	/**
    	 * @param keys A list of keys corresponding to items in the {@link Step}
    	 * {@link ExecutionContext} that must be promoted.
    	 */
    	public void setKeys(String[] keys) {
    		this.keys = keys;
    	}
    HTH
    Last edited by Gary Russell; Jan 26th, 2011, 10:16 PM.

    Leave a comment:

Working...
X