BATCH-1728: Added some documentation in the AbstractPaginatedDataItemReader and fixed the message in the RepositoryItemWriter
This commit is contained in:
@@ -2,10 +2,21 @@ package org.springframework.batch.item.data;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStreamReader;
|
||||
import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader;
|
||||
|
||||
/**
|
||||
* A base class that handles basic reading logic based on the paginated
|
||||
* semantics of Spring Data's paginated facilities. It also handles the
|
||||
* semantics required for restartability based on those facilities.
|
||||
*
|
||||
* @author Michael Minella
|
||||
* @since 2.2
|
||||
* @param <T> Type of item to be read
|
||||
*/
|
||||
public abstract class AbstractPaginatedDataItemReader<T> extends
|
||||
AbstractItemCountingItemStreamItemReader<T> {
|
||||
AbstractItemCountingItemStreamItemReader<T> {
|
||||
|
||||
protected volatile int page = 0;
|
||||
|
||||
@@ -15,6 +26,11 @@ public abstract class AbstractPaginatedDataItemReader<T> extends
|
||||
|
||||
private Object lock = new Object();
|
||||
|
||||
/**
|
||||
* The number of items to be read with each page.
|
||||
*
|
||||
* @param pageSize the number of items
|
||||
*/
|
||||
public void setPageSize(int pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
@@ -44,7 +60,19 @@ public abstract class AbstractPaginatedDataItemReader<T> extends
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Iterator doPageRead();
|
||||
/**
|
||||
* Method this {@link ItemStreamReader} delegates to
|
||||
* for the actual work of reading a page. Each time
|
||||
* this method is called, the resulting {@link Iterator}
|
||||
* should contain the items read within the next page.
|
||||
* <br/><br/>
|
||||
* If the {@link Iterator} is empty or null when it is
|
||||
* returned, this {@link ItemReader} will assume that the
|
||||
* input has been exhausted.
|
||||
*
|
||||
* @return an {@link Iterator} containing the items within a page.
|
||||
*/
|
||||
protected abstract Iterator<T> doPageRead();
|
||||
|
||||
@Override
|
||||
protected void doOpen() throws Exception {
|
||||
@@ -60,7 +88,7 @@ public abstract class AbstractPaginatedDataItemReader<T> extends
|
||||
page = itemLastIndex / pageSize;
|
||||
int current = itemLastIndex % pageSize;
|
||||
|
||||
Iterator initialPage = doPageRead();
|
||||
Iterator<T> initialPage = doPageRead();
|
||||
|
||||
for(; current >= 0; current--) {
|
||||
initialPage.next();
|
||||
|
||||
@@ -84,6 +84,7 @@ public class RepositoryItemWriter implements ItemWriter, InitializingBean {
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public void write(List items) throws Exception {
|
||||
if(!CollectionUtils.isEmpty(items)) {
|
||||
doWrite(items);
|
||||
@@ -112,8 +113,9 @@ public class RepositoryItemWriter implements ItemWriter, InitializingBean {
|
||||
/**
|
||||
* Check mandatory properties - there must be a repository.
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(repository != null, "A CRUDRepository is required");
|
||||
Assert.state(repository != null, "A CrudRepository implementation is required");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user