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 [SimpleJobBuilder.java]

nameclass, %method, %block, %line, %
SimpleJobBuilder.java100% (1/1)88%  (7/8)65%  (170/261)69%  (35.9/52)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleJobBuilder100% (1/1)88%  (7/8)65%  (170/261)69%  (35.9/52)
start (JobExecutionDecider): JobFlowBuilder 0%   (0/1)0%   (0/48)0%   (0/9)
start (Step): SimpleJobBuilder 100% (1/1)67%  (12/18)75%  (3/4)
next (JobExecutionDecider): JobFlowBuilder 100% (1/1)70%  (37/53)78%  (7/9)
split (TaskExecutor): FlowBuilder$SplitBuilder 100% (1/1)71%  (34/48)75%  (6/8)
build (): Job 100% (1/1)82%  (27/33)80%  (8/10)
on (String): FlowBuilder$TransitionBuilder 100% (1/1)98%  (44/45)99%  (6.9/7)
SimpleJobBuilder (JobBuilderHelper): void 100% (1/1)100% (9/9)100% (3/3)
next (Step): SimpleJobBuilder 100% (1/1)100% (7/7)100% (2/2)

1/*
2 * Copyright 2012-2013 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.List;
20 
21import org.springframework.batch.core.Job;
22import org.springframework.batch.core.Step;
23import org.springframework.batch.core.job.SimpleJob;
24import org.springframework.batch.core.job.flow.JobExecutionDecider;
25import org.springframework.core.task.TaskExecutor;
26import org.springframework.util.Assert;
27 
28/**
29 * @author Dave Syer
30 * 
31 * @since 2.2
32 * 
33 */
34public class SimpleJobBuilder extends JobBuilderHelper<SimpleJobBuilder> {
35 
36        private List<Step> steps = new ArrayList<Step>();
37 
38        private JobFlowBuilder builder;
39 
40        /**
41         * Create a new builder initialized with any properties in the parent. The parent is copied, so it can be re-used.
42         * 
43         * @param parent the parent to use
44         */
45        public SimpleJobBuilder(JobBuilderHelper<?> parent) {
46                super(parent);
47        }
48 
49        public Job build() {
50                if (builder != null) {
51                        return builder.end().build();
52                }
53                SimpleJob job = new SimpleJob(getName());
54                super.enhance(job);
55                job.setSteps(steps);
56                try {
57                        job.afterPropertiesSet();
58                }
59                catch (Exception e) {
60                        throw new JobBuilderException(e);
61                }
62                return job;
63        }
64 
65        /**
66         * Start the job with this step.
67         * 
68         * @param step a step to start with
69         * @return this for fluent chaining
70         */
71        public SimpleJobBuilder start(Step step) {
72                if (steps.isEmpty()) {
73                        steps.add(step);
74                }
75                else {
76                        steps.set(0, step);
77                }
78                return this;
79        }
80 
81        /**
82         * Branch into a flow conditional on the outcome of the current step.
83         * 
84         * @param pattern a pattern for the exit status of the current step
85         * @return a builder for fluent chaining
86         */
87        public FlowBuilder.TransitionBuilder<FlowJobBuilder> on(String pattern) {
88                Assert.state(steps.size() > 0, "You have to start a job with a step");
89                for (Step step : steps) {
90                        if (builder == null) {
91                                builder = new JobFlowBuilder(new FlowJobBuilder(this), step);
92                        }
93                        else {
94                                builder.next(step);
95                        }
96                }
97                return builder.on(pattern);
98        }
99 
100        /**
101         * Start with this decider. Returns a flow builder and when the flow is ended a job builder will be returned to
102         * continue the job configuration if needed.
103         * 
104         * @param decider a decider to execute first
105         * @return builder for fluent chaining
106         */
107        public JobFlowBuilder start(JobExecutionDecider decider) {
108                if (builder == null) {
109                        builder = new JobFlowBuilder(new FlowJobBuilder(this), decider);
110                }
111                else {
112                        builder.start(decider);
113                }
114                if (!steps.isEmpty()) {
115                        steps.remove(0);
116                }
117                for (Step step : steps) {
118                        builder.next(step);
119                }
120                return builder;
121        }
122 
123        /**
124         * Continue with this decider if the previous step was successful. Returns a flow builder and when the flow is ended
125         * a job builder will be returned to continue the job configuration if needed.
126         * 
127         * @param decider a decider to execute next
128         * @return builder for fluent chaining
129         */
130        public JobFlowBuilder next(JobExecutionDecider decider) {
131                for (Step step : steps) {
132                        if (builder == null) {
133                                builder = new JobFlowBuilder(new FlowJobBuilder(this), step);
134                        }
135                        else {
136                                builder.next(step);
137                        }
138                }
139                if (builder == null) {
140                        builder = new JobFlowBuilder(new FlowJobBuilder(this), decider);
141                }
142                else {
143                        builder.next(decider);
144                }
145                return builder;
146        }
147 
148        /**
149         * Continue or end a job with this step if the previous step was successful.
150         * 
151         * @param step a step to execute next
152         * @return this for fluent chaining
153         */
154        public SimpleJobBuilder next(Step step) {
155                steps.add(step);
156                return this;
157        }
158 
159        /**
160         * @param executor
161         * @return builder for fluent chaining
162         */
163        public JobFlowBuilder.SplitBuilder<FlowJobBuilder> split(TaskExecutor executor) {
164                for (Step step : steps) {
165                        if (builder == null) {
166                                builder = new JobFlowBuilder(new FlowJobBuilder(this), step);
167                        }
168                        else {
169                                builder.next(step);
170                        }
171                }
172                if (builder == null) {
173                        builder = new JobFlowBuilder(new FlowJobBuilder(this));
174                }
175                return builder.split(executor);
176        }
177 
178}

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