public class JpaItemWriter<T> extends java.lang.Object implements ItemWriter<T>, org.springframework.beans.factory.InitializingBean
ItemWriter that is using a JPA
EntityManagerFactory to merge any Entities that aren't part of the
persistence context.
It is required that write(List) is called inside a transaction.EntityManagerFactory that is capable of
participating in Spring managed transactions.
The writer is thread-safe after its properties are set (normal singleton
behaviour), so it can be used to write in multiple concurrent transactions.| Modifier and Type | Field and Description |
|---|---|
protected static org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
JpaItemWriter() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Check mandatory properties - there must be an entityManagerFactory.
|
protected void |
doWrite(javax.persistence.EntityManager entityManager,
java.util.List<? extends T> items)
Do perform the actual write operation.
|
void |
setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
Set the EntityManager to be used internally.
|
void |
write(java.util.List<? extends T> items)
Merge all provided items that aren't already in the persistence context
and then flush the entity manager.
|
public void setEntityManagerFactory(javax.persistence.EntityManagerFactory entityManagerFactory)
entityManagerFactory - the entityManagerFactory to setpublic void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exceptionpublic void write(java.util.List<? extends T> items)
write in interface ItemWriter<T>items - items to be writtenItemWriter.write(java.util.List)protected void doWrite(javax.persistence.EntityManager entityManager,
java.util.List<? extends T> items)
entityManager - the EntityManager to use for the operationitems - the list of items to use for the write