Class RepositoryItemReaderBuilder<T>
- java.lang.Object
- org.springframework.batch.item.data.builder.RepositoryItemReaderBuilder<T>
public class RepositoryItemReaderBuilder<T> extends java.lang.Object
A builder implementation for theRepositoryItemReader
.- Since:
- 4.0
- Author:
- Glenn Renfro, Mahmoud Ben Hassine
- See Also:
RepositoryItemReader
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RepositoryItemReaderBuilder.RepositoryMethodReference<T>
Establishes a proxy that will capture a the Repository and the associated methodName that will be used by the reader.
Constructor Summary
Constructors Constructor Description RepositoryItemReaderBuilder()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RepositoryItemReaderBuilder<T>
arguments(java.util.List<?> arguments)
Arguments to be passed to the data providing method.RepositoryItemReader<T>
build()
Builds theRepositoryItemReader
.RepositoryItemReaderBuilder<T>
currentItemCount(int currentItemCount)
Index for the current item.RepositoryItemReaderBuilder<T>
maxItemCount(int maxItemCount)
Configure the max number of items to be read.RepositoryItemReaderBuilder<T>
methodName(java.lang.String methodName)
Specifies what method on the repository to call.RepositoryItemReaderBuilder<T>
name(java.lang.String name)
The name used to calculate the key within theExecutionContext
.RepositoryItemReaderBuilder<T>
pageSize(int pageSize)
Establish the pageSize for the generated RepositoryItemReader.RepositoryItemReaderBuilder<T>
repository(RepositoryItemReaderBuilder.RepositoryMethodReference repositoryMethodReference)
Specifies a repository and the type-safe method to call for the reader.RepositoryItemReaderBuilder<T>
repository(org.springframework.data.repository.PagingAndSortingRepository<?,?> repository)
ThePagingAndSortingRepository
implementation used to read input from.RepositoryItemReaderBuilder<T>
saveState(boolean saveState)
Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
for restart purposes.RepositoryItemReaderBuilder<T>
sorts(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)
Provides ordering of the results so that order is maintained between paged queries.
Method Detail
saveState
public RepositoryItemReaderBuilder<T> saveState(boolean saveState)
Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
for restart purposes.- Parameters:
saveState
- defaults to true- Returns:
- The current instance of the builder.
name
public RepositoryItemReaderBuilder<T> name(java.lang.String name)
The name used to calculate the key within theExecutionContext
. Required ifsaveState(boolean)
is set to true.- Parameters:
name
- name of the reader instance- Returns:
- The current instance of the builder.
- See Also:
ItemStreamSupport.setName(String)
maxItemCount
public RepositoryItemReaderBuilder<T> maxItemCount(int maxItemCount)
Configure the max number of items to be read.- Parameters:
maxItemCount
- the max items to be read- Returns:
- The current instance of the builder.
- See Also:
AbstractItemCountingItemStreamItemReader.setMaxItemCount(int)
currentItemCount
public RepositoryItemReaderBuilder<T> currentItemCount(int currentItemCount)
Index for the current item. Used on restarts to indicate where to start from.- Parameters:
currentItemCount
- current index- Returns:
- this instance for method chaining
- See Also:
AbstractItemCountingItemStreamItemReader.setCurrentItemCount(int)
arguments
public RepositoryItemReaderBuilder<T> arguments(java.util.List<?> arguments)
Arguments to be passed to the data providing method.- Parameters:
arguments
- list of method arguments to be passed to the repository.- Returns:
- The current instance of the builder.
- See Also:
RepositoryItemReader.setArguments(List)
sorts
public RepositoryItemReaderBuilder<T> sorts(java.util.Map<java.lang.String,org.springframework.data.domain.Sort.Direction> sorts)
Provides ordering of the results so that order is maintained between paged queries.- Parameters:
sorts
- the fields to sort by and the directions.- Returns:
- The current instance of the builder.
- See Also:
RepositoryItemReader.setSort(Map)
pageSize
public RepositoryItemReaderBuilder<T> pageSize(int pageSize)
Establish the pageSize for the generated RepositoryItemReader.- Parameters:
pageSize
- The number of items to retrieve per page.- Returns:
- The current instance of the builder.
- See Also:
RepositoryItemReader.setPageSize(int)
repository
public RepositoryItemReaderBuilder<T> repository(org.springframework.data.repository.PagingAndSortingRepository<?,?> repository)
ThePagingAndSortingRepository
implementation used to read input from.- Parameters:
repository
- underlying repository for input to be read from.- Returns:
- The current instance of the builder.
- See Also:
RepositoryItemReader.setRepository(PagingAndSortingRepository)
methodName
public RepositoryItemReaderBuilder<T> methodName(java.lang.String methodName)
Specifies what method on the repository to call. This method must takePageable
as the last argument.- Parameters:
methodName
- name of the method to invoke.- Returns:
- The current instance of the builder.
- See Also:
RepositoryItemReader.setMethodName(String)
repository
public RepositoryItemReaderBuilder<T> repository(RepositoryItemReaderBuilder.RepositoryMethodReference repositoryMethodReference)
Specifies a repository and the type-safe method to call for the reader. The method configured via this mechanism must takePageable
as the last argument. This method can be used in place ofrepository(PagingAndSortingRepository)
,methodName(String)
, andarguments(List)
. Note: The repository that is used by the repositoryMethodReference must be non-final.- Parameters:
repositoryMethodReference
- of the used to get a repository and type-safe method for use by the reader.- Returns:
- The current instance of the builder.
- See Also:
RepositoryItemReader.setMethodName(String)
,RepositoryItemReader.setRepository(PagingAndSortingRepository)
build
public RepositoryItemReader<T> build()
Builds theRepositoryItemReader
.- Returns:
- a
RepositoryItemReader