org.springframework.batch.item

## Class KeyValueItemWriter<K,V>

- java.lang.Object
- - org.springframework.batch.item.KeyValueItemWriter<K,V>

- All Implemented Interfaces:
    ItemWriter<V>, org.springframework.beans.factory.InitializingBean
  Direct Known Subclasses:
    GemfireItemWriter

      public abstract class KeyValueItemWriter<K,V>
      extends java.lang.Object
      implements ItemWriter<V>, org.springframework.beans.factory.InitializingBean

  A base class to implement any `ItemWriter` that writes to a key value store using a `Converter` to derive a key from an item
  Since:
    2.2
  Author:
    David Turanski

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `delete`
    `protected org.springframework.core.convert.converter.Converter<V,K>` | `itemKeyMapper`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `KeyValueItemWriter()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()`
    `protected abstract void` | `init()` afterPropertiesSet() hook
    `void` | `setDelete(boolean delete)` Sets the delete flag to have the item writer perform deletes
    `void` | `setItemKeyMapper(org.springframework.core.convert.converter.Converter<V,K> itemKeyMapper)` Set the `Converter` to use to derive the key from the item
    `void` | `write(java.util.List<? extends V> items)` Process the supplied data element.
    `protected abstract void` | `writeKeyValue(K key, V value)` Subclasses implement this method to write each item to key value store

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### itemKeyMapper

          protected org.springframework.core.convert.converter.Converter<V,K> itemKeyMapper

    - #### delete

          protected boolean delete

  - ### Constructor Detail

    - #### KeyValueItemWriter

          public KeyValueItemWriter()

  - ### Method Detail

    - #### write

          public void write(java.util.List<? extends V> items)
                     throws java.lang.Exception

      Description copied from interface: `ItemWriter`
      Process the supplied data element. Will not be called with any null items in normal operation.
      Specified by:
        `write` in interface `ItemWriter<V>`
      Parameters:
        `items` - items to be written
      Throws:
        `java.lang.Exception` - if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.

    - #### writeKeyValue

          protected abstract void writeKeyValue(K key,
                                                V value)

      Subclasses implement this method to write each item to key value store
      Parameters:
        `key` - the key
        `value` - the item

    - #### init

          protected abstract void init()

      afterPropertiesSet() hook

    - #### setItemKeyMapper

          public void setItemKeyMapper(org.springframework.core.convert.converter.Converter<V,K> itemKeyMapper)

      Set the `Converter` to use to derive the key from the item
      Parameters:
        `itemKeyMapper` -

    - #### setDelete

          public void setDelete(boolean delete)

      Sets the delete flag to have the item writer perform deletes
      Parameters:
        `delete` -

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`