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
17 package org.springframework.batch.core.scope.context;
18
19 import java.util.Arrays;
20
21 import org.springframework.core.AttributeAccessorSupport;
22
23 /**
24 * Context object for weakly typed data stored for the duration of a chunk
25 * (usually a group of items processed together in a transaction). If there is a
26 * rollback and the chunk is retried the same context will be associated with
27 * it.
28 *
29 * @author Dave Syer
30 *
31 */
32 public class ChunkContext extends AttributeAccessorSupport {
33
34 private final StepContext stepContext;
35
36 private boolean complete = false;
37
38 /**
39 * @param stepContext the current step context
40 */
41 public ChunkContext(StepContext stepContext) {
42 this.stepContext = stepContext;
43 }
44
45 /**
46 * @return the current step context
47 */
48 public StepContext getStepContext() {
49 return stepContext;
50 }
51
52 /**
53 * @return true if there is no more processing to be done on this chunk
54 */
55 public boolean isComplete() {
56 return complete;
57 }
58
59 /**
60 * Setter for the flag to signal complete processing of a chunk.
61 */
62 public void setComplete() {
63 this.complete = true;
64 }
65
66 /*
67 * (non-Javadoc)
68 *
69 * @see java.lang.Object#toString()
70 */
71 @Override
72 public String toString() {
73 return String.format("ChunkContext: attributes=%s, complete=%b, stepContext=%s", Arrays
74 .asList(attributeNames()), complete, stepContext);
75 }
76
77 }