T
- type of items to readpublic 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.Constructor and Description |
---|
JpaCursorItemReader()
Create a new
JpaCursorItemReader . |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
doClose()
Close the resources opened in
AbstractItemCountingItemStreamItemReader.doOpen() . |
protected void |
doOpen()
Open resources necessary to start reading input.
|
protected T |
doRead()
Read next item from input.
|
void |
setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
Set the JPA entity manager factory.
|
void |
setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
Set the parameter values to be used for the query execution.
|
void |
setQueryProvider(JpaQueryProvider queryProvider)
Set the JPA query provider.
|
void |
setQueryString(java.lang.String queryString)
Set the JPQL query string.
|
void |
update(ExecutionContext executionContext)
Return empty
ExecutionContext . |
close, getCurrentItemCount, isSaveState, jumpToItem, open, read, setCurrentItemCount, setMaxItemCount, setSaveState
getExecutionContextKey, setExecutionContextName, setName
public JpaCursorItemReader()
JpaCursorItemReader
.public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
entityManagerFactory
- JPA entity manager factorypublic void setQueryProvider(JpaQueryProvider queryProvider)
queryProvider
- JPA query providerpublic void setQueryString(java.lang.String queryString)
queryString
- JPQL query stringpublic void setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
parameterValues
- the values keyed by parameter names used in
the query string.public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
protected void doOpen() throws java.lang.Exception
AbstractItemCountingItemStreamItemReader
doOpen
in class AbstractItemCountingItemStreamItemReader<T>
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkprotected T doRead()
AbstractItemCountingItemStreamItemReader
doRead
in class AbstractItemCountingItemStreamItemReader<T>
null
if the data source is exhaustedpublic void update(ExecutionContext executionContext) throws ItemStreamException
ItemStreamSupport
ExecutionContext
.update
in interface ItemStream
update
in class AbstractItemCountingItemStreamItemReader<T>
executionContext
- to be updatedItemStreamException
ItemStream.update(ExecutionContext)
protected void doClose()
AbstractItemCountingItemStreamItemReader
AbstractItemCountingItemStreamItemReader.doOpen()
.doClose
in class AbstractItemCountingItemStreamItemReader<T>