Class JpaPagingItemReaderBuilder<T>
- java.lang.Object
- org.springframework.batch.item.database.builder.JpaPagingItemReaderBuilder<T>
public class JpaPagingItemReaderBuilder<T> extends java.lang.Object
Creates a fully qualified JpaPagingItemReader.- Since:
- 4.0
- Author:
- Michael Minella, Glenn Renfro
Constructor Summary
Constructors Constructor Description JpaPagingItemReaderBuilder()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JpaPagingItemReader<T>
build()
Returns a fully constructedJpaPagingItemReader
.JpaPagingItemReaderBuilder<T>
currentItemCount(int currentItemCount)
Index for the current item.JpaPagingItemReaderBuilder<T>
entityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
TheEntityManagerFactory
to be used for executing the configuredqueryString
.JpaPagingItemReaderBuilder<T>
maxItemCount(int maxItemCount)
Configure the max number of items to be read.JpaPagingItemReaderBuilder<T>
name(java.lang.String name)
The name used to calculate the key within theExecutionContext
.JpaPagingItemReaderBuilder<T>
pageSize(int pageSize)
The number of records to request per page/query.JpaPagingItemReaderBuilder<T>
parameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
A map of parameter values to be set on the query.JpaPagingItemReaderBuilder<T>
queryProvider(JpaQueryProvider queryProvider)
A query provider.JpaPagingItemReaderBuilder<T>
queryString(java.lang.String queryString)
The HQL query string to execute.JpaPagingItemReaderBuilder<T>
saveState(boolean saveState)
Configure if the state of theItemStreamSupport
should be persisted within theExecutionContext
for restart purposes.JpaPagingItemReaderBuilder<T>
transacted(boolean transacted)
Indicates if a transaction should be created around the read (true by default).
Method Detail
saveState
public JpaPagingItemReaderBuilder<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 JpaPagingItemReaderBuilder<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 JpaPagingItemReaderBuilder<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 JpaPagingItemReaderBuilder<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)
pageSize
public JpaPagingItemReaderBuilder<T> pageSize(int pageSize)
The number of records to request per page/query. Defaults to 10. Must be greater than zero.- Parameters:
pageSize
- number of items- Returns:
- this instance for method chaining
- See Also:
AbstractPagingItemReader.setPageSize(int)
parameterValues
public JpaPagingItemReaderBuilder<T> parameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
A map of parameter values to be set on the query. The key of the map is the name of the parameter to be set with the value being the value to be set.- Parameters:
parameterValues
- map of values- Returns:
- this instance for method chaining
- See Also:
JpaPagingItemReader.setParameterValues(Map)
queryProvider
public JpaPagingItemReaderBuilder<T> queryProvider(JpaQueryProvider queryProvider)
A query provider. This should be set only ifqueryString(String)
have not been set.- Parameters:
queryProvider
- the query provider- Returns:
- this instance for method chaining
- See Also:
JpaPagingItemReader.setQueryProvider(JpaQueryProvider)
queryString
public JpaPagingItemReaderBuilder<T> queryString(java.lang.String queryString)
The HQL query string to execute. This should only be set ifqueryProvider(JpaQueryProvider)
has not been set.- Parameters:
queryString
- the HQL query- Returns:
- this instance for method chaining
- See Also:
JpaPagingItemReader.setQueryString(String)
transacted
public JpaPagingItemReaderBuilder<T> transacted(boolean transacted)
Indicates if a transaction should be created around the read (true by default). Can be set to false in cases where JPA implementation doesn't support a particular transaction, however this may cause object inconsistency in the EntityManagerFactory.- Parameters:
transacted
- defaults to true- Returns:
- this instance for method chaining
- See Also:
JpaPagingItemReader.setTransacted(boolean)
entityManagerFactory
public JpaPagingItemReaderBuilder<T> entityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
TheEntityManagerFactory
to be used for executing the configuredqueryString
.- Parameters:
entityManagerFactory
-EntityManagerFactory
used to createEntityManager
- Returns:
- this instance for method chaining
build
public JpaPagingItemReader<T> build()
Returns a fully constructedJpaPagingItemReader
.- Returns:
- a new
JpaPagingItemReader