类 MongoItemWriter<T>

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

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

    A ItemWriter implementation that writes to a MongoDB store using an implementation of Spring Data's MongoOperations. Since MongoDB is not a transactional store, a best effort is made to persist written data at the last moment, yet still honor job status contracts. No attempt to roll back is made if an error occurs during writing.

    This writer is thread-safe once all properties are set (normal singleton behavior) so it can be used in multiple concurrent transactions.

    作者:
    Michael Minella
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型方法说明
      voidafterPropertiesSet() 
      protected voiddoWrite​(java.util.List<? extends T> items)
      Performs the actual write to the store via the template.
      protected org.springframework.data.mongodb.core.MongoOperationsgetTemplate()
      Get the MongoOperations to be used to save items to be written.
      voidsetCollection​(java.lang.String collection)
      Set the name of the Mongo collection to be written to.
      voidsetDelete​(boolean delete)
      Indicates if the items being passed to the writer are to be saved or removed from the data store.
      voidsetTemplate​(org.springframework.data.mongodb.core.MongoOperations template)
      Set the MongoOperations to be used to save items to be written.
      voidwrite​(java.util.List<? extends T> items)
      If a transaction is active, buffer items to be written just before commit.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • setDelete

        public void setDelete​(boolean delete)
        Indicates if the items being passed to the writer are to be saved or removed from the data store. If set to false (default), the items will be saved. If set to true, the items will be removed.
        参数:
        delete - removal indicator
      • setTemplate

        public void setTemplate​(org.springframework.data.mongodb.core.MongoOperations template)
        Set the MongoOperations to be used to save items to be written.
        参数:
        template - the template implementation to be used.
      • getTemplate

        protected org.springframework.data.mongodb.core.MongoOperations getTemplate()
        Get the MongoOperations to be used to save items to be written. This can be called by a subclass if necessary.
        返回:
        template the template implementation to be used.
      • setCollection

        public void setCollection​(java.lang.String collection)
        Set the name of the Mongo collection to be written to.
        参数:
        collection - the name of the collection.
      • write

        public void write​(java.util.List<? extends T> items)
                   throws java.lang.Exception
        If a transaction is active, buffer items to be written just before commit. Otherwise write items using the provided template.
        指定者:
        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(List)
      • doWrite

        protected void doWrite​(java.util.List<? extends T> items)
        Performs the actual write to the store via the template. This can be overridden by a subclass if necessary.
        参数:
        items - the list of items to be persisted.
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        指定者:
        afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBean
        抛出:
        java.lang.Exception