Announcement Announcement Module
Collapse
No announcement yet.
Problems with step scope Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with step scope

    Hello,

    I try to test the possibilities of the step scope (I use the milestone 3).

    So, first of all, I have used a sample with fileReader and dbWriter (football sample).
    I have added a step scope on the reader and the writer.
    I have run the job and a ReaderNotOpenException is thrown.

    If I remove the scope, the job runs correctly.

    Do somebody have a idea about that ?
    Last edited by Edouard; Dec 9th, 2008, 10:50 AM.

  • #2
    My guess is that the scope interferes with the automatic registration of you reader as a stream. Try registering the reader explicitly as a stream.

    Comment


    • #3
      sorry

      I register the ItemReader as stream in the step and a ReaderNotOpenException is always thrown.

      I try to debug the application :
      The ItemReader is opened but it does not seem the same object that is called for reading.

      Comment


      • #4
        I am sorry to insist but I test following configurations :

        This one works well :
        Code:
        	<bean id="databaseJob" parent="abstractJob">
        		<property name="name" value="databaseJob" />
        		<property name="restartable" value="true" />
        		<property name="steps">
        			<list>
        				<bean id="step1" parent="itemOrientedStep">
        					<property name="throttleLimit" value="10" />
        
        					<property name="itemReader" ref="gameFileItemReader" />
        					<property name="itemWriter" ref="gameItemWriter" />
        				</bean>
        				<bean id="step2" parent="itemOrientedStep">
        					<property name="throttleLimit" value="10" />
        
        					<property name="itemReader" ref="itemReader" />
        					<property name="itemWriter" ref="itemWriter" />
        				</bean>
        			</list>
        		</property>
        	</bean>
        
        	<bean id="gameFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
        		<property name="resource" value="classpath:/data/games.csv" />
        		<property name="lineMapper">
        			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
        				<property name="lineTokenizer">
        					<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
        						<property name="names"
        							value="id,year,team,week,opponent,completes,attempts,passingYards,passingTd,interceptions,rushes,rushYards,receptions,receptionYards,totalTd" />
        					</bean>
        				</property>
        				<property name="fieldSetMapper">
        					<bean class="org.springframework.batch.sample.domain.football.internal.GameFieldSetMapper" />
        				</property>
        			</bean>
        		</property>
        	</bean>
        
        	<bean id="gameItemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter">
        		<property name="jdbcTemplate" ref="jdbcTemplate" />
        		<property name="itemPreparedStatementSetter">
        			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
        		</property>
        		<property name="sql"
        			value="insert into GAMES (player_id, year_no, team, week, opponent,
        				completes, attempts, passing_yards, passing_td, interceptions,
        				rushes, rush_yards, receptions, receptions_yards, total_td)
        				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
        	</bean>
        
        	<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
        		<property name="dataSource" ref="jobDataSource" />
        		<property name="fetchSize" value="100" />
        		<property name="mapper">
        			<bean class="org.springframework.batch.sample.domain.football.internal.GameRowMapper" />
        		</property>
        		<property name="sql" value="select * from GAMES" />
        		<property name="verifyCursorPosition" value="false" />
        	</bean>
        
        	<bean id="itemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter">
        		<property name="jdbcTemplate" ref="jdbcTemplate" />
        		<property name="itemPreparedStatementSetter">
        			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
        		</property>
        		<property name="sql"
        			value="insert into GAMES2 (player_id, year_no, team, week, opponent,
        				completes, attempts, passing_yards, passing_td, interceptions,
        				rushes, rush_yards, receptions, receptions_yards, total_td)
        				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
        	</bean>
        this one does not work and throws a ReaderNotOpenException :
        Code:
        	<bean id="databaseJob" parent="abstractJob">
        		<property name="name" value="databaseJob" />
        		<property name="restartable" value="true" />
        		<property name="steps">
        			<list>
        				<bean id="step1" parent="itemOrientedStep">
        					<property name="throttleLimit" value="10" />
        
        					<property name="itemReader" ref="gameFileItemReader" />
        					<property name="itemWriter" ref="gameItemWriter" />
        				</bean>
        				<bean id="step2" parent="itemOrientedStep">
        					<property name="throttleLimit" value="10" />
        
        					<property name="itemReader" ref="itemReader" />
        					<property name="itemWriter" ref="itemWriter" />
        				</bean>
        			</list>
        		</property>
        	</bean>
        
        	<bean id="gameFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
        		<property name="resource" value="classpath:/data/games.csv" />
        		<property name="lineMapper">
        			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
        				<property name="lineTokenizer">
        					<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
        						<property name="names"
        							value="id,year,team,week,opponent,completes,attempts,passingYards,passingTd,interceptions,rushes,rushYards,receptions,receptionYards,totalTd" />
        					</bean>
        				</property>
        				<property name="fieldSetMapper">
        					<bean class="org.springframework.batch.sample.domain.football.internal.GameFieldSetMapper" />
        				</property>
        			</bean>
        		</property>
        	</bean>
        
        	<bean id="gameItemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter" scope="step">
        		<property name="jdbcTemplate" ref="jdbcTemplate" />
        		<property name="itemPreparedStatementSetter">
        			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
        		</property>
        		<property name="sql"
        			value="insert into GAMES (player_id, year_no, team, week, opponent,
        				completes, attempts, passing_yards, passing_td, interceptions,
        				rushes, rush_yards, receptions, receptions_yards, total_td)
        				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
        	</bean>
        
        	<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
        		<property name="dataSource" ref="jobDataSource" />
        		<property name="fetchSize" value="100" />
        		<property name="mapper">
        			<bean class="org.springframework.batch.sample.domain.football.internal.GameRowMapper" />
        		</property>
        		<property name="sql" value="select * from GAMES" />
        		<property name="verifyCursorPosition" value="false" />
        	</bean>
        
        	<bean id="itemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter" scope="step">
        		<property name="jdbcTemplate" ref="jdbcTemplate" />
        		<property name="itemPreparedStatementSetter">
        			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
        		</property>
        		<property name="sql"
        			value="insert into GAMES2 (player_id, year_no, team, week, opponent,
        				completes, attempts, passing_yards, passing_td, interceptions,
        				rushes, rush_yards, receptions, receptions_yards, total_td)
        				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
        	</bean>
        
        <bean class="org.springframework.batch.core.scope.StepScope" />
        Should I open a issue on JIRA ?

        Comment


        • #5
          I am sorry to insist but I test following configurations :

          This one works well :
          Code:
          	<bean id="databaseJob" parent="abstractJob">
          		<property name="name" value="databaseJob" />
          		<property name="restartable" value="true" />
          		<property name="steps">
          			<list>
          				<bean id="step1" parent="itemOrientedStep">
          					<property name="throttleLimit" value="10" />
          
          					<property name="itemReader" ref="gameFileItemReader" />
          					<property name="itemWriter" ref="gameItemWriter" />
          				</bean>
          				<bean id="step2" parent="itemOrientedStep">
          					<property name="throttleLimit" value="10" />
          
          					<property name="itemReader" ref="itemReader" />
          					<property name="itemWriter" ref="itemWriter" />
          				</bean>
          			</list>
          		</property>
          	</bean>
          
          	<bean id="gameFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
          		<property name="resource" value="classpath:/data/games.csv" />
          		<property name="lineMapper">
          			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
          				<property name="lineTokenizer">
          					<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
          						<property name="names"
          							value="id,year,team,week,opponent,completes,attempts,passingYards,passingTd,interceptions,rushes,rushYards,receptions,receptionYards,totalTd" />
          					</bean>
          				</property>
          				<property name="fieldSetMapper">
          					<bean class="org.springframework.batch.sample.domain.football.internal.GameFieldSetMapper" />
          				</property>
          			</bean>
          		</property>
          	</bean>
          
          	<bean id="gameItemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter">
          		<property name="jdbcTemplate" ref="jdbcTemplate" />
          		<property name="itemPreparedStatementSetter">
          			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
          		</property>
          		<property name="sql"
          			value="insert into GAMES (player_id, year_no, team, week, opponent,
          				completes, attempts, passing_yards, passing_td, interceptions,
          				rushes, rush_yards, receptions, receptions_yards, total_td)
          				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
          	</bean>
          
          	<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
          		<property name="dataSource" ref="jobDataSource" />
          		<property name="fetchSize" value="100" />
          		<property name="mapper">
          			<bean class="org.springframework.batch.sample.domain.football.internal.GameRowMapper" />
          		</property>
          		<property name="sql" value="select * from GAMES" />
          		<property name="verifyCursorPosition" value="false" />
          	</bean>
          
          	<bean id="itemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter">
          		<property name="jdbcTemplate" ref="jdbcTemplate" />
          		<property name="itemPreparedStatementSetter">
          			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
          		</property>
          		<property name="sql"
          			value="insert into GAMES2 (player_id, year_no, team, week, opponent,
          				completes, attempts, passing_yards, passing_td, interceptions,
          				rushes, rush_yards, receptions, receptions_yards, total_td)
          				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
          	</bean>
          
          ...
          this one does not work and throws a ReaderNotOpenException :
          Code:
          	<bean id="databaseJob" parent="abstractJob">
          		<property name="name" value="databaseJob" />
          		<property name="restartable" value="true" />
          		<property name="steps">
          			<list>
          				<bean id="step1" parent="itemOrientedStep">
          					<property name="throttleLimit" value="10" />
          
          					<property name="itemReader" ref="gameFileItemReader" />
          					<property name="itemWriter" ref="gameItemWriter" />
          
          					<property name="streams" ref="gameFileItemReader" />
          				</bean>
          				<bean id="step2" parent="itemOrientedStep">
          					<property name="throttleLimit" value="10" />
          
          					<property name="itemReader" ref="itemReader" />
          					<property name="itemWriter" ref="itemWriter" />
          
          					<property name="streams" ref="itemReader" />
          				</bean>
          			</list>
          		</property>
          	</bean>
          
          	<bean id="gameFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
          		<property name="resource" value="classpath:/data/games.csv" />
          		<property name="lineMapper">
          			<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
          				<property name="lineTokenizer">
          					<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
          						<property name="names"
          							value="id,year,team,week,opponent,completes,attempts,passingYards,passingTd,interceptions,rushes,rushYards,receptions,receptionYards,totalTd" />
          					</bean>
          				</property>
          				<property name="fieldSetMapper">
          					<bean class="org.springframework.batch.sample.domain.football.internal.GameFieldSetMapper" />
          				</property>
          			</bean>
          		</property>
          	</bean>
          
          	<bean id="gameItemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter" scope="step">
          		<property name="jdbcTemplate" ref="jdbcTemplate" />
          		<property name="itemPreparedStatementSetter">
          			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
          		</property>
          		<property name="sql"
          			value="insert into GAMES (player_id, year_no, team, week, opponent,
          				completes, attempts, passing_yards, passing_td, interceptions,
          				rushes, rush_yards, receptions, receptions_yards, total_td)
          				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
          	</bean>
          
          	<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
          		<property name="dataSource" ref="jobDataSource" />
          		<property name="fetchSize" value="100" />
          		<property name="mapper">
          			<bean class="org.springframework.batch.sample.domain.football.internal.GameRowMapper" />
          		</property>
          		<property name="sql" value="select * from GAMES" />
          		<property name="verifyCursorPosition" value="false" />
          	</bean>
          
          	<bean id="itemWriter" class="org.springframework.batch.item.database.BatchSqlUpdateItemWriter" scope="step">
          		<property name="jdbcTemplate" ref="jdbcTemplate" />
          		<property name="itemPreparedStatementSetter">
          			<bean class="org.springframework.batch.sample.domain.football.internal.GamePreparedStatementSetter" />
          		</property>
          		<property name="sql"
          			value="insert into GAMES2 (player_id, year_no, team, week, opponent,
          				completes, attempts, passing_yards, passing_td, interceptions,
          				rushes, rush_yards, receptions, receptions_yards, total_td)
          				VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )" />
          	</bean>
          
          <bean class="org.springframework.batch.core.scope.StepScope" />
          
          ...
          Differences in red

          Should I open a issue on JIRA ?

          Comment


          • #6
            Funny it works for me. Do you have a simple test case that fails? Open the JIRA (and attach a test case if you can) and we can track it. You don't need to explictly register the streams for this job (it is detected in the injected reader and writer), by the way.

            Comment

            Working...
            X