Announcement Announcement Module
Collapse
No announcement yet.
execution context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • execution context

    Hello,

    I've a step which reads several rows from table and sets them to dao's. I would like to save the list of DAO's to execution context for the next steps to use. Could you please tell me how to set the list of objects to execution context. Or is there any other way to save this information.

    Code:
    job xml
    
    <step id="getProperties">
                    <tasklet>
                           <chunk reader="propertiesReader" writer="propertiesWriter"/>                           
                   </tasklet>
                </step>
    
    <bean id="propertiesReader" parent="baseIscReader" >
            <property name="queryId" value="getAllProperties" />
     </bean>
    
    SQLMap
    
    <select id="getAllProperties" resultMap="propertiesDAO">
             SELECT * from PROPERTY  
    </select>  
    
    <resultMap id="propertiesDAO" class="com.pnc.tsc.model.PropertiesDAO">
        <result property="propertyName" column="PROPERTYNAME" />
        <result property="propertyValue" column="PROPERTYVALUE" />
      </resultMap>
    Thanks

  • #2
    There is a section in the reference documentation on "Passing data to future steps":
    http://static.springframework.org/sp...s.html#d0e7667

    Comment


    • #3
      Originally posted by DHGarrette View Post
      There is a section in the reference documentation on "Passing data to future steps":
      http://static.springframework.org/sp...s.html#d0e7667
      Hi, I am trying to follow what is mentioned in the link to persist an object's state through the job in other words passing the sate to future jobs by setting it to job context. However I could there is partial success, am not able to read the object with key, here is the scenario.

      Code:
      JOB:
      
      <step id="getProperties" next="A">
       <tasklet>
         <chunk reader="propertiesReader" writer="propertiesWriter"  commit-interval="20">
         </chunk>                           
         <listeners> 
         <listener ref="propListener"/>
         </listeners>
       </tasklet>                     
      </step>
      <step id="B" >
         <tasklet>
          <chunk reader="readProperties"  writer="itemWriter" commit-interval="20"></chunk>
         </tasklet>
      </step>
       <beans:bean id="propListener" 
               class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
       <beans:property name="keys" value="prop"/>     
      
      propertiesWriter:
      
      public class PropertiesWriter implements ItemStream, ItemWriter{         
      ...
       public void update(ExecutionContext executionContext) throws ItemStreamException {
             executionContext.put("prop", propertiesList); //propertiesList is an ArrayList created in other method
          }  
      
      readProperties:
      
      public void open(ExecutionContext executionContext) throws ItemStreamException {  
           log.debug("PROPERTIES"+executionContext.containsKey("prop"));        
      }
      I checked the JOB CONTEXT and STEP CONTEXT table and it looks like the object is persisted to short_context column, however when in the readProperties am not able to find the object with key that was set. Am I missing something here?

      Comment


      • #4
        Your problem arises because there are two ExecutionContexts. The PromotionListener puts your entry into the Job ExecutionContext so that future steps can access it. However, the open() method's parameter is the Step ExecutionContext, so it doesn't have the entry. Instead of open(), you need to use a BeforeStep method:
        Code:
        @BeforeStep
        public void getJobExecutionContextEntry(StepExecution stepExecution) {
            ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext();
            Object prop = jobContext.get("prop");
        }

        Comment


        • #5
          Originally posted by DHGarrette View Post
          Your problem arises because there are two ExecutionContexts. The PromotionListener puts your entry into the Job ExecutionContext so that future steps can access it. However, the open() method's parameter is the Step ExecutionContext, so it doesn't have the entry. Instead of open(), you need to use a BeforeStep method:
          Code:
          @BeforeStep
          public void getJobExecutionContextEntry(StepExecution stepExecution) {
              ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext();
              Object prop = jobContext.get("prop");
          }
          Thanks, it works when I override BeforeStep from StepExecutionListener interface. Is it possible to pass multiple keys something like:

          Code:
          <beans:bean id="propListener"          class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
           <beans:property name="keys" value="prop"/>     
           <beans:property name="keys" value="prop1"/>     
           <beans:property name="keys" value="prop2"/>

          Comment


          • #6
            I found a way to pass multiple keys, here is the way
            Code:
            <beans:bean id="propListener"  class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
            <beans:property name="keys">
            <beans:list>
            <beans:value>prop1</beans:value>
            <beans:value>prop2</beans:value>
            <beans:value>prop3</beans:value>
            </beans:list>
            </beans:property>

            Comment


            • #7
              You can actually do the following since 'key's is a String[] on the listener:
              Code:
              <beans:bean id="propListener"  class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
                  <beans:property name="keys" value="prop1,prop2,prop3">
              </beans:property>

              Comment

              Working...
              X