类 HibernateCursorItemReader<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.HibernateCursorItemReader<T>
- 所有已实现的接口:
ItemReader<T>
,ItemStream
,ItemStreamReader<T>
,org.springframework.beans.factory.InitializingBean
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 asAbstractItemCountingItemStreamItemReader.read()
method is called, returning an object corresponding to current row. 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
The implementation is not thread-safe.StatelessSession
sufficient for simple mappings without the need to cascade to associated objects or standard hibernateSession
for more advanced mappings or when caching is desired. When stateful session is used it will be cleared in theupdate(ExecutionContext)
method without being flushed (no data modifications are expected).- 作者:
- Robert Kasanicky, Dave Syer
构造器概要
构造器 构造器 说明 HibernateCursorItemReader()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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(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<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.void
update(ExecutionContext executionContext)
Update the context and clear the session if stateful.从类继承的方法 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, read, setCurrentItemCount, setMaxItemCount, setSaveState
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
构造器详细资料
HibernateCursorItemReader
public HibernateCursorItemReader()
方法详细资料
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
java.lang.Exception
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).- 参数:
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 string
or the {query provider
should be set.- 参数:
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.- 参数:
fetchSize
- the fetch size to pass down to Hibernate
setQueryProvider
public void setQueryProvider(HibernateQueryProvider<T> queryProvider)
A query provider. Either this or the {query string
or the {query name
should be set.- 参数:
queryProvider
- Hibernate query provider
setQueryString
public void setQueryString(java.lang.String queryString)
A query string in HQL. Either this or the {query provider
or the {query name
should be set.- 参数:
queryString
- HQL query string
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
The Hibernate SessionFactory to use the create a session.- 参数:
sessionFactory
- theSessionFactory
to set
setUseStatelessSession
public void setUseStatelessSession(boolean useStatelessSession)
Can be set only in uninitialized state.- 参数:
useStatelessSession
-true
to useStatelessSession
false
to use standard hibernateSession
doRead
protected T doRead() throws java.lang.Exception
Read next item from input.- 指定者:
doRead
在类中AbstractItemCountingItemStreamItemReader<T>
- 返回:
- an item or
null
if the data source is exhausted - 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
doOpen
protected void doOpen() throws java.lang.Exception
Open hibernate session and create a forward-only cursor for the query.- 指定者:
doOpen
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework
update
public void update(ExecutionContext executionContext) throws ItemStreamException
Update the context and clear the session if stateful.- 指定者:
update
在接口中ItemStream
- 覆盖:
update
在类中AbstractItemCountingItemStreamItemReader<T>
- 参数:
executionContext
- the currentExecutionContext
- 抛出:
ItemStreamException
- if there is a problem- 另请参阅:
ItemStream.update(ExecutionContext)
jumpToItem
protected void jumpToItem(int itemIndex) throws java.lang.Exception
Wind forward through the result set to the item requested. Also clears the session every now and then (if stateful) to avoid memory problems. The frequency of session clearing is the larger of the fetch size (if set) and 100.- 覆盖:
jumpToItem
在类中AbstractItemCountingItemStreamItemReader<T>
- 参数:
itemIndex
- the first item to read- 抛出:
java.lang.Exception
- if there is a problem- 另请参阅:
AbstractItemCountingItemStreamItemReader.jumpToItem(int)
doClose
protected void doClose() throws java.lang.Exception
Close the cursor and hibernate session.- 指定者:
doClose
在类中AbstractItemCountingItemStreamItemReader<T>
- 抛出:
java.lang.Exception
- Allows subclasses to throw checked exceptions for interpretation by the framework