Announcement Announcement Module
Collapse
No announcement yet.
Setting sql parameters for the reader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting sql parameters for the reader

    Reader is reading data from the database. In the xml file, value for the property "sql" is set for this reader. I want to include "where id=?" in the sql.

    How to set the value for this "id" in the where clause during runtime?

    I am using "JdbcCursorItemReader". Do you have any example of using "DrivingQueryItemReader"?

  • #2
    Why donot you use JdbcDaoSupport which will enable you for preparedStatements.

    then by using setObject(1,value)..
    you can set the values...

    Regards
    Laks

    Comment


    • #3
      That's the approach I went for on the JdbcCursorItemReader, which you can use because a PreparedStatementSetter is exposed. However, there were too many api issues for me to get it done in time for 1.0 for the DrivingQuery readers. You will need to implement your own KeyCollectors for that. It should be a pretty similar pattern to what was done for the cursor though.

      Comment


      • #4
        Originally posted by lucasward View Post
        That's the approach I went for on the JdbcCursorItemReader, which you can use because a PreparedStatementSetter is exposed.
        I am using JdbcCursorItemReader. I have a class A implementing PreparedStatementSetter. The value to be set is with the JobParameters. How do i get the value from the JobParameters in the class A?

        Comment


        • #5
          There's already a class that does that: StepExecutionPreparedStatementSetter

          You just need to register it as a StepListener as well as passing it to the item reader.

          Comment


          • #6
            Originally posted by lucasward View Post
            There's already a class that does that: StepExecutionPreparedStatementSetter

            You just need to register it as a StepListener as well as passing it to the item reader.
            Thanks, Lucas!
            One more questions.... If i need to retrieve the value from the executionContext then do i need to implement (creating a class)StepExecutionPreparedStatementSetter?

            Comment


            • #7
              Any clue how to implement this?

              Comment


              • #8
                Yes, you would implement it in a similar way to the JobParameters version that's already available, all you would need would be to get the ExecutionContext, in addition to the JobParameters from the StepExecution.

                Comment


                • #9
                  Originally posted by lucasward View Post
                  Yes, you would implement it in a similar way to the JobParameters version that's already available, all you would need would be to get the ExecutionContext, in addition to the JobParameters from the StepExecution.
                  LoadID was stored in the executionContext by step-1. I am attaching StepExecutionPreparedStSetter to the step-2. So here in the step-2, would obviously not get the LoadID from the ExecutionContext.

                  I want to keep the listeners separate for the step-1 and step-2 (reason-1 -> easier to maintain..... reason-2 -> don't want to set empty parameterKeys for step-1)

                  One of the ways i was thinking was to access the LoadID from the table step_execution_context. Is there any better way to access LoadID in the step-2?

                  Comment


                  • #10
                    One easy way I can think of is to define your own singleton context and place all your job/step related parameters in there.

                    For ex. define MyJobContext as a singleton java class and have some properties (like LoadID) in it. you should be able to get that from your job or any subsequent steps.

                    Hope that helps!

                    Comment


                    • #11
                      You just need to register it as a StepListener as well as passing it to the item reader.
                      Can you please explain how I register this as a StepListener in 2.0.0 RC1

                      Comment


                      • #12
                        There's a listener tag in the xsd:

                        http://static.springframework.org/sp...x.html#d0e2686

                        Comment

                        Working...
                        X