org.springframework.batch.item.database
Class HibernateItemWriter<T>

java.lang.Object
  extended by org.springframework.batch.item.database.HibernateItemWriter<T>
All Implemented Interfaces:
ItemWriter<T>, org.springframework.beans.factory.InitializingBean

public class HibernateItemWriter<T>
extends Object
implements ItemWriter<T>, org.springframework.beans.factory.InitializingBean

ItemWriter that uses a Hibernate session to save or update entities that are not part of the current Hibernate session. It will also flush the session after writing (i.e. at chunk boundaries if used in a Spring Batch TaskletStep). It will also clear the session on write default (see clearSession property).

The writer is thread safe once properties are set (normal singleton behavior) if a CurrentSessionContext that uses only one session per thread is used.

Author:
Dave Syer, Thomas Risberg, Michael Minella

Field Summary
protected static org.apache.commons.logging.Log logger
           
 
Constructor Summary
HibernateItemWriter()
           
 
Method Summary
 void afterPropertiesSet()
          Check mandatory properties - there must be a hibernateTemplate.
protected  void doWrite(org.springframework.orm.hibernate3.HibernateOperations hibernateTemplate, List<? extends T> items)
          Deprecated. As of 2.2 in favor of using Hibernate's session management APIs directly
protected  void doWrite(org.hibernate.SessionFactory sessionFactory, List<? extends T> items)
          Deprecated. As of 2.2 in favor of using Hibernate's session management APIs directly
 void setClearSession(boolean clearSession)
          Flag to indicate that the session should be cleared and flushed at the end of the write (default true).
 void setHibernateTemplate(org.springframework.orm.hibernate3.HibernateOperations hibernateTemplate)
          Deprecated. As of 2.2 in favor of using Hibernate's session management APIs directly
 void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
          Set the Hibernate SessionFactory to be used internally.
 void write(List<? extends T> items)
          Save or update any entities not in the current hibernate session and then flush the hibernate session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.commons.logging.Log logger
Constructor Detail

HibernateItemWriter

public HibernateItemWriter()
Method Detail

setClearSession

public void setClearSession(boolean clearSession)
Flag to indicate that the session should be cleared and flushed at the end of the write (default true).

Parameters:
clearSession - the flag value to set

setHibernateTemplate

public void setHibernateTemplate(org.springframework.orm.hibernate3.HibernateOperations hibernateTemplate)
Deprecated. As of 2.2 in favor of using Hibernate's session management APIs directly

Public setter for the HibernateOperations property.

Parameters:
hibernateTemplate - the hibernateTemplate to set

setSessionFactory

public final void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the Hibernate SessionFactory to be used internally.

Parameters:
sessionFactory - session factory to be used by the writer

afterPropertiesSet

public void afterPropertiesSet()
Check mandatory properties - there must be a hibernateTemplate.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean

write

public final void write(List<? extends T> items)
Save or update any entities not in the current hibernate session and then flush the hibernate session.

Specified by:
write in interface ItemWriter<T>
See Also:
ItemWriter.write(java.util.List)

doWrite

protected void doWrite(org.hibernate.SessionFactory sessionFactory,
                       List<? extends T> items)
Deprecated. As of 2.2 in favor of using Hibernate's session management APIs directly

Do perform the actual write operation using Hibernate's API. This can be overridden in a subclass if necessary.

Parameters:
items - the list of items to use for the write

doWrite

protected void doWrite(org.springframework.orm.hibernate3.HibernateOperations hibernateTemplate,
                       List<? extends T> items)
Deprecated. As of 2.2 in favor of using Hibernate's session management APIs directly

Do perform the actual write operation using HibernateOperations. This can be overridden in a subclass if necessary.

Parameters:
hibernateTemplate - the HibernateTemplate to use for the operation
items - the list of items to use for the write


Copyright © 2013 SpringSource. All Rights Reserved.