001/* 002 * Copyright 2006-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.core.repository.support; 018 019import org.springframework.batch.core.repository.dao.ExecutionContextDao; 020import org.springframework.batch.core.repository.dao.JobExecutionDao; 021import org.springframework.batch.core.repository.dao.JobInstanceDao; 022import org.springframework.batch.core.repository.dao.MapExecutionContextDao; 023import org.springframework.batch.core.repository.dao.MapJobExecutionDao; 024import org.springframework.batch.core.repository.dao.MapJobInstanceDao; 025import org.springframework.batch.core.repository.dao.MapStepExecutionDao; 026import org.springframework.batch.core.repository.dao.StepExecutionDao; 027import org.springframework.batch.support.transaction.ResourcelessTransactionManager; 028import org.springframework.beans.factory.FactoryBean; 029import org.springframework.transaction.PlatformTransactionManager; 030 031/** 032 * A {@link FactoryBean} that automates the creation of a 033 * {@link SimpleJobRepository} using non-persistent in-memory DAO 034 * implementations. This repository is only really intended for use in testing 035 * and rapid prototyping. In such settings you might find that 036 * {@link ResourcelessTransactionManager} is useful (as long as your business 037 * logic does not use a relational database). Not suited for use in 038 * multi-threaded jobs with splits, although it should be safe to use in a 039 * multi-threaded step. 040 * 041 * @author Robert Kasanicky 042 */ 043public class MapJobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean { 044 045 private MapJobExecutionDao jobExecutionDao; 046 047 private MapJobInstanceDao jobInstanceDao; 048 049 private MapStepExecutionDao stepExecutionDao; 050 051 private MapExecutionContextDao executionContextDao; 052 053 /** 054 * Create a new instance with a {@link ResourcelessTransactionManager}. 055 */ 056 public MapJobRepositoryFactoryBean() { 057 this(new ResourcelessTransactionManager()); 058 } 059 060 /** 061 * Create a new instance with the provided transaction manager. 062 * 063 * @param transactionManager {@link org.springframework.transaction.PlatformTransactionManager} 064 */ 065 public MapJobRepositoryFactoryBean(PlatformTransactionManager transactionManager) { 066 setTransactionManager(transactionManager); 067 } 068 069 public JobExecutionDao getJobExecutionDao() { 070 return jobExecutionDao; 071 } 072 073 public JobInstanceDao getJobInstanceDao() { 074 return jobInstanceDao; 075 } 076 077 public StepExecutionDao getStepExecutionDao() { 078 return stepExecutionDao; 079 } 080 081 public ExecutionContextDao getExecutionContextDao() { 082 return executionContextDao; 083 } 084 085 /** 086 * Convenience method to clear all the map DAOs globally, removing all 087 * entities. 088 */ 089 public void clear() { 090 jobInstanceDao.clear(); 091 jobExecutionDao.clear(); 092 stepExecutionDao.clear(); 093 executionContextDao.clear(); 094 } 095 096 @Override 097 protected JobExecutionDao createJobExecutionDao() throws Exception { 098 jobExecutionDao = new MapJobExecutionDao(); 099 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}