Class HibernatePagingItemReader<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.HibernatePagingItemReader<T>
- All Implemented Interfaces:
ItemReader<T>,ItemStream,ItemStreamReader<T>,org.springframework.beans.factory.InitializingBean
public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> implements org.springframework.beans.factory.InitializingBean
ItemReaderfor reading database records built on top of Hibernate and reading only up to a fixed number of items at a time. It executes an HQL query when initialized is paged as theAbstractItemCountingItemStreamItemReader.read()method is called. The query can be set directly usingsetQueryString(String), a named query can be used bysetQueryName(String), or a query provider strategy can be supplied viasetQueryProvider(HibernateQueryProvider).The reader can be configured to use either
StatelessSessionsufficient for simple mappings without the need to cascade to associated objects or standard hibernateSessionfor more advanced mappings or when caching is desired. When stateful session is used it will be cleared in theAbstractItemCountingItemStreamItemReader.update(ExecutionContext)method without being flushed (no data modifications are expected).The implementation is thread-safe in between calls to
AbstractItemCountingItemStreamItemReader.open(ExecutionContext), but remember to usesaveState=falseif used in a multi-threaded client (no restart available).- Since:
- 2.1
- Author:
- Dave Syer
Field Summary
Fields inherited from class org.springframework.batch.item.database.AbstractPagingItemReader
logger, results
Constructor Summary
Constructors Constructor Description HibernatePagingItemReader()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Check mandatory properties.protected voiddoClose()Close the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().protected voiddoJumpToPage(int itemIndex)protected voiddoOpen()Open resources necessary to start reading input.protected voiddoReadPage()voidsetFetchSize(int fetchSize)Fetch size used internally by Hibernate to limit amount of data fetched from database per round trip.voidsetParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)The parameter values to apply to a query (map of name:value).voidsetQueryName(java.lang.String queryName)A query name for an externalized query.voidsetQueryProvider(HibernateQueryProvider<? extends T> queryProvider)A query provider.voidsetQueryString(java.lang.String queryString)A query string in HQL.voidsetSessionFactory(org.hibernate.SessionFactory sessionFactory)The Hibernate SessionFactory to use the create a session.voidsetUseStatelessSession(boolean useStatelessSession)Can be set only in uninitialized state.Methods inherited from class org.springframework.batch.item.database.AbstractPagingItemReader
doRead, getPage, getPageSize, jumpToItem, setPageSize
Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
Methods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
Method Detail
setParameterValues
public void setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
The parameter values to apply to a query (map of name:value).- Parameters:
parameterValues- the parameter values to set
setQueryName
public void setQueryName(java.lang.String queryName)
A query name for an externalized query. Either this or the {query stringor the {query providershould be set.- Parameters:
queryName- name of a hibernate named query
setFetchSize
public void setFetchSize(int fetchSize)
Fetch size used internally by Hibernate to limit amount of data fetched from database per round trip.- Parameters:
fetchSize- the fetch size to pass down to Hibernate
setQueryProvider
public void setQueryProvider(HibernateQueryProvider<? extends T> queryProvider)
A query provider. Either this or the {query stringor the {query nameshould be set.- Parameters:
queryProvider- Hibernate query provider
setQueryString
public void setQueryString(java.lang.String queryString)
A query string in HQL. Either this or the {query provideror the {query nameshould be set.- Parameters:
queryString- HQL query string
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
The Hibernate SessionFactory to use the create a session.- Parameters:
sessionFactory- theSessionFactoryto set
setUseStatelessSession
public void setUseStatelessSession(boolean useStatelessSession)
Can be set only in uninitialized state.- Parameters:
useStatelessSession-trueto useStatelessSessionfalseto use standard hibernateSession
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.ExceptionDescription copied from class:AbstractPagingItemReaderCheck mandatory properties.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classAbstractPagingItemReader<T>- Throws:
java.lang.Exception- See Also:
InitializingBean.afterPropertiesSet()
doOpen
protected void doOpen() throws java.lang.ExceptionDescription copied from class:AbstractItemCountingItemStreamItemReaderOpen resources necessary to start reading input.- Overrides:
doOpenin classAbstractPagingItemReader<T>- Throws:
java.lang.Exception- Allows subclasses to throw checked exceptions for interpretation by the framework
doReadPage
protected void doReadPage()
- Specified by:
doReadPagein classAbstractPagingItemReader<T>
doJumpToPage
protected void doJumpToPage(int itemIndex)
- Specified by:
doJumpToPagein classAbstractPagingItemReader<T>
doClose
protected void doClose() throws java.lang.ExceptionDescription copied from class:AbstractItemCountingItemStreamItemReaderClose the resources opened inAbstractItemCountingItemStreamItemReader.doOpen().- Overrides:
doClosein classAbstractPagingItemReader<T>- Throws:
java.lang.Exception- Allows subclasses to throw checked exceptions for interpretation by the framework