RESOLVED - BATCH-578: remove self-initialization from ItemReader#read() implementations
This commit is contained in:
@@ -51,3 +51,7 @@ bespoke
|
||||
standalone
|
||||
kasanicky
|
||||
remedial
|
||||
ben
|
||||
overriden
|
||||
backport
|
||||
mapper
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.job.SimpleJob;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.database.JdbcCursorItemReader;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class JdbcCursorItemReaderPreparedStatementIntegrationTests extends
|
||||
}
|
||||
|
||||
public void testRead() throws Exception{
|
||||
|
||||
itemReader.open(new ExecutionContext());
|
||||
Foo foo = (Foo)itemReader.read();
|
||||
assertEquals(2, foo.getId());
|
||||
foo = (Foo)itemReader.read();
|
||||
|
||||
@@ -102,9 +102,6 @@ public class DrivingQueryItemReader implements ItemReader, InitializingBean,
|
||||
* null otherwise.
|
||||
*/
|
||||
public Object read() {
|
||||
if (!initialized) {
|
||||
open(new ExecutionContext());
|
||||
}
|
||||
|
||||
if (keysIterator.hasNext()) {
|
||||
currentIndex++;
|
||||
|
||||
@@ -76,9 +76,7 @@ public class HibernateCursorItemReader extends ExecutionContextUserSupport imple
|
||||
}
|
||||
|
||||
public Object read() {
|
||||
if (!initialized) {
|
||||
open(new ExecutionContext());
|
||||
}
|
||||
|
||||
if (cursor.next()) {
|
||||
currentProcessedRow++;
|
||||
Object[] data = cursor.get();
|
||||
|
||||
@@ -151,6 +151,7 @@ public class JdbcCursorItemReader extends ExecutionContextUserSupport implements
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(dataSource, "DataSOurce must be provided");
|
||||
Assert.notNull(sql, "The SQL query must be provided");
|
||||
Assert.notNull(mapper, "RowMapper must be provided");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,12 +175,6 @@ public class JdbcCursorItemReader extends ExecutionContextUserSupport implements
|
||||
*/
|
||||
public Object read() throws Exception{
|
||||
|
||||
if (!initialized) {
|
||||
open(new ExecutionContext());
|
||||
}
|
||||
|
||||
Assert.state(mapper != null, "Mapper must not be null.");
|
||||
|
||||
return bufferredReader.read();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,8 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
|
||||
*/
|
||||
public void testNormalProcessing() throws Exception {
|
||||
getAsInitializingBean(reader).afterPropertiesSet();
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
Foo foo1 = (Foo) reader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
|
||||
@@ -116,6 +117,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
|
||||
|
||||
// create new input source
|
||||
reader = createItemReader();
|
||||
getAsItemStream(reader).open(new ExecutionContext());
|
||||
|
||||
Foo foo = (Foo) reader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -134,7 +136,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
Foo foo = (Foo) reader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -145,6 +147,8 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
Foo foo1 = (Foo) reader.read();
|
||||
|
||||
commit();
|
||||
|
||||
@@ -105,6 +105,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
|
||||
// create new input source
|
||||
itemReader = createItemReader();
|
||||
getAsItemStream(itemReader).open(new ExecutionContext());
|
||||
|
||||
Foo foo = (Foo) itemReader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -134,6 +135,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
getAsItemStream(itemReader).open(executionContext);
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
|
||||
commit();
|
||||
|
||||
@@ -44,6 +44,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
*/
|
||||
public void testNormalProcessing() throws Exception {
|
||||
getAsInitializingBean(itemReader).afterPropertiesSet();
|
||||
getAsItemStream(itemReader).open(new ExecutionContext());
|
||||
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
@@ -109,6 +110,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
// create new input source
|
||||
itemReader = createItemReader();
|
||||
getAsItemStream(itemReader).open(new ExecutionContext());
|
||||
|
||||
Foo foo = (Foo) itemReader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -140,6 +142,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
getAsItemStream(itemReader).open(new ExecutionContext());
|
||||
Foo foo1 = (Foo) itemReader.read();
|
||||
|
||||
commit();
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -56,6 +57,7 @@ public class HibernateCursorProjectionItemReaderIntegrationTests extends Abstrac
|
||||
|
||||
public void testNormalProcessing() throws Exception {
|
||||
((InitializingBean) reader).afterPropertiesSet();
|
||||
((ItemStream) reader).open(new ExecutionContext());
|
||||
Object[] foo1 = (Object[]) reader.read();
|
||||
assertEquals(new Integer(1), foo1[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user