Package 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:
KafkaItemWriter,RedisItemWriter
public abstract class KeyValueItemWriter<K,V>
extends 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, Mahmoud Ben Hassine
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidflush()Flush items to the key/value store.protected abstract voidinit()afterPropertiesSet() hookvoidsetDelete(boolean delete) Sets the delete flag to have the item writer perform deletesvoidsetItemKeyMapper(org.springframework.core.convert.converter.Converter<V, K> itemKeyMapper) Set theConverterto use to derive the key from the itemvoidProcess the supplied data element.protected abstract voidwriteKeyValue(K key, V value) Subclasses implement this method to write each item to key value store
-
Field Details
-
itemKeyMapper
-
delete
protected boolean delete
-
-
Constructor Details
-
KeyValueItemWriter
public KeyValueItemWriter()
-
-
Method Details
-
write
Description copied from interface:ItemWriterProcess the supplied data element. Will not be called with any null items in normal operation.- Specified by:
writein interfaceItemWriter<K>- Parameters:
items- of items to be written. Must not benull.- Throws:
Exception- if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.
-
flush
Flush items to the key/value store.- Throws:
Exception- if unable to flush items
-
writeKeyValue
Subclasses implement this method to write each item to key value store- Parameters:
key- the keyvalue- the item
-
init
protected abstract void init()afterPropertiesSet() hook -
setItemKeyMapper
public void setItemKeyMapper(org.springframework.core.convert.converter.Converter<V, K> itemKeyMapper) Set theConverterto use to derive the key from the item- Parameters:
itemKeyMapper- theConverterused to derive a key from an item.
-
setDelete
public void setDelete(boolean delete) Sets the delete flag to have the item writer perform deletes- Parameters:
delete- if trueItemWriterwill perform deletes, if false not to perform deletes.
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-