001/* 002 * Copyright 2018 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.integration.partition; 018 019import org.springframework.batch.core.explore.JobExplorer; 020import org.springframework.batch.core.repository.JobRepository; 021import org.springframework.beans.BeansException; 022import org.springframework.beans.factory.BeanFactory; 023import org.springframework.beans.factory.BeanFactoryAware; 024import org.springframework.transaction.PlatformTransactionManager; 025 026/** 027 * Convenient factory for a {@link RemotePartitioningMasterStepBuilder} which sets 028 * the {@link JobRepository}, {@link JobExplorer}, {@link BeanFactory} and 029 * {@link PlatformTransactionManager} automatically. 030 * 031 * @since 4.1 032 * @author Mahmoud Ben Hassine 033 */ 034public class RemotePartitioningMasterStepBuilderFactory implements BeanFactoryAware { 035 036 private BeanFactory beanFactory; 037 final private JobExplorer jobExplorer; 038 final private JobRepository jobRepository; 039 final private PlatformTransactionManager transactionManager; 040 041 042 /** 043 * Create a new {@link RemotePartitioningMasterStepBuilderFactory}. 044 * @param jobRepository the job repository to use 045 * @param jobExplorer the job explorer to use 046 * @param transactionManager the transaction manager to use 047 */ 048 public RemotePartitioningMasterStepBuilderFactory(JobRepository jobRepository, 049 JobExplorer jobExplorer, PlatformTransactionManager transactionManager) { 050 051 this.jobRepository = jobRepository; 052 this.jobExplorer = jobExplorer; 053 this.transactionManager = transactionManager; 054 } 055 056 @Override 057 public void setBeanFactory(BeanFactory beanFactory) throws BeansException { 058 this.beanFactory = beanFactory; 059 } 060 061 /** 062 * Creates a {@link RemotePartitioningMasterStepBuilder} and initializes its job 063 * repository, job explorer, bean factory and transaction manager. 064 * @param name the name of the step 065 * @return a {@link RemotePartitioningMasterStepBuilder} 066 */ 067 public RemotePartitioningMasterStepBuilder get(String name) { 068 return new RemotePartitioningMasterStepBuilder(name) 069 .repository(this.jobRepository) 070 .jobExplorer(this.jobExplorer) 071 .beanFactory(this.beanFactory) 072 .transactionManager(this.transactionManager); 073 } 074 075}