Java Code Examples for org.springframework.batch.core.repository.JobRepository

The following examples show how to use org.springframework.batch.core.repository.JobRepository. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-cloud-dataflow   Source File: SimpleJobService.java    License: Apache License 2.0 6 votes vote down vote up
public SimpleJobService(SearchableJobInstanceDao jobInstanceDao, SearchableJobExecutionDao jobExecutionDao,
		SearchableStepExecutionDao stepExecutionDao, JobRepository jobRepository,
		ExecutionContextDao executionContextDao, JobOperator jsrJobOperator) {
	super();
	this.jobInstanceDao = jobInstanceDao;
	this.jobExecutionDao = jobExecutionDao;
	this.stepExecutionDao = stepExecutionDao;
	this.jobRepository = jobRepository;
	this.executionContextDao = executionContextDao;

	if (jsrJobOperator == null) {
		logger.warn("No JobOperator compatible with JSR-352 was provided.");
	}
	else {
		this.jsrJobOperator = jsrJobOperator;
	}
}
 
Example 2
Source Project: spring-cloud-dataflow   Source File: JobExecutionUtils.java    License: Apache License 2.0 6 votes vote down vote up
static MockMvc createBaseJobExecutionMockMvc(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, WebApplicationContext wac, RequestMappingHandlerAdapter adapter) {
	MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac)
			.defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)).build();
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_ORIG, 1);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FOO, 1);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FOOBAR, 2);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_COMPLETED, 1, BatchStatus.COMPLETED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_STARTED, 1, BatchStatus.STARTED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_STOPPED, 1, BatchStatus.STOPPED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FAILED1, 1, BatchStatus.FAILED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FAILED2, 1, BatchStatus.FAILED);
	for (HttpMessageConverter<?> converter : adapter.getMessageConverters()) {
		if (converter instanceof MappingJackson2HttpMessageConverter) {
			final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
			jacksonConverter.getObjectMapper().addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class);
			jacksonConverter.getObjectMapper().addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class);
			jacksonConverter.getObjectMapper().setDateFormat(new ISO8601DateFormatWithMilliSeconds());
		}
	}
	return mockMvc;
}
 
Example 3
Source Project: spring-cloud-dataflow   Source File: JobExecutionUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, String jobName,
		int jobExecutionCount, BatchStatus status) {
	JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
	TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution;

	for (int i = 0; i < jobExecutionCount; i++) {
		jobExecution = jobRepository.createJobExecution(instance, new JobParameters(), null);
		StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L);
		stepExecution.setId(null);
		jobRepository.add(stepExecution);
		taskBatchDao.saveRelationship(taskExecution, jobExecution);
		jobExecution.setStatus(status);
		jobExecution.setStartTime(new Date());
		if (BatchStatus.STOPPED.equals(status)) {
			jobExecution.setEndTime(new Date());
		}
		jobRepository.update(jobExecution);
	}
}
 
Example 4
private void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, String jobName,
		int jobExecutionCount, BatchStatus status) {
	JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
	TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution;

	for (int i = 0; i < jobExecutionCount; i++) {
		jobExecution = jobRepository.createJobExecution(instance,
				this.jobParameters, null);
		StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L);
		stepExecution.setId(null);
		jobRepository.add(stepExecution);
		taskBatchDao.saveRelationship(taskExecution, jobExecution);
		jobExecution.setStatus(status);
		jobExecution.setStartTime(new Date());
		jobRepository.update(jobExecution);
	}
}
 
Example 5
public TaskJobLauncherCommandLineRunnerFactoryBean(JobLauncher jobLauncher,
		JobExplorer jobExplorer, List<Job> jobs,
		TaskBatchProperties taskBatchProperties, JobRegistry jobRegistry,
		JobRepository jobRepository, BatchProperties batchProperties) {
	Assert.notNull(taskBatchProperties, "taskBatchProperties must not be null");
	Assert.notNull(batchProperties, "batchProperties must not be null");
	this.jobLauncher = jobLauncher;
	this.jobExplorer = jobExplorer;
	Assert.notEmpty(jobs, "jobs must not be null nor empty");
	this.jobs = jobs;
	this.jobNames = taskBatchProperties.getJobNames();
	this.jobRegistry = jobRegistry;
	this.taskBatchProperties = taskBatchProperties;
	if (StringUtils.hasText(batchProperties.getJob().getNames())) {
		this.jobNames = batchProperties.getJob().getNames();
	}
	else {
		this.jobNames = taskBatchProperties.getJobNames();
	}
	this.order = taskBatchProperties.getCommandLineRunnerOrder();
	this.jobRepository = jobRepository;
}
 
Example 6
protected JobRepository createJobRepository() throws Exception {
	JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
	factory.setDataSource(dataSource);
	factory.setTransactionManager(transactionManager);
	factory.setSerializer(serializer);
	String isolationLevelForCreate = batchConfig.getRepository().getIsolationLevelForCreate();
	if (isolationLevelForCreate != null) {
		factory.setIsolationLevelForCreate(isolationLevelForCreate);
	}
	String tablePrefix = batchConfig.getRepository().getTablePrefix();
	if (tablePrefix != null) {
		factory.setTablePrefix(tablePrefix);
	}
	factory.afterPropertiesSet();
	return factory.getObject();
}
 
Example 7
Source Project: Demo   Source File: CsvBatchConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public JobRepository jobRepository(DataSource dataSource, PlatformTransactionManager transactionManager)
        throws Exception {
    JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
    jobRepositoryFactoryBean.setDataSource(dataSource);
    jobRepositoryFactoryBean.setTransactionManager(transactionManager);
    jobRepositoryFactoryBean.setDatabaseType("mysql");
    return jobRepositoryFactoryBean.getObject();
}
 
Example 8
Source Project: spring-graalvm-native   Source File: BatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(JobOperator.class)
public JobOperator jobOperator(ObjectProvider<JobParametersConverter> jobParametersConverter,
		JobExplorer jobExplorer, JobLauncher jobLauncher, ListableJobLocator jobRegistry,
		JobRepository jobRepository) throws Exception {
	System.out.println("FOOBAR");
	SimpleJobOperator factory = new SimpleJobOperator();
	factory.setJobExplorer(jobExplorer);
	factory.setJobLauncher(jobLauncher);
	factory.setJobRegistry(jobRegistry);
	factory.setJobRepository(jobRepository);
	jobParametersConverter.ifAvailable(factory::setJobParametersConverter);
	return factory;
}
 
Example 9
Source Project: spring-cloud   Source File: SpringBatchConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
protected JobRepository createJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setIsolationLevelForCreate("ISOLATION_SERIALIZABLE");
    factory.setDataSource(dataSource);
    factory.setTransactionManager(transactionManager);
    factory.setValidateTransactionState(false);
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 10
Source Project: SpringBootBucket   Source File: MyBatchConfig.java    License: MIT License 5 votes vote down vote up
/**
 * JobRepository,用来注册Job的容器
 * jobRepositor的定义需要dataSource和transactionManager,Spring Boot已为我们自动配置了
 * 这两个类,Spring可通过方法注入已有的Bean
 *
 * @param dataSource
 * @param transactionManager
 * @return
 * @throws Exception
 */
@Bean
public JobRepository jobRepository(DruidDataSource dataSource, PlatformTransactionManager transactionManager) throws Exception {
    JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
    jobRepositoryFactoryBean.setDataSource(dataSource);
    jobRepositoryFactoryBean.setTransactionManager(transactionManager);
    jobRepositoryFactoryBean.setDatabaseType(String.valueOf(DatabaseType.ORACLE));
    jobRepositoryFactoryBean.setMaxVarCharLength(5000);
    // 下面事务隔离级别的配置是针对Oracle的
    jobRepositoryFactoryBean.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
    jobRepositoryFactoryBean.afterPropertiesSet();
    return jobRepositoryFactoryBean.getObject();
}
 
Example 11
Source Project: spring-batch-rest   Source File: AdHocStarter.java    License: Apache License 2.0 5 votes vote down vote up
public AdHocStarter(JobLocator jobLocator, JobRepository jobRepository, JobPropertyResolvers jobPropertyResolvers,
                    @Value("${com.github.chrisgleissner.springbatchrest.addUniqueJobParameter:true}") boolean addUniqueJobParameter,
                    JobRegistry jobRegistry) {
    this.jobLocator = jobLocator;
    asyncJobLauncher = jobLauncher(new SimpleAsyncTaskExecutor(), jobRepository);
    syncJobLauncher = jobLauncher(new SyncTaskExecutor(), jobRepository);
    this.jobPropertyResolvers = jobPropertyResolvers;
    this.addUniqueJobParameter = addUniqueJobParameter;
    this.jobRegistry = jobRegistry;
    log.info("Adding unique job parameter: {}", addUniqueJobParameter);
}
 
Example 12
@Bean
BatchConfigurer myBatchConfigurer(DataSource dataSource,
		Jackson2ExecutionContextStringSerializer myJackson2ExecutionContextStringSerializer,
		PlatformTransactionManager transactionManager) {
	return new DefaultBatchConfigurer(dataSource) {
		@Override
		protected JobExplorer createJobExplorer() throws Exception {
			JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
			jobExplorerFactoryBean.setDataSource(dataSource);
			jobExplorerFactoryBean
					.setSerializer(myJackson2ExecutionContextStringSerializer);
			jobExplorerFactoryBean.afterPropertiesSet();
			return jobExplorerFactoryBean.getObject();
		}

		@Override
		protected JobRepository createJobRepository() throws Exception {
			JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
			jobRepositoryFactoryBean.setDataSource(dataSource);
			jobRepositoryFactoryBean
					.setSerializer(myJackson2ExecutionContextStringSerializer);
			jobRepositoryFactoryBean.setTransactionManager(transactionManager);
			jobRepositoryFactoryBean.afterPropertiesSet();
			return jobRepositoryFactoryBean.getObject();
		}
	};
}
 
Example 13
protected JobRepository createJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(this.batchDataSource);
    factory.setTransactionManager(getTransactionManager());
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 14
Source Project: CogStack-Pipeline   Source File: BatchConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected JobRepository createJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(jobRepositoryDataSource);
    factory.setTransactionManager(getTransactionManager());
    //to avoid deadlocks on the Job repo in SQL SERVER 2008
    factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ");
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 15
public DefaultSchedulerService(final BeanRegistrar beanRegistrar,
                               final JobRepository jobRepository,
                               final JobRegistry jobRegistry) {
    this.beanRegistrar = beanRegistrar;
    this.jobRepository = jobRepository;
    this.jobRegistry = jobRegistry;
}
 
Example 16
@Bean
@ConditionalOnMissingBean(value = {SchedulerService.class})
public SchedulerService schedulerService(final BeanRegistrar beanRegistrar,
                                         final JobRepository jobRepository,
                                         final JobRegistry jobRegistry) {
    return new DefaultSchedulerService(beanRegistrar, jobRepository, jobRegistry);
}
 
Example 17
@Bean
@ConditionalOnMissingBean(value = {ListenerService.class})
public ListenerService listenerService(final BeanRegistrar beanRegistrar,
                                       final JobRegistry jobRegistry,
                                       final JobRepository jobRepository) {
    return new DefaultListenerService(beanRegistrar, jobRegistry, jobRepository);
}
 
Example 18
protected JobRepository createJobRepository() throws Exception {
    final JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
    jobRepositoryFactoryBean.setDataSource(this.dataSource);
    jobRepositoryFactoryBean.setTransactionManager(this.transactionManager);
    jobRepositoryFactoryBean.setTablePrefix(this.tablePrefix);
    jobRepositoryFactoryBean.afterPropertiesSet();
    return jobRepositoryFactoryBean.getObject();
}
 
Example 19
@Bean(name = "defaultAsyncJobLauncher")
public JobLauncher defaultAsyncJobLauncher(final JobRepository jobRepository) {
    final SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    jobLauncher.setJobRepository(jobRepository);
    jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
    return jobLauncher;
}
 
Example 20
/**
 * Create a new {@link TaskJobLauncherCommandLineRunner}.
 * @param jobLauncher to launch jobs
 * @param jobExplorer to check the job repository for previous executions
 * @param jobRepository to check if a job instance exists with the given parameters
 * when running a job
 * @param taskBatchProperties the properties used to configure the
 * taskBatchProperties.
 */
public TaskJobLauncherCommandLineRunner(JobLauncher jobLauncher,
		JobExplorer jobExplorer, JobRepository jobRepository,
		TaskBatchProperties taskBatchProperties) {
	super(jobLauncher, jobExplorer, jobRepository);
	this.taskJobLauncher = jobLauncher;
	this.taskJobExplorer = jobExplorer;
	this.taskJobRepository = jobRepository;
	this.taskBatchProperties = taskBatchProperties;
}
 
Example 21
public DeployerStepExecutionHandler(BeanFactory beanFactory, JobExplorer jobExplorer,
		JobRepository jobRepository) {
	Assert.notNull(beanFactory, "A beanFactory is required");
	Assert.notNull(jobExplorer, "A jobExplorer is required");
	Assert.notNull(jobRepository, "A jobRepository is required");

	this.stepLocator = new BeanFactoryStepLocator();
	((BeanFactoryStepLocator) this.stepLocator).setBeanFactory(beanFactory);

	this.jobExplorer = jobExplorer;
	this.jobRepository = jobRepository;
}
 
Example 22
@Bean
public TaskJobLauncherCommandLineRunnerFactoryBean jobLauncherCommandLineRunner(
		JobLauncher jobLauncher, JobExplorer jobExplorer, List<Job> jobs,
		JobRegistry jobRegistry, JobRepository jobRepository,
		BatchProperties batchProperties) {
	TaskJobLauncherCommandLineRunnerFactoryBean taskJobLauncherCommandLineRunnerFactoryBean;
	taskJobLauncherCommandLineRunnerFactoryBean = new TaskJobLauncherCommandLineRunnerFactoryBean(
			jobLauncher, jobExplorer, jobs, this.properties, jobRegistry,
			jobRepository, batchProperties);

	return taskJobLauncherCommandLineRunnerFactoryBean;
}
 
Example 23
private void validateConstructorValidation(BeanFactory beanFactory,
		JobExplorer jobExplorer, JobRepository jobRepository, String message) {
	try {
		new DeployerStepExecutionHandler(beanFactory, jobExplorer, jobRepository);
	}
	catch (IllegalArgumentException iae) {
		assertThat(iae.getMessage()).isEqualTo(message);
	}
}
 
Example 24
public JobOperationsController(JobOperator jobOperator, JobExplorer jobExplorer, JobRegistry jobRegistry,
		JobRepository jobRepository, JobLauncher jobLauncher, JsrJobOperator jsrJobOperator) {
	super();
	this.jobOperator = jobOperator;
	this.jobExplorer = jobExplorer;
	this.jobRegistry = jobRegistry;
	this.jobRepository = jobRepository;
	this.jobLauncher = jobLauncher;
	this.jsrJobOperator = jsrJobOperator;
}
 
Example 25
public CustomJsrJobOperator(JobExplorer jobExplorer, JobRepository jobRepository,
		JobParametersConverter jobParametersConverter, AddListenerToJobService addListenerToJobService,
		PlatformTransactionManager transactionManager) {
	super(jobExplorer, jobRepository, jobParametersConverter, transactionManager);
	this.jobRepository = jobRepository;
	this.jobParametersConverter = jobParametersConverter;
	this.addListenerToJobService = addListenerToJobService;
}
 
Example 26
Source Project: tutorials   Source File: SpringbatchPartitionConfig.java    License: MIT License 5 votes vote down vote up
private JobRepository getJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(dataSource());
    factory.setTransactionManager(getTransactionManager());
    // JobRepositoryFactoryBean's methods Throws Generic Exception,
    // it would have been better to have a specific one
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 27
Source Project: tutorials   Source File: SpringConfig.java    License: MIT License 5 votes vote down vote up
private JobRepository getJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(dataSource());
    factory.setTransactionManager(getTransactionManager());
    // JobRepositoryFactoryBean's methods Throws Generic Exception,
    // it would have been better to have a specific one
    factory.afterPropertiesSet();
    return (JobRepository) factory.getObject();
}
 
Example 28
Source Project: spring4-sandbox   Source File: JpaBatchConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
protected JobRepository createJobRepository() throws Exception {
	JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
	factory.setIsolationLevelForCreate("ISOLATION_SERIALIZABLE");
	factory.setDataSource(dataSource);
	factory.setTransactionManager(transactionManager);
	factory.setValidateTransactionState(false);
	factory.afterPropertiesSet();
	return factory.getObject();
}
 
Example 29
Source Project: spring-cloud   Source File: SpringBatchConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Bean
public JobRepository getJobRepository() {
    return jobRepository;
}
 
Example 30
Source Project: spring-cloud   Source File: SpringBatchConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public JobBuilderFactory jobBuilderFactory(JobRepository jobRepository) {
    return new JobBuilderFactory(jobRepository);
}