EMMA Coverage Report (generated Fri Jan 30 13:20:29 EST 2009)
[all classes][org.springframework.batch.repeat.policy]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleCompletionPolicy.java]

nameclass, %method, %block, %line, %
SimpleCompletionPolicy.java100% (2/2)91%  (10/11)76%  (64/84)95%  (19/20)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleCompletionPolicy100% (1/1)88%  (7/8)69%  (44/64)93%  (13/14)
toString (): String 0%   (0/1)0%   (0/20)0%   (0/1)
SimpleCompletionPolicy (): void 100% (1/1)100% (4/4)100% (2/2)
SimpleCompletionPolicy (int): void 100% (1/1)100% (9/9)100% (4/4)
isComplete (RepeatContext): boolean 100% (1/1)100% (4/4)100% (1/1)
isComplete (RepeatContext, ExitStatus): boolean 100% (1/1)100% (13/13)100% (1/1)
setChunkSize (int): void 100% (1/1)100% (4/4)100% (2/2)
start (RepeatContext): RepeatContext 100% (1/1)100% (6/6)100% (1/1)
update (RepeatContext): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimpleCompletionPolicy$SimpleTerminationContext100% (1/1)100% (3/3)100% (20/20)100% (6/6)
SimpleCompletionPolicy$SimpleTerminationContext (SimpleCompletionPolicy, Repe... 100% (1/1)100% (7/7)100% (3/3)
isComplete (): boolean 100% (1/1)100% (10/10)100% (1/1)
update (): void 100% (1/1)100% (3/3)100% (2/2)

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.repeat.policy;
18 
19import org.springframework.batch.repeat.ExitStatus;
20import org.springframework.batch.repeat.RepeatContext;
21import org.springframework.batch.repeat.context.RepeatContextSupport;
22import org.springframework.batch.repeat.support.RepeatTemplate;
23import org.springframework.util.ClassUtils;
24 
25/**
26 * Policy for terminating a batch after a fixed number of operations. Internal
27 * state is maintained and a counter incremented, so successful use of this
28 * policy requires that isComplete() is only called once per batch item. Using
29 * the standard {@link RepeatTemplate} should ensure this contract is kept, but it needs
30 * to be carefully monitored.
31 * 
32 * @author Dave Syer
33 * 
34 */
35public class SimpleCompletionPolicy extends DefaultResultCompletionPolicy {
36 
37        public static final int DEFAULT_CHUNK_SIZE = 5;
38 
39        int chunkSize = 0;
40 
41        public SimpleCompletionPolicy() {
42                this(DEFAULT_CHUNK_SIZE);
43        }
44 
45        public SimpleCompletionPolicy(int chunkSize) {
46                super();
47                this.chunkSize = chunkSize;
48        }
49 
50        public void setChunkSize(int chunkSize) {
51                this.chunkSize = chunkSize;
52        }
53 
54        /**
55         * Reset the counter.
56         * 
57         * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext)
58         */
59        public RepeatContext start(RepeatContext context) {
60                return new SimpleTerminationContext(context);
61        }
62 
63        /**
64         * Terminate if the chunk size has been reached, or the result is null.
65         * 
66         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext,
67         * ExitStatus)
68         * @throws RuntimeException (normally terminating the batch) if the result is
69         * itself an exception.
70         */
71        public boolean isComplete(RepeatContext context, ExitStatus result) {
72                return super.isComplete(context, result) || ((SimpleTerminationContext) context).isComplete();
73        }
74 
75        /**
76         * Terminate if the chunk size has been reached.
77         * 
78         * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext)
79         */
80        public boolean isComplete(RepeatContext context) {
81                return ((SimpleTerminationContext) context).isComplete();
82        }
83 
84        /**
85         * Increment the counter in the context.
86         * 
87         * @see org.springframework.batch.repeat.CompletionPolicy#update(RepeatContext)
88         */
89        public void update(RepeatContext context) {
90                ((SimpleTerminationContext) context).update();
91        }
92 
93        protected class SimpleTerminationContext extends RepeatContextSupport {
94 
95                public SimpleTerminationContext(RepeatContext context) {
96                        super(context);
97                }
98 
99                public void update() {
100                        increment();
101                }
102 
103                public boolean isComplete() {
104                        return getStartedCount() >= chunkSize;
105                }
106        }
107        
108        /* (non-Javadoc)
109         * @see java.lang.Object#toString()
110         */
111        public String toString() {
112                return ClassUtils.getShortName(SimpleCompletionPolicy.class)+": chunkSize="+chunkSize;
113        }
114 
115}

[all classes][org.springframework.batch.repeat.policy]
EMMA 2.0.5312 (C) Vladimir Roubtsov