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.explore.support; |
18 | |
19 | import org.springframework.batch.core.repository.dao.ExecutionContextDao; |
20 | import org.springframework.batch.core.repository.dao.JobExecutionDao; |
21 | import org.springframework.batch.core.repository.dao.JobInstanceDao; |
22 | import org.springframework.batch.core.repository.dao.StepExecutionDao; |
23 | import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; |
24 | import org.springframework.beans.factory.FactoryBean; |
25 | import org.springframework.beans.factory.InitializingBean; |
26 | import org.springframework.util.Assert; |
27 | |
28 | /** |
29 | * A {@link FactoryBean} that automates the creation of a |
30 | * {@link SimpleJobExplorer} using in-memory DAO implementations. |
31 | * |
32 | * @author Dave Syer |
33 | * @since 2.0 |
34 | */ |
35 | public class MapJobExplorerFactoryBean extends AbstractJobExplorerFactoryBean implements InitializingBean { |
36 | |
37 | private MapJobRepositoryFactoryBean repositoryFactory; |
38 | |
39 | /** |
40 | * Create an instance with the provided {@link MapJobRepositoryFactoryBean} |
41 | * as a source of Dao instances. |
42 | * @param repositoryFactory |
43 | */ |
44 | public MapJobExplorerFactoryBean(MapJobRepositoryFactoryBean repositoryFactory) { |
45 | this.repositoryFactory = repositoryFactory; |
46 | } |
47 | |
48 | /** |
49 | * Create a factory with no {@link MapJobRepositoryFactoryBean}. It must be |
50 | * injected as a property. |
51 | */ |
52 | public MapJobExplorerFactoryBean() { |
53 | } |
54 | |
55 | /** |
56 | * The repository factory that can be used to create daos for the explorer. |
57 | * |
58 | * @param repositoryFactory a {@link MapJobExplorerFactoryBean} |
59 | */ |
60 | public void setRepositoryFactory(MapJobRepositoryFactoryBean repositoryFactory) { |
61 | this.repositoryFactory = repositoryFactory; |
62 | } |
63 | |
64 | /** |
65 | * @throws Exception |
66 | * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() |
67 | */ |
68 | public void afterPropertiesSet() throws Exception { |
69 | Assert.state(repositoryFactory != null, "A MapJobRepositoryFactoryBean must be provided"); |
70 | repositoryFactory.afterPropertiesSet(); |
71 | } |
72 | |
73 | @Override |
74 | protected JobExecutionDao createJobExecutionDao() throws Exception { |
75 | return repositoryFactory.getJobExecutionDao(); |
76 | } |
77 | |
78 | @Override |
79 | protected JobInstanceDao createJobInstanceDao() throws Exception { |
80 | return repositoryFactory.getJobInstanceDao(); |
81 | } |
82 | |
83 | @Override |
84 | protected StepExecutionDao createStepExecutionDao() throws Exception { |
85 | return repositoryFactory.getStepExecutionDao(); |
86 | } |
87 | |
88 | @Override |
89 | protected ExecutionContextDao createExecutionContextDao() throws Exception { |
90 | return repositoryFactory.getExecutionContextDao(); |
91 | } |
92 | |
93 | public Object getObject() throws Exception { |
94 | return new SimpleJobExplorer(createJobInstanceDao(), createJobExecutionDao(), createStepExecutionDao(), |
95 | createExecutionContextDao()); |
96 | } |
97 | |
98 | } |