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

COVERAGE SUMMARY FOR SOURCE FILE [StepExecutionSimpleCompletionPolicy.java]

nameclass, %method, %block, %line, %
StepExecutionSimpleCompletionPolicy.java100% (1/1)62%  (5/8)65%  (67/103)61%  (11.5/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class StepExecutionSimpleCompletionPolicy100% (1/1)62%  (5/8)65%  (67/103)61%  (11.5/19)
isComplete (RepeatContext, RepeatStatus): boolean 0%   (0/1)0%   (0/14)0%   (0/2)
setKeyName (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
update (RepeatContext): void 0%   (0/1)0%   (0/13)0%   (0/3)
toString (): String 100% (1/1)70%  (7/10)70%  (0.7/1)
isComplete (RepeatContext): boolean 100% (1/1)92%  (12/13)96%  (1.9/2)
start (RepeatContext): RepeatContext 100% (1/1)92%  (12/13)96%  (1.9/2)
StepExecutionSimpleCompletionPolicy (): void 100% (1/1)100% (6/6)100% (2/2)
beforeStep (StepExecution): void 100% (1/1)100% (30/30)100% (5/5)

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.resource;
18 
19import org.springframework.batch.core.JobParameters;
20import org.springframework.batch.core.StepExecution;
21import org.springframework.batch.core.StepExecutionListener;
22import org.springframework.batch.core.listener.StepExecutionListenerSupport;
23import org.springframework.batch.repeat.CompletionPolicy;
24import org.springframework.batch.repeat.RepeatContext;
25import org.springframework.batch.repeat.RepeatStatus;
26import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
27import org.springframework.util.Assert;
28 
29/**
30 * A {@link CompletionPolicy} that picks up a commit interval from
31 * {@link JobParameters} by listening to the start of a step. Use anywhere that
32 * a {@link CompletionPolicy} can be used (usually at the chunk level in a
33 * step), and inject as a {@link StepExecutionListener} into the surrounding
34 * step. N.B. only after the step has started will the completion policy be
35 * usable.
36 * 
37 * @author Dave Syer
38 * 
39 * @see CompletionPolicy
40 */
41public class StepExecutionSimpleCompletionPolicy extends StepExecutionListenerSupport implements CompletionPolicy {
42 
43        private CompletionPolicy delegate;
44 
45        private String keyName = "commit.interval";
46 
47        /**
48         * Public setter for the key name of a Long value in the
49         * {@link JobParameters} that will contain a commit interval. Defaults to
50         * "commit.interval".
51         * @param keyName the keyName to set
52         */
53        public void setKeyName(String keyName) {
54                this.keyName = keyName;
55        }
56 
57        /**
58         * Set up a {@link SimpleCompletionPolicy} with a commit interval taken from
59         * the {@link JobParameters}. If there is a Long parameter with the given
60         * key name, the intValue of this parameter is used. If not an exception
61         * will be thrown.
62         * 
63         * @see org.springframework.batch.core.listener.StepExecutionListenerSupport#beforeStep(org.springframework.batch.core.StepExecution)
64         */
65        public void beforeStep(StepExecution stepExecution) {
66                JobParameters jobParameters = stepExecution.getJobParameters();
67                Assert.state(jobParameters.getParameters().containsKey(keyName),
68                                "JobParameters do not contain Long parameter with key=[" + keyName + "]");
69                delegate = new SimpleCompletionPolicy((int) jobParameters.getLong(keyName));
70        }
71 
72        /**
73         * @param context
74         * @param result
75         * @return true if the commit interval has been reached or the result
76         * indicates completion
77         * @see CompletionPolicy#isComplete(RepeatContext, RepeatStatus)
78         */
79        public boolean isComplete(RepeatContext context, RepeatStatus result) {
80                Assert.state(delegate != null, "The delegate resource has not been initialised. "
81                                + "Remember to register this object as a StepListener.");
82                return delegate.isComplete(context, result);
83        }
84 
85        /**
86         * @param context
87         * @return if the commit interval has been reached
88         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext)
89         */
90        public boolean isComplete(RepeatContext context) {
91                Assert.state(delegate != null, "The delegate resource has not been initialised. "
92                                + "Remember to register this object as a StepListener.");
93                return delegate.isComplete(context);
94        }
95 
96        /**
97         * @param parent
98         * @return a new {@link RepeatContext}
99         * @see org.springframework.batch.repeat.CompletionPolicy#start(org.springframework.batch.repeat.RepeatContext)
100         */
101        public RepeatContext start(RepeatContext parent) {
102                Assert.state(delegate != null, "The delegate resource has not been initialised. "
103                                + "Remember to register this object as a StepListener.");
104                return delegate.start(parent);
105        }
106 
107        /**
108         * @param context
109         * @see org.springframework.batch.repeat.CompletionPolicy#update(org.springframework.batch.repeat.RepeatContext)
110         */
111        public void update(RepeatContext context) {
112                Assert.state(delegate != null, "The delegate resource has not been initialised. "
113                                + "Remember to register this object as a StepListener.");
114                delegate.update(context);
115        }
116 
117        /**
118         * Delegates to the wrapped {@link CompletionPolicy} if set, otherwise
119         * returns the value of {@link #setKeyName(String)}.
120         */
121        public String toString() {
122                return (delegate == null) ? keyName : delegate.toString();
123        }
124 
125}

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