Results 1 to 6 of 6

Thread: Problems with step scope

  1. #1
    Join Date
    Dec 2008
    Location
    Toulouse, France
    Posts
    22

    Unhappy 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 at 09:50 AM.

  2. #2
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    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.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3
    Join Date
    Dec 2008
    Location
    Toulouse, France
    Posts
    22

    Default

    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.

  4. #4
    Join Date
    Dec 2008
    Location
    Toulouse, France
    Posts
    22

    Default

    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 ?

  5. #5
    Join Date
    Dec 2008
    Location
    Toulouse, France
    Posts
    22

    Default

    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 ?

  6. #6
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •