From 79c4672e6c000381fd9d2f93684b78df74b3e9e0 Mon Sep 17 00:00:00 2001 From: lucasward Date: Wed, 5 Sep 2007 19:53:43 +0000 Subject: [PATCH] Fixed SqlCursorInputSource to correctly handled blank restart data. --- .../springframework/batch/io/sql/SqlCursorInputSource.java | 7 ++++++- .../batch/io/sql/SqlCursorInputSourceIntegrationTests.java | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/infrastructure/src/main/java/org/springframework/batch/io/sql/SqlCursorInputSource.java b/infrastructure/src/main/java/org/springframework/batch/io/sql/SqlCursorInputSource.java index 7f7926f9e..09e71edf5 100644 --- a/infrastructure/src/main/java/org/springframework/batch/io/sql/SqlCursorInputSource.java +++ b/infrastructure/src/main/java/org/springframework/batch/io/sql/SqlCursorInputSource.java @@ -414,9 +414,14 @@ public class SqlCursorInputSource implements InputSource, DisposableBean, if (rs == null) { executeQuery(); } + + Properties restartProperties = data.getProperties(); + if(restartProperties.containsKey(CURRENT_PROCESSED_ROW) == false){ + return; + } try { - this.currentProcessedRow = Integer.parseInt(data.getProperties() + this.currentProcessedRow = Integer.parseInt(restartProperties .getProperty(CURRENT_PROCESSED_ROW)); rs.absolute(currentProcessedRow); } catch (SQLException se) { diff --git a/infrastructure/src/test/java/org/springframework/batch/io/sql/SqlCursorInputSourceIntegrationTests.java b/infrastructure/src/test/java/org/springframework/batch/io/sql/SqlCursorInputSourceIntegrationTests.java index 5b625d33c..52f419592 100644 --- a/infrastructure/src/test/java/org/springframework/batch/io/sql/SqlCursorInputSourceIntegrationTests.java +++ b/infrastructure/src/test/java/org/springframework/batch/io/sql/SqlCursorInputSourceIntegrationTests.java @@ -7,6 +7,7 @@ import java.util.Properties; import org.springframework.batch.repeat.context.RepeatContextSupport; import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager; import org.springframework.batch.repeat.synch.RepeatSynchronizationManager; +import org.springframework.batch.restart.GenericRestartData; import org.springframework.batch.restart.RestartData; import org.springframework.jdbc.core.RowMapper; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -94,6 +95,12 @@ public class SqlCursorInputSourceIntegrationTests extends AbstractTransactionalD validateFoo(3, "bar3", 3, foo); } + public void testRestartWithEmptyRestartData(){ + + RestartData restartData = new GenericRestartData(new Properties()); + sqlCursorInputSource.restoreFrom(restartData); + } + public void testReadWithNullMapper(){ //calling read without a mapper should throw an exception.