View Javadoc

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.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  	@Override
69  	public void afterPropertiesSet() throws Exception {
70  		Assert.state(repositoryFactory != null, "A MapJobRepositoryFactoryBean must be provided");
71  		repositoryFactory.afterPropertiesSet();
72  	}
73  
74  	@Override
75  	protected JobExecutionDao createJobExecutionDao() throws Exception {
76  		return repositoryFactory.getJobExecutionDao();
77  	}
78  
79  	@Override
80  	protected JobInstanceDao createJobInstanceDao() throws Exception {
81  		return repositoryFactory.getJobInstanceDao();
82  	}
83  
84  	@Override
85  	protected StepExecutionDao createStepExecutionDao() throws Exception {
86  		return repositoryFactory.getStepExecutionDao();
87  	}
88  
89  	@Override
90  	protected ExecutionContextDao createExecutionContextDao() throws Exception {
91  		return repositoryFactory.getExecutionContextDao();
92  	}
93  
94  	@Override
95  	public Object getObject() throws Exception {
96  		return new SimpleJobExplorer(createJobInstanceDao(), createJobExecutionDao(), createStepExecutionDao(),
97  				createExecutionContextDao());
98  	}
99  
100 }