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