|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.batch.item.ExecutionContextUserSupport
org.springframework.batch.item.database.HibernateCursorItemReader
public class HibernateCursorItemReader
ItemReader
for reading database records built on top of Hibernate.
It executes the HQL setQueryString(String)
when initialized and
iterates over the result set as read()
method is called, returning
an object corresponding to current row.
Input source 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 after successful commit
without being flushed (no inserts or updates are expected).
Constructor Summary | |
---|---|
HibernateCursorItemReader()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
|
void |
close(ExecutionContext executionContext)
Closes the result set cursor and hibernate session. |
void |
mark()
Mark is supported as long as this ItemStream is used in a
single-threaded environment. |
void |
open(ExecutionContext executionContext)
Creates cursor for the query. |
Object |
read()
Reads a piece of input data and advance to the next one. |
void |
reset()
Reset the stream to the last mark. |
void |
setQueryString(String queryString)
|
void |
setSaveState(boolean saveState)
|
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
|
void |
setUseStatelessSession(boolean useStatelessSession)
Can be set only in uninitialized state. |
void |
update(ExecutionContext executionContext)
Indicates that the execution context provided during open is about to be saved. |
Methods inherited from class org.springframework.batch.item.ExecutionContextUserSupport |
---|
getKey, setName |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HibernateCursorItemReader()
Method Detail |
---|
public Object read()
ItemReader
null
at the end of the input
data set. In a transactional setting, caller might get the same item
twice from successive calls (or otherwise), if the first call was in a
transaction that rolled back.
read
in interface ItemReader
public void close(ExecutionContext executionContext)
close
in interface ItemStream
executionContext
- TODOpublic void open(ExecutionContext executionContext)
open
in interface ItemStream
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
sessionFactory
- hibernate session factorypublic void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
public void setQueryString(String queryString)
queryString
- HQL query stringpublic void setUseStatelessSession(boolean useStatelessSession)
useStatelessSession
- true
to use
StatelessSession
false
to use standard hibernate
Session
public void update(ExecutionContext executionContext)
ItemStream
update
in interface ItemStream
executionContext
- to be updatedpublic void mark()
ItemStream
is used in a
single-threaded environment. The state backing the mark is a single
counter, keeping track of the current position, so multiple threads
cannot be accommodated.
mark
in interface ItemReader
ItemReader.mark()
public void reset()
ItemReader
reset
in interface ItemReader
public void setSaveState(boolean saveState)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |