Class JpaBulkItemWriter<T>

java.lang.Object
com.ecom.winners.writers.JpaBulkItemWriter<T>
Type Parameters:
T - an entity
All Implemented Interfaces:
org.springframework.batch.item.ItemWriter<List<T>>, org.springframework.beans.factory.InitializingBean

public class JpaBulkItemWriter<T> extends Object implements org.springframework.batch.item.ItemWriter<List<T>>, org.springframework.beans.factory.InitializingBean
JPA bulk item writer is an ItemWriter for the bulk writes of Spring Data JPA. It's somehow a chunk bulk writer
See Also:
  • JpaItemWriter
  • Constructor Details

    • JpaBulkItemWriter

      public JpaBulkItemWriter()
  • Method Details

    • setEntityManagerFactory

      public void setEntityManagerFactory (jakarta.persistence.EntityManagerFactory entityManagerFactory)
    • setUsePersist

      public void setUsePersist (boolean usePersist)
    • afterPropertiesSet

      public void afterPropertiesSet()
      Asserts the state of entity manager property.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • write

      public void write (org.springframework.batch.item.Chunk<? extends List<T>> listOfItems)
      It's a wrapper around doWrite. It takes the transaction from entity manager and checks the existence of it then raise a DataAccessResourceFailure exception if the connection does not exist. If all goes well, it persists the list of items into the database.
      Specified by:
      write in interface org.springframework.batch.item.ItemWriter<T>
      Parameters:
      listOfItems - a chunk of items as List of generic T