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

COVERAGE SUMMARY FOR SOURCE FILE [JobBuilderHelper.java]

nameclass, %method, %block, %line, %
JobBuilderHelper.java100% (2/2)50%  (17/34)65%  (182/280)61%  (45.5/75)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JobBuilderHelper$CommonJobProperties100% (1/1)48%  (11/23)62%  (85/136)53%  (17.5/33)
access$102 (JobBuilderHelper$CommonJobProperties, JobParametersValidator): Jo... 0%   (0/1)0%   (0/5)0%   (0/1)
access$202 (JobBuilderHelper$CommonJobProperties, JobParametersIncrementer): ... 0%   (0/1)0%   (0/5)0%   (0/1)
access$300 (JobBuilderHelper$CommonJobProperties): JobRepository 0%   (0/1)0%   (0/3)0%   (0/1)
access$400 (JobBuilderHelper$CommonJobProperties): boolean 0%   (0/1)0%   (0/3)0%   (0/1)
addJobExecutionListener (JobExecutionListener): void 0%   (0/1)0%   (0/6)0%   (0/2)
addStepExecutionListeners (List): void 0%   (0/1)0%   (0/6)0%   (0/2)
getName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
setJobParametersIncrementer (JobParametersIncrementer): void 0%   (0/1)0%   (0/4)0%   (0/2)
setJobParametersValidator (JobParametersValidator): void 0%   (0/1)0%   (0/4)0%   (0/2)
setJobRepository (JobRepository): void 0%   (0/1)0%   (0/4)0%   (0/2)
setName (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setRestartable (boolean): void 0%   (0/1)0%   (0/4)0%   (0/2)
JobBuilderHelper$CommonJobProperties (): void 100% (1/1)100% (11/11)100% (4/4)
JobBuilderHelper$CommonJobProperties (JobBuilderHelper$CommonJobProperties): ... 100% (1/1)100% (38/38)100% (10/10)
access$000 (JobBuilderHelper$CommonJobProperties): String 100% (1/1)100% (3/3)100% (1/1)
access$002 (JobBuilderHelper$CommonJobProperties, String): String 100% (1/1)100% (5/5)100% (1/1)
access$302 (JobBuilderHelper$CommonJobProperties, JobRepository): JobRepository 100% (1/1)100% (5/5)100% (1/1)
access$402 (JobBuilderHelper$CommonJobProperties, boolean): boolean 100% (1/1)100% (5/5)100% (1/1)
getJobExecutionListeners (): List 100% (1/1)100% (6/6)100% (1/1)
getJobParametersIncrementer (): JobParametersIncrementer 100% (1/1)100% (3/3)100% (1/1)
getJobParametersValidator (): JobParametersValidator 100% (1/1)100% (3/3)100% (1/1)
getJobRepository (): JobRepository 100% (1/1)100% (3/3)100% (1/1)
getRestartable (): boolean 100% (1/1)100% (3/3)100% (1/1)
     
class JobBuilderHelper100% (1/1)55%  (6/11)67%  (97/144)67%  (28/42)
getJobRepository (): JobRepository 0%   (0/1)0%   (0/4)0%   (0/1)
incrementer (JobParametersIncrementer): JobBuilderHelper 0%   (0/1)0%   (0/9)0%   (0/3)
isRestartable (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
listener (JobExecutionListener): JobBuilderHelper 0%   (0/1)0%   (0/8)0%   (0/3)
validator (JobParametersValidator): JobBuilderHelper 0%   (0/1)0%   (0/9)0%   (0/3)
enhance (Job): void 100% (1/1)76%  (42/55)81%  (13/16)
JobBuilderHelper (JobBuilderHelper): void 100% (1/1)100% (15/15)100% (4/4)
JobBuilderHelper (String): void 100% (1/1)100% (18/18)100% (5/5)
getName (): String 100% (1/1)100% (4/4)100% (1/1)
preventRestart (): JobBuilderHelper 100% (1/1)100% (9/9)100% (3/3)
repository (JobRepository): JobBuilderHelper 100% (1/1)100% (9/9)100% (3/3)

1/*
2 * Copyright 2006-2011 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 */
16package org.springframework.batch.core.job.builder;
17 
18import java.util.ArrayList;
19import java.util.LinkedHashSet;
20import java.util.List;
21import java.util.Set;
22 
23import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
25import org.springframework.batch.core.Job;
26import org.springframework.batch.core.JobExecutionListener;
27import org.springframework.batch.core.JobParametersIncrementer;
28import org.springframework.batch.core.JobParametersValidator;
29import org.springframework.batch.core.job.AbstractJob;
30import org.springframework.batch.core.repository.JobRepository;
31 
32/**
33 * A base class and utility for other job builders providing access to common properties like job repository.
34 * 
35 * @author Dave Syer
36 * 
37 * @since 2.2
38 */
39public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
40 
41        protected final Log logger = LogFactory.getLog(getClass());
42 
43        private final CommonJobProperties properties;
44 
45        public JobBuilderHelper(String name) {
46                this.properties = new CommonJobProperties();
47                properties.name = name;
48        }
49 
50        /**
51         * Create a new builder initialized with any properties in the parent. The parent is copied, so it can be re-used.
52         * 
53         * @param parent a parent helper containing common step properties
54         */
55        protected JobBuilderHelper(JobBuilderHelper<?> parent) {
56                this.properties = new CommonJobProperties(parent.properties);
57        }
58 
59        /**
60         * Add a job parameters validator.
61         * 
62         * @param jobParametersValidator a job parameters validator
63         * @return this to enable fluent chaining
64         */
65        public B validator(JobParametersValidator jobParametersValidator) {
66                properties.jobParametersValidator = jobParametersValidator;
67                @SuppressWarnings("unchecked")
68                B result = (B) this;
69                return result;
70        }
71 
72        /**
73         * Add a job parameters incrementer.
74         * 
75         * @param jobParametersIncrementer a job parameters incrementer
76         * @return this to enable fluent chaining
77         */
78        public B incrementer(JobParametersIncrementer jobParametersIncrementer) {
79                properties.jobParametersIncrementer = jobParametersIncrementer;
80                @SuppressWarnings("unchecked")
81                B result = (B) this;
82                return result;
83        }
84 
85        /**
86         * Sets the job repository for the job.
87         * 
88         * @param jobRepository the job repository (mandatory)
89         * @return this to enable fluent chaining
90         */
91        public B repository(JobRepository jobRepository) {
92                properties.jobRepository = jobRepository;
93                @SuppressWarnings("unchecked")
94                B result = (B) this;
95                return result;
96        }
97 
98        /**
99         * Register a job execution listener.
100         * 
101         * @param listener a job execution listener
102         * @return this to enable fluent chaining
103         */
104        public B listener(JobExecutionListener listener) {
105                properties.addJobExecutionListener(listener);
106                @SuppressWarnings("unchecked")
107                B result = (B) this;
108                return result;
109        }
110 
111        /**
112         * Set a flag to prevent restart an execution of this job even if it has failed.
113         * 
114         * @return this to enable fluent chaining
115         */
116        public B preventRestart() {
117                properties.restartable = false;
118                @SuppressWarnings("unchecked")
119                B result = (B) this;
120                return result;
121        }
122 
123        protected String getName() {
124                return properties.name;
125        }
126 
127        protected JobRepository getJobRepository() {
128                return properties.jobRepository;
129        }
130 
131        protected boolean isRestartable() {
132                return properties.restartable;
133        }
134 
135        protected void enhance(Job target) {
136 
137                if (target instanceof AbstractJob) {
138 
139                        AbstractJob job = (AbstractJob) target;
140                        job.setJobRepository(properties.getJobRepository());
141 
142                        JobParametersIncrementer jobParametersIncrementer = properties.getJobParametersIncrementer();
143                        if (jobParametersIncrementer != null) {
144                                job.setJobParametersIncrementer(jobParametersIncrementer);
145                        }
146                        JobParametersValidator jobParametersValidator = properties.getJobParametersValidator();
147                        if (jobParametersValidator != null) {
148                                job.setJobParametersValidator(jobParametersValidator);
149                        }
150 
151                        Boolean restartable = properties.getRestartable();
152                        if (restartable != null) {
153                                job.setRestartable(restartable);
154                        }
155 
156                        List<JobExecutionListener> listeners = properties.getJobExecutionListeners();
157                        if (!listeners.isEmpty()) {
158                                job.setJobExecutionListeners(listeners.toArray(new JobExecutionListener[0]));
159                        }
160 
161                }
162 
163        }
164 
165        public static class CommonJobProperties {
166 
167                private Set<JobExecutionListener> jobExecutionListeners = new LinkedHashSet<JobExecutionListener>();
168 
169                private boolean restartable = true;
170 
171                private JobRepository jobRepository;
172 
173                private JobParametersIncrementer jobParametersIncrementer;
174 
175                private JobParametersValidator jobParametersValidator;
176 
177                public CommonJobProperties() {
178                }
179 
180                public CommonJobProperties(CommonJobProperties properties) {
181                        this.name = properties.name;
182                        this.restartable = properties.restartable;
183                        this.jobRepository = properties.jobRepository;
184                        this.jobExecutionListeners = new LinkedHashSet<JobExecutionListener>(properties.jobExecutionListeners);
185                        this.jobParametersIncrementer = properties.jobParametersIncrementer;
186                        this.jobParametersValidator = properties.jobParametersValidator;
187                }
188 
189                public JobParametersIncrementer getJobParametersIncrementer() {
190                        return jobParametersIncrementer;
191                }
192 
193                public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIncrementer) {
194                        this.jobParametersIncrementer = jobParametersIncrementer;
195                }
196 
197                public JobParametersValidator getJobParametersValidator() {
198                        return jobParametersValidator;
199                }
200 
201                public void setJobParametersValidator(JobParametersValidator jobParametersValidator) {
202                        this.jobParametersValidator = jobParametersValidator;
203                }
204 
205                public JobRepository getJobRepository() {
206                        return jobRepository;
207                }
208 
209                public void setJobRepository(JobRepository jobRepository) {
210                        this.jobRepository = jobRepository;
211                }
212 
213                public String getName() {
214                        return name;
215                }
216 
217                public void setName(String name) {
218                        this.name = name;
219                }
220 
221                public List<JobExecutionListener> getJobExecutionListeners() {
222                        return new ArrayList<JobExecutionListener>(jobExecutionListeners);
223                }
224 
225                public void addStepExecutionListeners(List<JobExecutionListener> jobExecutionListeners) {
226                        this.jobExecutionListeners.addAll(jobExecutionListeners);
227                }
228 
229                public void addJobExecutionListener(JobExecutionListener jobExecutionListener) {
230                        this.jobExecutionListeners.add(jobExecutionListener);
231                }
232 
233                public boolean getRestartable() {
234                        return restartable;
235                }
236 
237                public void setRestartable(boolean restartable) {
238                        this.restartable = restartable;
239                }
240 
241                private String name;
242 
243        }
244 
245}

[all classes][org.springframework.batch.core.job.builder]
EMMA 2.0.5312 (C) Vladimir Roubtsov