EMMA Coverage Report (generated Fri Aug 21 15:59:46 BST 2009)
[all classes][org.springframework.batch.core.job]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleJob.java]

nameclass, %method, %block, %line, %
SimpleJob.java100% (1/1)100% (7/7)100% (116/116)100% (28/28)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleJob100% (1/1)100% (7/7)100% (116/116)100% (28/28)
SimpleJob (): void 100% (1/1)100% (4/4)100% (2/2)
SimpleJob (String): void 100% (1/1)100% (9/9)100% (3/3)
addStep (Step): void 100% (1/1)100% (6/6)100% (2/2)
doExecute (JobExecution): void 100% (1/1)100% (44/44)100% (10/10)
getStep (String): Step 100% (1/1)100% (21/21)100% (4/4)
getStepNames (): Collection 100% (1/1)100% (23/23)100% (4/4)
setSteps (List): void 100% (1/1)100% (9/9)100% (3/3)

1/*
2 * Copyright 2006-2007 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.core.job;
18 
19import java.util.ArrayList;
20import java.util.Collection;
21import java.util.List;
22 
23import org.springframework.batch.core.BatchStatus;
24import org.springframework.batch.core.Job;
25import org.springframework.batch.core.JobExecution;
26import org.springframework.batch.core.JobInterruptedException;
27import org.springframework.batch.core.StartLimitExceededException;
28import org.springframework.batch.core.Step;
29import org.springframework.batch.core.StepExecution;
30import org.springframework.batch.core.repository.JobRestartException;
31 
32/**
33 * Simple implementation of {@link Job} interface providing the ability to run a
34 * {@link JobExecution}. Sequentially executes a job by iterating through its
35 * list of steps.  Any {@link Step} that fails will fail the job.  The job is
36 * considered complete when all steps have been executed.
37 * 
38 * @author Lucas Ward
39 * @author Dave Syer
40 */
41public class SimpleJob extends AbstractJob {
42 
43        private List<Step> steps = new ArrayList<Step>();
44 
45        /**
46         * Default constructor for job with null name
47         */
48        public SimpleJob() {
49                this(null);
50        }
51 
52        /**
53         * @param name
54         */
55        public SimpleJob(String name) {
56                super(name);
57        }
58 
59        /**
60         * Public setter for the steps in this job. Overrides any calls to
61         * {@link #addStep(Step)}.
62         * 
63         * @param steps the steps to execute
64         */
65        public void setSteps(List<Step> steps) {
66                this.steps.clear();
67                this.steps.addAll(steps);
68        }
69 
70        /**
71         * Convenience method for clients to inspect the steps for this job.
72         * 
73         * @return the step names for this job
74         */
75        public Collection<String> getStepNames() {
76                List<String> names = new ArrayList<String>();
77                for (Step step : steps) {
78                        names.add(step.getName());
79                }
80                return names;
81        }
82 
83        /**
84         * Convenience method for adding a single step to the job.
85         * 
86         * @param step a {@link Step} to add
87         */
88        public void addStep(Step step) {
89                this.steps.add(step);
90        }
91 
92        /*
93         * (non-Javadoc)
94         * 
95         * @see
96         * org.springframework.batch.core.job.AbstractJob#getStep(java.lang.String)
97         */
98        public Step getStep(String stepName) {
99                for (Step step : this.steps) {
100                        if (step.getName().equals(stepName)) {
101                                return step;
102                        }
103                }
104                return null;
105        }
106 
107        /**
108         * Handler of steps sequentially as provided, checking each one for success
109         * before moving to the next. Returns the last {@link StepExecution}
110         * successfully processed if it exists, and null if none were processed.
111         * 
112         * @param execution the current {@link JobExecution}
113         * 
114         * @see AbstractJob#handleStep(Step, JobExecution)
115         */
116        protected void doExecute(JobExecution execution) throws JobInterruptedException, JobRestartException,
117                        StartLimitExceededException {
118 
119                StepExecution stepExecution = null;
120                for (Step step : steps) {
121                        stepExecution = handleStep(step, execution);
122                        if (stepExecution.getStatus() != BatchStatus.COMPLETED) {
123                                //
124                                // Terminate the job if a step fails
125                                //
126                                break;
127                        }
128                }
129 
130                //
131                // Update the job status to be the same as the last step
132                //
133                if (stepExecution != null) {
134                        logger.debug("Upgrading JobExecution status: " + stepExecution);
135                        execution.upgradeStatus(stepExecution.getStatus());
136                        execution.setExitStatus(stepExecution.getExitStatus());
137                }
138        }
139 
140}

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