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 | package org.springframework.batch.core; |
17 | |
18 | /** |
19 | * Represents a contribution to a {@link StepExecution}, buffering changes |
20 | * until they can be applied at a chunk boundary. |
21 | * |
22 | * @author Dave Syer |
23 | * |
24 | */ |
25 | public class StepContribution { |
26 | |
27 | private int itemCount = 0; |
28 | |
29 | private int parentSkipCount; |
30 | |
31 | private int commitCount; |
32 | |
33 | private int skipCount; |
34 | |
35 | private int readSkipCount; |
36 | |
37 | /** |
38 | * @param execution |
39 | */ |
40 | public StepContribution(StepExecution execution) { |
41 | this.parentSkipCount = execution.getSkipCount(); |
42 | } |
43 | |
44 | /** |
45 | * Increment the counter for the number of items processed. |
46 | */ |
47 | public void incrementItemCount() { |
48 | itemCount++; |
49 | } |
50 | |
51 | /** |
52 | * Public access to the item counter. |
53 | * |
54 | * @return the item counter. |
55 | */ |
56 | public int getItemCount() { |
57 | return itemCount; |
58 | } |
59 | |
60 | /** |
61 | * Increment the commit counter. |
62 | */ |
63 | public void incrementCommitCount() { |
64 | commitCount++; |
65 | } |
66 | |
67 | /** |
68 | * Public getter for the commit counter. |
69 | * @return the commitCount |
70 | */ |
71 | public int getCommitCount() { |
72 | return commitCount; |
73 | } |
74 | |
75 | /** |
76 | * @return the sum of skips accumulated in the parent {@link StepExecution} |
77 | * and this <code>StepContribution</code>, including uncommitted read |
78 | * skips. |
79 | */ |
80 | public int getStepSkipCount() { |
81 | return readSkipCount + skipCount + parentSkipCount; |
82 | } |
83 | |
84 | /** |
85 | * @return the number of skips collected in this |
86 | * <code>StepContribution</code> (not including skips accumulated in the |
87 | * parent {@link StepExecution}. |
88 | */ |
89 | public int getSkipCount() { |
90 | return skipCount; |
91 | } |
92 | |
93 | /** |
94 | * Increment the total skip count for this contribution |
95 | */ |
96 | public void incrementSkipCount() { |
97 | skipCount++; |
98 | } |
99 | |
100 | /** |
101 | * Increment the counter for skipped reads |
102 | */ |
103 | public void incrementReadSkipCount() { |
104 | readSkipCount++; |
105 | } |
106 | |
107 | /** |
108 | * @return the read skip count |
109 | */ |
110 | public int getReadSkipCount() { |
111 | return readSkipCount; |
112 | } |
113 | |
114 | /** |
115 | * Combine the skip counts and reset read skips to zero. |
116 | */ |
117 | public void combineSkipCounts() { |
118 | skipCount += readSkipCount; |
119 | readSkipCount = 0; |
120 | } |
121 | |
122 | /* |
123 | * (non-Javadoc) |
124 | * @see java.lang.Object#toString() |
125 | */ |
126 | public String toString() { |
127 | return "[StepContribution: items=" + itemCount + ", commits=" + commitCount + ", readSkips=" + readSkipCount |
128 | + ", skips=" + skipCount + "]"; |
129 | } |
130 | |
131 | } |