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.repeat.callback;
18
19 import org.springframework.batch.repeat.RepeatCallback;
20 import org.springframework.batch.repeat.RepeatContext;
21 import org.springframework.batch.repeat.RepeatOperations;
22 import org.springframework.batch.repeat.RepeatStatus;
23
24 /**
25 * Callback that delegates to another callback, via a {@link RepeatOperations}
26 * instance. Useful when nesting or composing batches in one another, e.g. for
27 * breaking a batch down into chunks.
28 *
29 * @author Dave Syer
30 *
31 */
32 public class NestedRepeatCallback implements RepeatCallback {
33
34 private RepeatOperations template;
35
36 private RepeatCallback callback;
37
38 /**
39 * Constructor setting mandatory fields.
40 *
41 * @param template the {@link RepeatOperations} to use when calling the
42 * delegate callback
43 * @param callback the {@link RepeatCallback} delegate
44 */
45 public NestedRepeatCallback(RepeatOperations template, RepeatCallback callback) {
46 super();
47 this.template = template;
48 this.callback = callback;
49 }
50
51 /**
52 * Simply calls template.execute(callback). Clients can use this to repeat a
53 * batch process, or to break a process up into smaller chunks (e.g. to
54 * change the transaction boundaries).
55 *
56 * @see org.springframework.batch.repeat.RepeatCallback#doInIteration(RepeatContext)
57 */
58 @Override
59 public RepeatStatus doInIteration(RepeatContext context) throws Exception {
60 return template.iterate(callback);
61 }
62 }