Class JpaCursorItemReader<T>
java.lang.Object
org.springframework.batch.item.ItemStreamSupport
org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
org.springframework.batch.item.database.JpaCursorItemReader<T>
- Type Parameters:
T- type of items to read
- All Implemented Interfaces:
ItemReader<T>,ItemStream,ItemStreamReader<T>,org.springframework.beans.factory.InitializingBean
public class JpaCursorItemReader<T>
extends AbstractItemCountingItemStreamItemReader<T>
implements org.springframework.beans.factory.InitializingBean
ItemStreamReader implementation based on JPA
Query.getResultStream(). It executes the JPQL query when initialized and
iterates over the result set as AbstractItemCountingItemStreamItemReader.read() method is called, returning an object
corresponding to the current row. The query can be set directly using
setQueryString(String), or using a query provider via
setQueryProvider(JpaQueryProvider).
The implementation is not thread-safe.
- Since:
- 4.3
- Author:
- Mahmoud Ben Hassine, Jinwoo Bae
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voiddoClose()Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().protected voiddoOpen()Open resources necessary to start reading input.protected TdoRead()Read next item from input.voidsetEntityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory) Set the JPA entity manager factory.voidsetHintValues(Map<String, Object> hintValues) Set the query hint values for the JPA query.voidsetParameterValues(Map<String, Object> parameterValues) Set the parameter values to be used for the query execution.voidsetQueryProvider(JpaQueryProvider queryProvider) Set the JPA query provider.voidsetQueryString(String queryString) Set the JPQL query string.voidupdate(ExecutionContext executionContext) Indicates that the execution context provided during open is about to be saved.Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveStateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, getName, setExecutionContextName, setName
-
Constructor Details
-
JpaCursorItemReader
public JpaCursorItemReader()Create a newJpaCursorItemReader.
-
-
Method Details
-
setEntityManagerFactory
public void setEntityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory) Set the JPA entity manager factory.- Parameters:
entityManagerFactory- JPA entity manager factory
-
setQueryProvider
Set the JPA query provider.- Parameters:
queryProvider- JPA query provider
-
setQueryString
Set the JPQL query string.- Parameters:
queryString- JPQL query string
-
setParameterValues
Set the parameter values to be used for the query execution.- Parameters:
parameterValues- the values keyed by parameter names used in the query string.
-
setHintValues
Set the query hint values for the JPA query. Query hints can be used to give instructions to the JPA provider.- Parameters:
hintValues- a map where each key is the name of the hint, and the corresponding value is the hint's value.- Since:
- 5.2
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
doOpen
Description copied from class:AbstractItemCountingItemStreamItemReaderOpen resources necessary to start reading input.- Specified by:
doOpenin classAbstractItemCountingItemStreamItemReader<T>- Throws:
Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
-
doRead
Description copied from class:AbstractItemCountingItemStreamItemReaderRead next item from input.- Specified by:
doReadin classAbstractItemCountingItemStreamItemReader<T>- Returns:
- an item or
nullif the data source is exhausted
-
update
Description copied from interface:ItemStreamIndicates that the execution context provided during open is about to be saved. If any state is remaining, but has not been put in the context, it should be added here.- Specified by:
updatein interfaceItemStream- Overrides:
updatein classAbstractItemCountingItemStreamItemReader<T>- Parameters:
executionContext- to be updated- Throws:
ItemStreamException
-
doClose
protected void doClose()Description copied from class:AbstractItemCountingItemStreamItemReaderClose the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().- Specified by:
doClosein classAbstractItemCountingItemStreamItemReader<T>
-