public class HibernateCursorItemReader<T> extends AbstractItemCountingItemStreamItemReader<T> implements org.springframework.beans.factory.InitializingBean
ItemStreamReader for reading database records built on top of Hibernate. It
executes the HQL query when initialized iterates over the result set as
AbstractItemCountingItemStreamItemReader.read() method is called, returning an object corresponding to
current row. 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 update(ExecutionContext) method without being flushed (no data
modifications are expected).
| Constructor and Description |
|---|
HibernateCursorItemReader() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected void |
doClose()
Close the cursor and hibernate session.
|
protected void |
doOpen()
Open hibernate session and create a forward-only cursor for the query.
|
protected T |
doRead()
Read next item from input.
|
protected void |
jumpToItem(int itemIndex)
Wind forward through the result set to the item requested.
|
void |
setFetchSize(int fetchSize)
Fetch size used internally by Hibernate to limit amount of data fetched
from database per round trip.
|
void |
setParameterValues(Map<String,Object> parameterValues)
The parameter values to apply to a query (map of name:value).
|
void |
setQueryName(String queryName)
A query name for an externalized query.
|
void |
setQueryProvider(HibernateQueryProvider queryProvider)
A query provider.
|
void |
setQueryString(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.
|
void |
update(ExecutionContext executionContext)
Update the context and clear the session if stateful.
|
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveStategetExecutionContextKey, setExecutionContextName, setNamepublic void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic void setParameterValues(Map<String,Object> parameterValues)
parameterValues - the parameter values to setpublic void setQueryName(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 queryProvider)
query string or the {query name should be
set.queryProvider - Hibernate query providerpublic void setQueryString(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
Sessionprotected T doRead() throws Exception
AbstractItemCountingItemStreamItemReaderdoRead in class AbstractItemCountingItemStreamItemReader<T>Exceptionprotected void doOpen()
throws Exception
doOpen in class AbstractItemCountingItemStreamItemReader<T>Exceptionpublic void update(ExecutionContext executionContext) throws ItemStreamException
update in interface ItemStreamupdate in class AbstractItemCountingItemStreamItemReader<T>executionContext - the current ExecutionContextItemStreamException - if there is a problemItemStream.update(ExecutionContext)protected void jumpToItem(int itemIndex)
throws Exception
jumpToItem in class AbstractItemCountingItemStreamItemReader<T>itemIndex - the first item to readException - if there is a problemAbstractItemCountingItemStreamItemReader.jumpToItem(int)protected void doClose()
throws Exception
doClose in class AbstractItemCountingItemStreamItemReader<T>ExceptionCopyright © 2014 Pivotal. All rights reserved.