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

COVERAGE SUMMARY FOR SOURCE FILE [Neo4jItemWriter.java]

nameclass, %method, %block, %line, %
Neo4jItemWriter.java100% (1/1)100% (7/7)100% (68/68)100% (21/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Neo4jItemWriter100% (1/1)100% (7/7)100% (68/68)100% (21/21)
<static initializer> 100% (1/1)100% (4/4)100% (2/2)
Neo4jItemWriter (): void 100% (1/1)100% (6/6)100% (2/2)
afterPropertiesSet (): void 100% (1/1)100% (9/9)100% (2/2)
doWrite (List): void 100% (1/1)100% (34/34)100% (8/8)
setDelete (boolean): void 100% (1/1)100% (4/4)100% (2/2)
setTemplate (Neo4jOperations): void 100% (1/1)100% (4/4)100% (2/2)
write (List): void 100% (1/1)100% (7/7)100% (3/3)

1/*
2 * Copyright 2012 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17package org.springframework.batch.item.data;
18 
19import java.util.List;
20 
21import org.apache.commons.logging.Log;
22import org.apache.commons.logging.LogFactory;
23import org.springframework.batch.item.ItemWriter;
24import org.springframework.beans.factory.InitializingBean;
25import org.springframework.data.neo4j.template.Neo4jOperations;
26import org.springframework.util.Assert;
27import org.springframework.util.CollectionUtils;
28 
29/**
30 * <p>
31 * A {@link ItemWriter} implementation that writes to a Neo4j database using an
32 * implementation of Spring Data's {@link Neo4jOperations}.
33 * </p>
34 *
35 * <p>
36 * This writer is thread safe once all properties are set (normal singleton
37 * behavior) so it can be used in multiple concurrent transactions.
38 * </p>
39 *
40 * @author Michael Minella
41 *
42 */
43public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
44 
45        protected static final Log logger = LogFactory
46                        .getLog(Neo4jItemWriter.class);
47 
48        private boolean delete = false;
49 
50        private Neo4jOperations template;
51 
52        public void setDelete(boolean delete) {
53                this.delete = delete;
54        }
55 
56        /**
57         * Set the {@link Neo4jOperations} to be used to save items
58         *
59         * @param template the template implementation to be used
60         */
61        public void setTemplate(Neo4jOperations template) {
62                this.template = template;
63        }
64 
65        /**
66         * Checks mandatory properties
67         *
68         * @see InitializingBean#afterPropertiesSet()
69         */
70        public void afterPropertiesSet() throws Exception {
71                Assert.state(template != null, "A Neo4JOperations implementation is required");
72        }
73 
74        /**
75         * Write all items to the data store.
76         *
77         * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
78         */
79        public void write(List<? extends T> items) throws Exception {
80                if(!CollectionUtils.isEmpty(items)) {
81                        doWrite(items);
82                }
83        }
84 
85        /**
86         * Performs the actual write using the template.  This can be overriden by
87         * a subclass if necessary.
88         *
89         * @param items the list of items to be persisted.
90         */
91        protected void doWrite(List<? extends T> items) {
92                if(delete) {
93                        for (T t : items) {
94                                template.delete(t);
95                        }
96                }
97                else {
98                        for (T t : items) {
99                                template.save(t);
100                        }
101                }
102        }
103}

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