Class HibernateItemReaderHelper<T>
- java.lang.Object
- org.springframework.batch.item.database.HibernateItemReaderHelper<T>
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
public class HibernateItemReaderHelper<T> extends java.lang.Object implements org.springframework.beans.factory.InitializingBean
Internal shared state helper for hibernate readers managing sessions and queries.- Author:
- Dave Syer
Constructor Summary
Constructors Constructor Description HibernateItemReaderHelper()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
void
clear()
Clear the session if stateful.void
close()
Close the open session (stateful or otherwise).org.hibernate.Query
createQuery()
Open appropriate type of hibernate session and create the query.org.hibernate.ScrollableResults
getForwardOnlyCursor(int fetchSize, java.util.Map<java.lang.String,java.lang.Object> parameterValues)
Get a cursor over all of the results, with the forward-only flag set.void
jumpToItem(org.hibernate.ScrollableResults cursor, int itemIndex, int flushInterval)
Scroll through the results up to the item specified.java.util.Collection<? extends T>
readPage(int page, int pageSize, int fetchSize, java.util.Map<java.lang.String,java.lang.Object> parameterValues)
Read a page of data, clearing the existing session (if necessary) first, and creating a new session before executing the query.void
setQueryName(java.lang.String queryName)
void
setQueryProvider(HibernateQueryProvider<? extends T> queryProvider)
void
setQueryString(java.lang.String queryString)
void
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
void
setUseStatelessSession(boolean useStatelessSession)
Can be set only in uninitialized state.
Method Detail
setQueryName
public void setQueryName(java.lang.String queryName)
- Parameters:
queryName
- name of a hibernate named query
setQueryString
public void setQueryString(java.lang.String queryString)
- Parameters:
queryString
- HQL query string
setQueryProvider
public void setQueryProvider(HibernateQueryProvider<? extends T> queryProvider)
- Parameters:
queryProvider
- Hibernate query provider
setUseStatelessSession
public void setUseStatelessSession(boolean useStatelessSession)
Can be set only in uninitialized state.- Parameters:
useStatelessSession
-true
to useStatelessSession
false
to use standard hibernateSession
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
- Parameters:
sessionFactory
- hibernate session factory
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
java.lang.Exception
getForwardOnlyCursor
public org.hibernate.ScrollableResults getForwardOnlyCursor(int fetchSize, java.util.Map<java.lang.String,java.lang.Object> parameterValues)
Get a cursor over all of the results, with the forward-only flag set.- Parameters:
fetchSize
- the fetch size to use retrieving the resultsparameterValues
- the parameter values to use (or null if none).- Returns:
- a forward-only
ScrollableResults
createQuery
public org.hibernate.Query createQuery()
Open appropriate type of hibernate session and create the query.- Returns:
- a Hibernate Query
jumpToItem
public void jumpToItem(org.hibernate.ScrollableResults cursor, int itemIndex, int flushInterval)
Scroll through the results up to the item specified.- Parameters:
cursor
- the results to scroll overitemIndex
- index to scroll toflushInterval
- the number of items to scroll past before flushing
close
public void close()
Close the open session (stateful or otherwise).
readPage
public java.util.Collection<? extends T> readPage(int page, int pageSize, int fetchSize, java.util.Map<java.lang.String,java.lang.Object> parameterValues)
Read a page of data, clearing the existing session (if necessary) first, and creating a new session before executing the query.- Parameters:
page
- the page to read (starting at 0)pageSize
- the size of the page or maximum number of items to readfetchSize
- the fetch size to useparameterValues
- the parameter values to use (if any, otherwise null)- Returns:
- a collection of items
clear
public void clear()
Clear the session if stateful.