Class KeyValueItemWriter<K,V>
java.lang.Object
org.springframework.batch.infrastructure.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. If a derived key is null, the item
will be skipped and a warning logged.- Since:
- 2.2
- Author:
- David Turanski, Mahmoud Ben Hassine, Stefano Cordio
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean -
Constructor Summary
ConstructorsConstructorDescriptionKeyValueItemWriter(org.springframework.core.convert.converter.Converter<V, K> itemKeyMapper) Create a newKeyValueItemWriterinstance. -
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
Create a newKeyValueItemWriterinstance.- Parameters:
itemKeyMapper- theConverterused to derive a key from an item.- Since:
- 6.0
-
-
Method Details
-
write
Description copied from interface:ItemWriterProcess the supplied data element. Will not be called with any null items in normal operation but might be called with an empty chunk, for example when all items have been filtered by anItemProcessoror skipped by the fault-tolerant step processing. Implementations are expected to handle empty chunks gracefully.- Specified by:
writein interfaceItemWriter<K>- Parameters:
chunk- of items to be written. Nevernullbut may be empty.- Throws:
Exception- if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.
-
flush
-
writeKeyValue
-
init
protected abstract void init()afterPropertiesSet() hook -
setItemKeyMapper
-
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
-