EMMA Coverage Report (generated Thu May 22 12:08:10 CDT 2014)
[all classes][org.springframework.batch.item]

COVERAGE SUMMARY FOR SOURCE FILE [KeyValueItemWriter.java]

nameclass, %method, %block, %line, %
KeyValueItemWriter.java100% (1/1)100% (5/5)100% (41/41)100% (15/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class KeyValueItemWriter100% (1/1)100% (5/5)100% (41/41)100% (15/15)
KeyValueItemWriter (): void 100% (1/1)100% (3/3)100% (1/1)
afterPropertiesSet (): void 100% (1/1)100% (7/7)100% (3/3)
setDelete (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setItemKeyMapper (Converter): void 100% (1/1)100% (4/4)100% (2/2)
write (List): void 100% (1/1)100% (23/23)100% (7/7)

1/*
2 * Copyright 2002-2013 the original author or authors.
3 * 
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
6 * 
7 * http://www.apache.org/licenses/LICENSE-2.0
8 * 
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
12 */
13package org.springframework.batch.item;
14 
15import java.util.List;
16 
17import org.springframework.beans.factory.InitializingBean;
18import org.springframework.core.convert.converter.Converter;
19import org.springframework.util.Assert;
20 
21/**
22 * A base class to implement any {@link ItemWriter} that writes to a key value store 
23 * using a {@link Converter} to derive a key from an item
24 * 
25 * @author David Turanski
26 * @since 2.2
27 *
28 */
29public abstract class KeyValueItemWriter<K, V> implements ItemWriter<V>, InitializingBean {
30 
31        protected Converter<V, K> itemKeyMapper;
32        protected boolean delete;
33 
34        /* (non-Javadoc)
35         * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
36         */
37        @Override
38        public void write(List<? extends V> items) throws Exception {
39                if (items == null) {
40                        return;
41                }
42                for (V item : items) {
43                        K key = itemKeyMapper.convert(item);
44                        writeKeyValue(key, item);
45                }
46        }
47 
48        /**
49         * Subclasses implement this method to write each item to key value store
50         * @param key the key
51         * @param value the item
52         */
53        protected abstract void writeKeyValue(K key, V value);
54 
55        /**
56         * afterPropertiesSet() hook
57         */
58        protected abstract void init();
59 
60        /**
61         * Set the {@link Converter} to use to derive the key from the item
62         * @param itemKeyMapper
63         */
64        public void setItemKeyMapper(Converter<V, K> itemKeyMapper) {
65                this.itemKeyMapper = itemKeyMapper;
66        }
67 
68        /**
69         * Sets the delete flag to have the item writer perform deletes
70         * @param delete
71         */
72        public void setDelete(boolean delete) {
73                this.delete = delete;
74        }
75 
76        /* (non-Javadoc)
77         * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
78         */
79        @Override
80        public void afterPropertiesSet() throws Exception {
81                Assert.notNull(itemKeyMapper, "itemKeyMapper requires a Converter type.");
82                init();
83        }
84}

[all classes][org.springframework.batch.item]
EMMA 2.0.5312 (C) Vladimir Roubtsov