public class JpaItemWriter<T> extends 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,
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(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 Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public void write(List<? extends T> items)
write
in interface ItemWriter<T>
ItemWriter.write(java.util.List)
protected void doWrite(javax.persistence.EntityManager entityManager, List<? extends T> items)
entityManager
- the EntityManager to use for the operationitems
- the list of items to use for the writeCopyright © 2014 Pivotal. All rights reserved.