| 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.repository.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.MapExecutionContextDao; |
| 23 | import org.springframework.batch.core.repository.dao.MapJobExecutionDao; |
| 24 | import org.springframework.batch.core.repository.dao.MapJobInstanceDao; |
| 25 | import org.springframework.batch.core.repository.dao.MapStepExecutionDao; |
| 26 | import org.springframework.batch.core.repository.dao.StepExecutionDao; |
| 27 | import org.springframework.batch.support.transaction.ResourcelessTransactionManager; |
| 28 | import org.springframework.beans.factory.FactoryBean; |
| 29 | import org.springframework.transaction.PlatformTransactionManager; |
| 30 | |
| 31 | /** |
| 32 | * A {@link FactoryBean} that automates the creation of a |
| 33 | * {@link SimpleJobRepository} using non-persistent in-memory DAO |
| 34 | * implementations. This repository is only really intended for use in testing |
| 35 | * and rapid prototyping. In such settings you might find that |
| 36 | * {@link ResourcelessTransactionManager} is useful (as long as your business |
| 37 | * logic does not use a relational database). Not suited for use in |
| 38 | * multi-threaded jobs with splits, although it should be safe to use in a |
| 39 | * multi-threaded step. |
| 40 | * |
| 41 | * @author Robert Kasanicky |
| 42 | */ |
| 43 | public class MapJobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean { |
| 44 | |
| 45 | private MapJobExecutionDao jobExecutionDao; |
| 46 | |
| 47 | private MapJobInstanceDao jobInstanceDao; |
| 48 | |
| 49 | private MapStepExecutionDao stepExecutionDao; |
| 50 | |
| 51 | private MapExecutionContextDao executionContextDao; |
| 52 | |
| 53 | /** |
| 54 | * Create a new instance with a {@link ResourcelessTransactionManager}. |
| 55 | */ |
| 56 | public MapJobRepositoryFactoryBean() { |
| 57 | this(new ResourcelessTransactionManager()); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Create a new instance with the provided transaction manager. |
| 62 | * |
| 63 | * @param transactionManager |
| 64 | */ |
| 65 | public MapJobRepositoryFactoryBean(PlatformTransactionManager transactionManager) { |
| 66 | setTransactionManager(transactionManager); |
| 67 | } |
| 68 | |
| 69 | public JobExecutionDao getJobExecutionDao() { |
| 70 | return jobExecutionDao; |
| 71 | } |
| 72 | |
| 73 | public JobInstanceDao getJobInstanceDao() { |
| 74 | return jobInstanceDao; |
| 75 | } |
| 76 | |
| 77 | public StepExecutionDao getStepExecutionDao() { |
| 78 | return stepExecutionDao; |
| 79 | } |
| 80 | |
| 81 | public ExecutionContextDao getExecutionContextDao() { |
| 82 | return executionContextDao; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Convenience method to clear all the map daos globally, removing all |
| 87 | * entities. |
| 88 | */ |
| 89 | public void clear() { |
| 90 | jobInstanceDao.clear(); |
| 91 | jobExecutionDao.clear(); |
| 92 | stepExecutionDao.clear(); |
| 93 | executionContextDao.clear(); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | protected JobExecutionDao createJobExecutionDao() throws Exception { |
| 98 | jobExecutionDao = new MapJobExecutionDao(); |
| 99 | return jobExecutionDao; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | protected JobInstanceDao createJobInstanceDao() throws Exception { |
| 104 | jobInstanceDao = new MapJobInstanceDao(); |
| 105 | return jobInstanceDao; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | protected StepExecutionDao createStepExecutionDao() throws Exception { |
| 110 | stepExecutionDao = new MapStepExecutionDao(); |
| 111 | return stepExecutionDao; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | protected ExecutionContextDao createExecutionContextDao() throws Exception { |
| 116 | executionContextDao = new MapExecutionContextDao(); |
| 117 | return executionContextDao; |
| 118 | } |
| 119 | |
| 120 | } |