001/* 002 * Copyright 2006-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.repeat.callback; 018 019import org.springframework.batch.repeat.RepeatCallback; 020import org.springframework.batch.repeat.RepeatContext; 021import org.springframework.batch.repeat.RepeatOperations; 022import org.springframework.batch.repeat.RepeatStatus; 023 024/** 025 * Callback that delegates to another callback, via a {@link RepeatOperations} 026 * instance. Useful when nesting or composing batches in one another, e.g. for 027 * breaking a batch down into chunks. 028 * 029 * @author Dave Syer 030 * 031 */ 032public class NestedRepeatCallback implements RepeatCallback { 033 034 private RepeatOperations template; 035 036 private RepeatCallback callback; 037 038 /** 039 * Constructor setting mandatory fields. 040 * 041 * @param template the {@link RepeatOperations} to use when calling the 042 * delegate callback 043 * @param callback the {@link RepeatCallback} delegate 044 */ 045 public NestedRepeatCallback(RepeatOperations template, RepeatCallback callback) { 046 super(); 047 this.template = template; 048 this.callback = callback; 049 } 050 051 /** 052 * Simply calls template.execute(callback). Clients can use this to repeat a 053 * batch process, or to break a process up into smaller chunks (e.g. to 054 * change the transaction boundaries). 055 * 056 * @see org.springframework.batch.repeat.RepeatCallback#doInIteration(RepeatContext) 057 */ 058 @Override 059 public RepeatStatus doInIteration(RepeatContext context) throws Exception { 060 return template.iterate(callback); 061 } 062}