类 RepositoryItemWriter<T>

  • 所有已实现的接口:
    ItemWriter<T>, org.springframework.beans.factory.InitializingBean

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

    A ItemReader wrapper for a CrudRepository from Spring Data.

    It depends on CrudRepository.saveAll(Iterable) method to store the items for the chunk. Performance will be determined by that implementation more than this writer.

    As long as the repository provided is thread-safe, this writer is also thread-safe once properties are set (normal singleton behavior), so it can be used in multiple concurrent transactions.

    NOTE: The RepositoryItemWriter only stores Java Objects i.e. non primitives.

    从以下版本开始:
    2.2
    作者:
    Michael Minella, Mahmoud Ben Hassine
    • 字段概要

      字段 
      修饰符和类型字段说明
      protected static org.apache.commons.logging.Loglogger 
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型方法说明
      voidafterPropertiesSet()
      Check mandatory properties - there must be a repository.
      protected voiddoWrite​(java.util.List<? extends T> items)
      Performs the actual write to the repository.
      voidsetMethodName​(java.lang.String methodName)
      Specifies what method on the repository to call.
      voidsetRepository​(org.springframework.data.repository.CrudRepository<T,​?> repository)
      Set the CrudRepository implementation for persistence
      voidwrite​(java.util.List<? extends T> items)
      Write all items to the data store via a Spring Data repository.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • logger

        protected static final org.apache.commons.logging.Log logger
    • 方法详细资料

      • setMethodName

        public void setMethodName​(java.lang.String methodName)
        Specifies what method on the repository to call. This method must have the type of object passed to this writer as the sole argument.
        参数:
        methodName - String containing the method name.
      • setRepository

        public void setRepository​(org.springframework.data.repository.CrudRepository<T,​?> repository)
        Set the CrudRepository implementation for persistence
        参数:
        repository - the Spring Data repository to be set
      • write

        public void write​(java.util.List<? extends T> items)
                   throws java.lang.Exception
        Write all items to the data store via a Spring Data repository.
        指定者:
        write 在接口中 ItemWriter<T>
        参数:
        items - items to be written
        抛出:
        java.lang.Exception - if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.
        另请参阅:
        ItemWriter.write(java.util.List)
      • doWrite

        protected void doWrite​(java.util.List<? extends T> items)
                        throws java.lang.Exception
        Performs the actual write to the repository. This can be overridden by a subclass if necessary.
        参数:
        items - the list of items to be persisted.
        抛出:
        java.lang.Exception - thrown if error occurs during writing.
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Check mandatory properties - there must be a repository.
        指定者:
        afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBean
        抛出:
        java.lang.Exception