public class HibernatePagingItemReader<T> extends AbstractPagingItemReader<T> implements org.springframework.beans.factory.InitializingBean
ItemReader
for 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 the AbstractItemCountingItemStreamItemReader.read()
method is called. The
query can be set directly using setQueryString(String)
, a named
query can be used by setQueryName(String)
, or a query provider
strategy can be supplied via
setQueryProvider(HibernateQueryProvider)
.
The reader can be configured to use either StatelessSession
sufficient for simple mappings without the need to cascade to associated
objects or standard hibernate Session
for more advanced mappings or
when caching is desired. When stateful session is used it will be cleared in
the AbstractItemCountingItemStreamItemReader.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 use
saveState=false
if used in a multi-threaded client (no restart
available).
logger, results
Constructor and Description |
---|
HibernatePagingItemReader() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Check mandatory properties.
|
protected void |
doClose()
Close the resources opened in
AbstractItemCountingItemStreamItemReader.doOpen() . |
protected void |
doJumpToPage(int itemIndex) |
protected void |
doOpen()
Open resources necessary to start reading input.
|
protected void |
doReadPage() |
void |
setFetchSize(int fetchSize)
Fetch size used internally by Hibernate to limit amount of data fetched
from database per round trip.
|
void |
setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
The parameter values to apply to a query (map of name:value).
|
void |
setQueryName(java.lang.String queryName)
A query name for an externalized query.
|
void |
setQueryProvider(HibernateQueryProvider<? extends T> queryProvider)
A query provider.
|
void |
setQueryString(java.lang.String queryString)
A query string in HQL.
|
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
The Hibernate SessionFactory to use the create a session.
|
void |
setUseStatelessSession(boolean useStatelessSession)
Can be set only in uninitialized state.
|
doRead, getPage, getPageSize, jumpToItem, setPageSize
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState, update
getExecutionContextKey, getName, setExecutionContextName, setName
public void setParameterValues(java.util.Map<java.lang.String,java.lang.Object> parameterValues)
parameterValues
- the parameter values to setpublic void setQueryName(java.lang.String queryName)
query string
or the {
query provider
should
be set.queryName
- name of a hibernate named querypublic void setFetchSize(int fetchSize)
fetchSize
- the fetch size to pass down to Hibernatepublic void setQueryProvider(HibernateQueryProvider<? extends T> queryProvider)
query string
or the {query name
should be
set.queryProvider
- Hibernate query providerpublic void setQueryString(java.lang.String queryString)
query provider
or the {
query name
should be set.queryString
- HQL query stringpublic void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
sessionFactory
- the SessionFactory
to setpublic void setUseStatelessSession(boolean useStatelessSession)
useStatelessSession
- true
to use
StatelessSession
false
to use standard hibernate
Session
public void afterPropertiesSet() throws java.lang.Exception
AbstractPagingItemReader
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
in class AbstractPagingItemReader<T>
java.lang.Exception
InitializingBean.afterPropertiesSet()
protected void doOpen() throws java.lang.Exception
AbstractItemCountingItemStreamItemReader
doOpen
in class AbstractPagingItemReader<T>
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the frameworkprotected void doReadPage()
doReadPage
in class AbstractPagingItemReader<T>
protected void doJumpToPage(int itemIndex)
doJumpToPage
in class AbstractPagingItemReader<T>
protected void doClose() throws java.lang.Exception
AbstractItemCountingItemStreamItemReader
AbstractItemCountingItemStreamItemReader.doOpen()
.doClose
in class AbstractPagingItemReader<T>
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework