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

COVERAGE SUMMARY FOR SOURCE FILE [StepBuilderHelper.java]

nameclass, %method, %block, %line, %
StepBuilderHelper.java100% (2/2)72%  (28/39)87%  (291/335)80%  (66/83)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StepBuilderHelper$CommonStepProperties100% (1/1)62%  (16/26)72%  (104/144)52%  (17/33)
addStepExecutionListeners (List): void 0%   (0/1)0%   (0/6)0%   (0/2)
getAllowStartIfComplete (): Boolean 0%   (0/1)0%   (0/3)0%   (0/1)
getName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getStartLimit (): Integer 0%   (0/1)0%   (0/4)0%   (0/1)
getTransactionManager (): PlatformTransactionManager 0%   (0/1)0%   (0/3)0%   (0/1)
setAllowStartIfComplete (Boolean): 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)
setStartLimit (Integer): void 0%   (0/1)0%   (0/5)0%   (0/2)
setTransactionManager (PlatformTransactionManager): void 0%   (0/1)0%   (0/4)0%   (0/2)
StepBuilderHelper$CommonStepProperties (): void 100% (1/1)100% (11/11)100% (4/4)
StepBuilderHelper$CommonStepProperties (StepBuilderHelper$CommonStepPropertie... 100% (1/1)100% (38/38)100% (10/10)
access$000 (StepBuilderHelper$CommonStepProperties): String 100% (1/1)100% (3/3)100% (1/1)
access$002 (StepBuilderHelper$CommonStepProperties, String): String 100% (1/1)100% (5/5)100% (1/1)
access$100 (StepBuilderHelper$CommonStepProperties): JobRepository 100% (1/1)100% (3/3)100% (1/1)
access$102 (StepBuilderHelper$CommonStepProperties, JobRepository): JobReposi... 100% (1/1)100% (5/5)100% (1/1)
access$200 (StepBuilderHelper$CommonStepProperties): PlatformTransactionManager 100% (1/1)100% (3/3)100% (1/1)
access$202 (StepBuilderHelper$CommonStepProperties, PlatformTransactionManage... 100% (1/1)100% (5/5)100% (1/1)
access$300 (StepBuilderHelper$CommonStepProperties): int 100% (1/1)100% (3/3)100% (1/1)
access$302 (StepBuilderHelper$CommonStepProperties, int): int 100% (1/1)100% (5/5)100% (1/1)
access$400 (StepBuilderHelper$CommonStepProperties): Boolean 100% (1/1)100% (3/3)100% (1/1)
access$402 (StepBuilderHelper$CommonStepProperties, Boolean): Boolean 100% (1/1)100% (5/5)100% (1/1)
access$500 (StepBuilderHelper$CommonStepProperties): List 100% (1/1)100% (3/3)100% (1/1)
addStepExecutionListener (StepExecutionListener): void 100% (1/1)100% (6/6)100% (2/2)
getJobRepository (): JobRepository 100% (1/1)100% (3/3)100% (1/1)
getStepExecutionListeners (): List 100% (1/1)100% (3/3)100% (1/1)
     
class StepBuilderHelper100% (1/1)92%  (12/13)98%  (187/191)98%  (49/50)
getTransactionManager (): PlatformTransactionManager 0%   (0/1)0%   (0/4)0%   (0/1)
StepBuilderHelper (StepBuilderHelper): void 100% (1/1)100% (15/15)100% (4/4)
StepBuilderHelper (String): void 100% (1/1)100% (18/18)100% (5/5)
allowStartIfComplete (boolean): StepBuilderHelper 100% (1/1)100% (10/10)100% (3/3)
enhance (Step): void 100% (1/1)100% (52/52)100% (14/14)
getJobRepository (): JobRepository 100% (1/1)100% (4/4)100% (1/1)
getName (): String 100% (1/1)100% (4/4)100% (1/1)
isAllowStartIfComplete (): boolean 100% (1/1)100% (11/11)100% (1/1)
listener (Object): StepBuilderHelper 100% (1/1)100% (38/38)100% (9/9)
listener (StepExecutionListener): StepBuilderHelper 100% (1/1)100% (8/8)100% (3/3)
repository (JobRepository): StepBuilderHelper 100% (1/1)100% (9/9)100% (3/3)
startLimit (int): StepBuilderHelper 100% (1/1)100% (9/9)100% (3/3)
transactionManager (PlatformTransactionManager): StepBuilderHelper 100% (1/1)100% (9/9)100% (3/3)

1/*
2 * Copyright 2006-2014 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.step.builder;
17 
18import org.apache.commons.logging.Log;
19import org.apache.commons.logging.LogFactory;
20import org.springframework.batch.core.Step;
21import org.springframework.batch.core.StepExecutionListener;
22import org.springframework.batch.core.annotation.AfterStep;
23import org.springframework.batch.core.annotation.BeforeStep;
24import org.springframework.batch.core.listener.StepListenerFactoryBean;
25import org.springframework.batch.core.repository.JobRepository;
26import org.springframework.batch.core.step.AbstractStep;
27import org.springframework.batch.core.step.tasklet.TaskletStep;
28import org.springframework.batch.support.ReflectionUtils;
29import org.springframework.transaction.PlatformTransactionManager;
30 
31import java.lang.reflect.Method;
32import java.util.ArrayList;
33import java.util.HashSet;
34import java.util.List;
35import java.util.Set;
36 
37/**
38 * A base class and utility for other step builders providing access to common properties like job repository and
39 * transaction manager.
40 * 
41 * @author Dave Syer
42 * @author Michael Minella
43 *
44 * @since 2.2
45 */
46public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
47 
48        protected final Log logger = LogFactory.getLog(getClass());
49 
50        protected final CommonStepProperties properties;
51 
52        public StepBuilderHelper(String name) {
53                this.properties = new CommonStepProperties();
54                properties.name = name;
55        }
56 
57        /**
58         * Create a new builder initialized with any properties in the parent. The parent is copied, so it can be re-used.
59         * 
60         * @param parent a parent helper containing common step properties
61         */
62        protected StepBuilderHelper(StepBuilderHelper<?> parent) {
63                this.properties = new CommonStepProperties(parent.properties);
64        }
65 
66        public B repository(JobRepository jobRepository) {
67                properties.jobRepository = jobRepository;
68                @SuppressWarnings("unchecked")
69                B result = (B) this;
70                return result;
71        }
72 
73        public B transactionManager(PlatformTransactionManager transactionManager) {
74                properties.transactionManager = transactionManager;
75                @SuppressWarnings("unchecked")
76                B result = (B) this;
77                return result;
78        }
79 
80        public B startLimit(int startLimit) {
81                properties.startLimit = startLimit;
82                @SuppressWarnings("unchecked")
83                B result = (B) this;
84                return result;
85        }
86 
87        /**
88         * Registers objects using the annotation based listener configuration.
89         *
90         * @param listener the object that has a method configured with listener annotation
91         * @return this for fluent chaining
92         */
93        public B listener(Object listener) {
94                Set<Method> stepExecutionListenerMethods = new HashSet<Method>();
95                stepExecutionListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), BeforeStep.class));
96                stepExecutionListenerMethods.addAll(ReflectionUtils.findMethod(listener.getClass(), AfterStep.class));
97 
98                if(stepExecutionListenerMethods.size() > 0) {
99                        StepListenerFactoryBean factory = new StepListenerFactoryBean();
100                        factory.setDelegate(listener);
101                        properties.addStepExecutionListener((StepExecutionListener) factory.getObject());
102                }
103 
104                @SuppressWarnings("unchecked")
105                B result = (B) this;
106                return result;
107        }
108 
109        public B listener(StepExecutionListener listener) {
110                properties.addStepExecutionListener(listener);
111                @SuppressWarnings("unchecked")
112                B result = (B) this;
113                return result;
114        }
115 
116        public B allowStartIfComplete(boolean allowStartIfComplete) {
117                properties.allowStartIfComplete = allowStartIfComplete;
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 PlatformTransactionManager getTransactionManager() {
132                return properties.transactionManager;
133        }
134 
135        protected boolean isAllowStartIfComplete() {
136                return properties.allowStartIfComplete != null ? properties.allowStartIfComplete : false;
137        }
138 
139        protected void enhance(Step target) {
140 
141                if (target instanceof AbstractStep) {
142 
143                        AbstractStep step = (AbstractStep) target;
144                        step.setJobRepository(properties.getJobRepository());
145 
146                        Boolean allowStartIfComplete = properties.allowStartIfComplete;
147                        if (allowStartIfComplete != null) {
148                                step.setAllowStartIfComplete(allowStartIfComplete);
149                        }
150 
151                        step.setStartLimit(properties.startLimit);
152 
153                        List<StepExecutionListener> listeners = properties.stepExecutionListeners;
154                        if (!listeners.isEmpty()) {
155                                step.setStepExecutionListeners(listeners.toArray(new StepExecutionListener[0]));
156                        }
157 
158                }
159 
160                if (target instanceof TaskletStep) {
161                        TaskletStep step = (TaskletStep) target;
162                        step.setTransactionManager(properties.transactionManager);
163                }
164 
165        }
166 
167        public static class CommonStepProperties {
168 
169                private List<StepExecutionListener> stepExecutionListeners = new ArrayList<StepExecutionListener>();
170 
171                private int startLimit = Integer.MAX_VALUE;
172 
173                private Boolean allowStartIfComplete;
174 
175                private JobRepository jobRepository;
176 
177                private PlatformTransactionManager transactionManager;
178 
179                public CommonStepProperties() {
180                }
181 
182                public CommonStepProperties(CommonStepProperties properties) {
183                        this.name = properties.name;
184                        this.startLimit = properties.startLimit;
185                        this.allowStartIfComplete = properties.allowStartIfComplete;
186                        this.jobRepository = properties.jobRepository;
187                        this.transactionManager = properties.transactionManager;
188                        this.stepExecutionListeners = new ArrayList<StepExecutionListener>(properties.stepExecutionListeners);
189                }
190 
191                public JobRepository getJobRepository() {
192                        return jobRepository;
193                }
194 
195                public void setJobRepository(JobRepository jobRepository) {
196                        this.jobRepository = jobRepository;
197                }
198 
199                public PlatformTransactionManager getTransactionManager() {
200                        return transactionManager;
201                }
202 
203                public void setTransactionManager(PlatformTransactionManager transactionManager) {
204                        this.transactionManager = transactionManager;
205                }
206 
207                public String getName() {
208                        return name;
209                }
210 
211                public void setName(String name) {
212                        this.name = name;
213                }
214 
215                public List<StepExecutionListener> getStepExecutionListeners() {
216                        return stepExecutionListeners;
217                }
218 
219                public void addStepExecutionListeners(List<StepExecutionListener> stepExecutionListeners) {
220                        this.stepExecutionListeners.addAll(stepExecutionListeners);
221                }
222 
223                public void addStepExecutionListener(StepExecutionListener stepExecutionListener) {
224                        this.stepExecutionListeners.add(stepExecutionListener);
225                }
226 
227                public Integer getStartLimit() {
228                        return startLimit;
229                }
230 
231                public void setStartLimit(Integer startLimit) {
232                        this.startLimit = startLimit;
233                }
234 
235                public Boolean getAllowStartIfComplete() {
236                        return allowStartIfComplete;
237                }
238 
239                public void setAllowStartIfComplete(Boolean allowStartIfComplete) {
240                        this.allowStartIfComplete = allowStartIfComplete;
241                }
242 
243                private String name;
244 
245        }
246 
247}

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