diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java index 4a99a7f51..5fe0b26de 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/IbatisPagingItemReader.java @@ -26,21 +26,42 @@ import java.util.HashMap; import com.ibatis.sqlmap.client.SqlMapClient; /** - * {@link org.springframework.batch.item.ItemReader} for reading database records using iBATIS in a paging - * fashion. - * - * It executes the query specified as the {@link #setQueryId(String)} to retrieve requested data. - * The query is executed using paged requests of a size specified in {@link #setPageSize(int)}. - * Additional pages are requested when needed as {@link #read()} method is called, returning an - * object corresponding to current position. - * + *

+ * {@link org.springframework.batch.item.ItemReader} for reading database + * records using iBATIS in a paging fashion. + *

+ * + *

+ * It executes the query specified as the {@link #setQueryId(String)} to + * retrieve requested data. The query is executed using paged requests of a size + * specified in {@link #setPageSize(int)}. Additional pages are requested when + * needed as {@link #read()} method is called, returning an object corresponding + * to current position. Some standard query parameters are provided by the + * reader and the SQL in the named query must use some or all of these parameters + * (depending on the SQL variant) to construct a result set of the required + * size. The parameters are: + *

+ * Failure to write the correct platform-specific SQL often results in an + * infinite loop in the reader because it keeps asking for the next page and + * gets the same result set over and over. + *

+ * + *

* The performance of the paging depends on the iBATIS implementation. - * - * Setting a fairly large page size and using a commit interval that matches the page size should provide - * better performance. - * + * Setting a fairly large page size and using a commit interval that matches the + * page size should provide better performance. + *

+ * + *

* The implementation is *not* thread-safe. - * + *

+ * * @author Thomas Risberg * @since 2.0 */ @@ -68,14 +89,14 @@ public class IbatisPagingItemReader extends AbstractPagingItemReader { /** * The parameter values to be used for the query execution. - * - * @param parameterValues the values keyed by the parameter named used in the query string. + * + * @param parameterValues the values keyed by the parameter named used in + * the query string. */ public void setParameterValues(Map parameterValues) { this.parameterValues = parameterValues; } - /** * Check mandatory properties. * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java index 88277ec40..67bd642cb 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java @@ -5,7 +5,9 @@ import static org.junit.Assert.assertEquals; import javax.sql.DataSource; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; +import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.sample.Foo; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.junit.Before; @@ -31,13 +33,14 @@ public abstract class AbstractDatabaseItemStreamItemReaderTests extends Abstract @Test public void testReadToExhaustion() throws Exception { ItemReader reader = getItemReader(); - pointToEmptyInput(reader); + ((ItemStream) reader).open(new ExecutionContext()); + // pointToEmptyInput(reader); int count = 0; Foo item = new Foo(); while (count++<100 && item!=null) { item = reader.read(); } - assertEquals(2, count); + assertEquals(7, count); } protected DataSource getDataSource() { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java index 1eff93894..04a06ec3e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/IbatisPagingItemReaderCommonTests.java @@ -23,6 +23,7 @@ public class IbatisPagingItemReaderCommonTests extends AbstractDatabaseItemStrea IbatisPagingItemReader reader = new IbatisPagingItemReader(); reader.setQueryId("getPagedFoos"); + reader.setPageSize(2); reader.setSqlMapClient(sqlMapClient); reader.setSaveState(true);