class KeyValueItemWriter<K, V> implements ItemWriter<V>, InitializingBean {

	protected Converter<V, K> itemKeyMapper;

	protected boolean delete;

	@Override
	public void write(Chunk<? extends V> items) throws Exception {
		if (items == null) {
			return;
		}
		for (V item : items) {
			K key = itemKeyMapper.convert(item);
			writeKeyValue(key, item);
		}
		flush();
	}

	/**
	 * Flush items to the key/value store.
	 * @throws Exception if unable to flush items
	 */
	protected void flush() throws Exception {
	}

	/**
	 * Subclasses implement this method to write each item to key value store
	 * @param key the key
	 * @param value the item
	 */
	protected abstract void writeKeyValue(K key, V value);

	/**
	 * afterPropertiesSet() hook
	 */
	protected abstract void init();

	/**
	 * Set the {@link Converter} to use to derive the key from the item
	 * @param itemKeyMapper the {@link Converter} used to derive a key from an item.
	 */
	public void setItemKeyMapper(Converter<V, K> itemKeyMapper) {
		this.itemKeyMapper = itemKeyMapper;
	}

	/**
	 * Sets the delete flag to have the item writer perform deletes
	 * @param delete if true {@link ItemWriter} will perform deletes, if false not to
	 * perform deletes.
	 */
	public void setDelete(boolean delete) {
		this.delete = delete;
	}

	@Override
	public void afterPropertiesSet() throws Exception {<FILL_FUNCTION_BODY>}

}

		Assert.state(itemKeyMapper != null, "itemKeyMapper requires a Converter type.");
		init();
	
<no_super_class>