|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.batch.item.database.AbstractTransactionalResourceItemWriter org.springframework.batch.item.database.HibernateAwareItemWriter
public class HibernateAwareItemWriter
ItemWriter
that is aware of the Hibernate session and can take some
responsibilities to do with chunk boundaries away from a less smart
ItemWriter
(the delegate). A delegate is required, and will be used
to do the actual writing of the item.
It is expected that AbstractTransactionalResourceItemWriter.write(Object)
is called inside a transaction,
and that AbstractTransactionalResourceItemWriter.flush()
is then subsequently called before the transaction
commits, or AbstractTransactionalResourceItemWriter.clear()
before it rolls back.
The writer is thread safe after its properties are set (normal singleton
behaviour), so it can be used to write in multiple concurrent transactions.
Note, however, that the set of failed items is stored in a collection
internally, and this collection is never cleared, so it is not a great idea
to go on using the writer indefinitely. Normally it would be used for the
duration of a batch job and then discarded.
Constructor Summary | |
---|---|
HibernateAwareItemWriter()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Check mandatory properties - there must be a delegate and hibernateTemplate. |
protected void |
doClear()
Call the delegate clear() method, and then clear the hibernate session. |
protected void |
doFlush()
Delegate to subclass and flush the hibernate session. |
protected void |
doWrite(Object output)
Callback method of AbstractTransactionalResourceItemWriter.write(Object) . |
protected String |
getResourceKey()
|
void |
setDelegate(ItemWriter delegate)
Public setter for the ItemWriter property. |
void |
setHibernateTemplate(HibernateOperations hibernateTemplate)
Public setter for the HibernateOperations property. |
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the Hibernate SessionFactory to be used internally. |
Methods inherited from class org.springframework.batch.item.database.AbstractTransactionalResourceItemWriter |
---|
clear, flush, getProcessed, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HibernateAwareItemWriter()
Method Detail |
---|
public void setDelegate(ItemWriter delegate)
ItemWriter
property.
delegate
- the delegate to setpublic void setHibernateTemplate(HibernateOperations hibernateTemplate)
HibernateOperations
property.
hibernateTemplate
- the hibernateTemplate to setpublic final void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
setHibernateTemplate(org.springframework.orm.hibernate3.HibernateOperations)
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface InitializingBean
Exception
protected void doFlush()
doFlush
in class AbstractTransactionalResourceItemWriter
protected void doClear() throws ClearFailedException
doClear
in class AbstractTransactionalResourceItemWriter
ClearFailedException
protected String getResourceKey()
getResourceKey
in class AbstractTransactionalResourceItemWriter
RepeatContext
.protected void doWrite(Object output) throws Exception
AbstractTransactionalResourceItemWriter
AbstractTransactionalResourceItemWriter.write(Object)
.
doWrite
in class AbstractTransactionalResourceItemWriter
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |