BATCH-610:JdbcCursorItemReader can now be closed and opened again without issue.

This commit is contained in:
lucasward
2008-05-02 15:12:00 +00:00
parent 4e59bf9b84
commit 68092549bd
2 changed files with 22 additions and 1 deletions

View File

@@ -230,6 +230,7 @@ public class JdbcCursorItemReader extends ExecutionContextUserSupport implements
JdbcUtils.closeStatement(this.preparedStatement);
JdbcUtils.closeConnection(this.con);
bufferredReader = null;
rs = null;
}
/*
@@ -343,7 +344,7 @@ public class JdbcCursorItemReader extends ExecutionContextUserSupport implements
*/
public void open(ExecutionContext context) {
Assert.state(!initialized, "Stream is already initialized. Close before re-opening.");
Assert.isNull(rs);
Assert.isNull(rs, "ResultSet still open! Close before re-opening.");
Assert.notNull(context, "ExecutionContext must not be null");
executeQuery();
initialized = true;

View File

@@ -55,5 +55,25 @@ public abstract class CommonItemStreamItemReaderTests extends CommonItemReaderTe
Foo fooAfterRestart = (Foo) tested.read();
assertEquals(3, fooAfterRestart.getValue());
}
public void testReopen() throws Exception {
testedAsStream().update(executionContext);
Foo foo1 = (Foo) tested.read();
assertEquals(1, foo1.getValue());
Foo foo2 = (Foo) tested.read();
assertEquals(2, foo2.getValue());
testedAsStream().update(executionContext);
// create new input source
testedAsStream().close(executionContext);
testedAsStream().open(executionContext);
Foo fooAfterRestart = (Foo) tested.read();
assertEquals(3, fooAfterRestart.getValue());
}
}