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