| 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 | |
| 30 | /** |
| 31 | * A {@link FactoryBean} that automates the creation of a |
| 32 | * {@link SimpleJobRepository} using non-persistent in-memory DAO |
| 33 | * implementations. This repository is only really intended for use in testing |
| 34 | * and rapid prototyping. In such settings you might find that |
| 35 | * {@link ResourcelessTransactionManager} is useful (as long as your business |
| 36 | * logic does not use a relational database). Not suited for use in |
| 37 | * multi-threaded jobs with splits, although it should be safe to use in a |
| 38 | * multi-threaded step. |
| 39 | * |
| 40 | * @author Robert Kasanicky |
| 41 | */ |
| 42 | public class MapJobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean { |
| 43 | |
| 44 | /** |
| 45 | * Convenience method to clear all the map daos globally, removing all |
| 46 | * entities. |
| 47 | */ |
| 48 | public static void clear() { |
| 49 | MapJobInstanceDao.clear(); |
| 50 | MapJobExecutionDao.clear(); |
| 51 | MapStepExecutionDao.clear(); |
| 52 | MapExecutionContextDao.clear(); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected JobExecutionDao createJobExecutionDao() throws Exception { |
| 57 | return new MapJobExecutionDao(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected JobInstanceDao createJobInstanceDao() throws Exception { |
| 62 | return new MapJobInstanceDao(); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected StepExecutionDao createStepExecutionDao() throws Exception { |
| 67 | return new MapStepExecutionDao(); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | protected ExecutionContextDao createExecutionContextDao() throws Exception { |
| 72 | return new MapExecutionContextDao(); |
| 73 | } |
| 74 | |
| 75 | } |