类 JpaPagingItemReader<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.AbstractPagingItemReader<T>
- org.springframework.batch.item.database.JpaPagingItemReader<T>
- 所有已实现的接口:
ItemReader<T>
,ItemStream
,ItemStreamReader<T>
,org.springframework.beans.factory.InitializingBean
public class JpaPagingItemReader<T> extends AbstractPagingItemReader<T>
ItemReader
for reading database records built on top of JPA.It executes the JPQL
setQueryString(String)
to retrieve requested data. The query is executed using paged requests of a size specified inAbstractPagingItemReader.setPageSize(int)
. Additional pages are requested when needed asAbstractItemCountingItemStreamItemReader.read()
method is called, returning an object corresponding to current position.The performance of the paging depends on the JPA implementation and its use of database specific features to limit the number of returned rows.
Setting a fairly large page size and using a commit interval that matches the page size should provide better performance.
In order to reduce the memory usage for large results the persistence context is flushed and cleared after each page is read. This causes any entities read to be detached. If you make changes to the entities and want the changes persisted then you must explicitly merge the entities.
The reader must be configured with an
EntityManagerFactory
. All entity access is performed within a new transaction, independent of any existing Spring managed transactions.The implementation is thread-safe in between calls to
AbstractItemCountingItemStreamItemReader.open(ExecutionContext)
, but remember to usesaveState=false
if used in a multi-threaded client (no restart available).- 从以下版本开始:
- 2.0
- 作者:
- Thomas Risberg, Dave Syer, Will Schipp
字段概要
从类继承的字段 org.springframework.batch.item.database.AbstractPagingItemReader
logger, results
构造器概要
构造器 构造器 说明 JpaPagingItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Check mandatory properties.protected void
doClose()
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.protected void
doJumpToPage(int itemIndex)
protected void
doOpen()
Open resources necessary to start reading input.protected void
doReadPage()
void
setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
void
setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
The parameter values to be used for the query execution.void
setQueryProvider(JpaQueryProvider queryProvider)
void
setQueryString(java.lang.String queryString)
void
setTransacted(boolean transacted)
By default (true) the EntityTransaction will be started and committed around the read.从类继承的方法 org.springframework.batch.item.database.AbstractPagingItemReader
doRead, getPage, getPageSize, jumpToItem, setPageSize
从类继承的方法 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
构造器详细资料
JpaPagingItemReader
public JpaPagingItemReader()
方法详细资料
setEntityManagerFactory
public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
setParameterValues
public void setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
The parameter values to be used for the query execution.- 参数:
parameterValues
- the values keyed by the parameter named used in the query string.
setTransacted
public void setTransacted(boolean transacted)
By default (true) the EntityTransaction will be started and committed around the read. Can be overridden (false) in cases where the JPA implementation doesn't support a particular transaction. (e.g. Hibernate with a JTA transaction). NOTE: may cause problems in guaranteeing the object consistency in the EntityManagerFactory.- 参数:
transacted
- indicator
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
从类复制的说明:AbstractPagingItemReader
Check mandatory properties.- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 覆盖:
afterPropertiesSet
在类中AbstractPagingItemReader<T>
- 抛出:
java.lang.Exception
- 另请参阅:
InitializingBean.afterPropertiesSet()
setQueryString
public void setQueryString(java.lang.String queryString)
- 参数:
queryString
- JPQL query string
setQueryProvider
public void setQueryProvider(JpaQueryProvider queryProvider)
- 参数:
queryProvider
- JPA query provider
doOpen
protected void doOpen() throws java.lang.Exception
Open resources necessary to start reading input.- 覆盖:
doOpen
在类中AbstractPagingItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doReadPage
protected void doReadPage()
- 指定者:
doReadPage
在类中AbstractPagingItemReader<T>
doJumpToPage
protected void doJumpToPage(int itemIndex)
- 指定者:
doJumpToPage
在类中AbstractPagingItemReader<T>
doClose
protected void doClose() throws java.lang.Exception
Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen()
.- 覆盖:
doClose
在类中AbstractPagingItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework