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.step.item; |
17 | |
18 | import org.springframework.batch.core.Step; |
19 | import org.springframework.batch.repeat.RepeatOperations; |
20 | import org.springframework.batch.repeat.support.RepeatTemplate; |
21 | |
22 | /** |
23 | * Factory bean for {@link Step} implementations allowing registration of |
24 | * listeners and also direct injection of the {@link RepeatOperations} needed at |
25 | * step and chunk level. |
26 | * |
27 | * @author Dave Syer |
28 | * |
29 | */ |
30 | public class RepeatOperationsStepFactoryBean extends AbstractStepFactoryBean { |
31 | |
32 | private RepeatOperations chunkOperations = new RepeatTemplate(); |
33 | |
34 | private RepeatOperations stepOperations = new RepeatTemplate(); |
35 | |
36 | /** |
37 | * The {@link RepeatOperations} to use for the outer loop of the batch |
38 | * processing. Should be set up by the caller through a factory. Defaults to |
39 | * a plain {@link RepeatTemplate}. |
40 | * |
41 | * @param stepOperations a {@link RepeatOperations} instance. |
42 | */ |
43 | public void setStepOperations(RepeatOperations stepOperations) { |
44 | this.stepOperations = stepOperations; |
45 | } |
46 | |
47 | /** |
48 | * The {@link RepeatOperations} to use for the inner loop of the batch |
49 | * processing. should be set up by the caller through a factory. defaults to |
50 | * a plain {@link RepeatTemplate}. |
51 | * |
52 | * @param chunkOperations a {@link RepeatOperations} instance. |
53 | */ |
54 | public void setChunkOperations(RepeatOperations chunkOperations) { |
55 | this.chunkOperations = chunkOperations; |
56 | } |
57 | |
58 | /** |
59 | * @param step |
60 | * |
61 | */ |
62 | protected void applyConfiguration(ItemOrientedStep step) { |
63 | |
64 | super.applyConfiguration(step); |
65 | |
66 | RepeatOperations chunkOperations = BatchListenerFactoryHelper.addChunkListeners(this.chunkOperations, getListeners()); |
67 | |
68 | step.setChunkOperations(chunkOperations); |
69 | step.setStepOperations(stepOperations); |
70 | |
71 | } |
72 | |
73 | } |