Java Code Examples for org.springframework.batch.core.repository.support.JobRepositoryFactoryBean#getObject()

The following examples show how to use org.springframework.batch.core.repository.support.JobRepositoryFactoryBean#getObject() . 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 File: TaskExecutorBatchConfiguration.java    From spring-boot-starter-batch-web with Apache License 2.0 6 votes vote down vote up
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 2
Source File: CsvBatchConfig.java    From Demo with 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 3
Source File: SpringBatchConfiguration.java    From spring-cloud with 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 4
Source File: MyBatchConfig.java    From SpringBootBucket with 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 5
Source File: BatchConfiguration.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@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 6
Source File: BatchConfiguration.java    From patient-batch-loader with GNU General Public License v3.0 5 votes vote down vote up
protected JobRepository createJobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(this.batchDataSource);
    factory.setTransactionManager(getTransactionManager());
    factory.afterPropertiesSet();
    return factory.getObject();
}
 
Example 7
Source File: BatchConfigurer.java    From CogStack-Pipeline with 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 8
Source File: JobCommandTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
	Thread.sleep(2000);
	DataSource dataSource = applicationContext.getBean(DataSource.class);
	taskBatchDao = new JdbcTaskBatchDao(dataSource);
	JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
	repositoryFactoryBean.setDataSource(dataSource);
	repositoryFactoryBean.setTransactionManager(new DataSourceTransactionManager(dataSource));
	jobRepository = repositoryFactoryBean.getObject();
	TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean = new TaskExecutionDaoFactoryBean(dataSource);
	dao = taskExecutionDaoFactoryBean.getObject();
	taskExecutionIds.add(createSampleJob(JOB_NAME_ORIG, 1));
	taskExecutionIds.add(createSampleJob(JOB_NAME_FOO, 1));
	taskExecutionIds.add(createSampleJob(JOB_NAME_FOOBAR, 2));
}
 
Example 9
Source File: JobInstancesDocumentation.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void initialize() throws Exception {
	JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
	repositoryFactoryBean.setDataSource(this.dataSource);
	repositoryFactoryBean.setTransactionManager(new DataSourceTransactionManager(this.dataSource));
	this.jobRepository = repositoryFactoryBean.getObject();
	this.dao = (new TaskExecutionDaoFactoryBean(this.dataSource)).getObject();
	this.taskBatchDao = new JdbcTaskBatchDao(this.dataSource);
}
 
Example 10
Source File: JobStepExecutionsDocumentation.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void initialize() throws Exception {
	JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
	repositoryFactoryBean.setDataSource(this.dataSource);
	repositoryFactoryBean.setTransactionManager(new DataSourceTransactionManager(this.dataSource));
	this.jobRepository = repositoryFactoryBean.getObject();
	this.dao = (new TaskExecutionDaoFactoryBean(this.dataSource)).getObject();
	this.taskBatchDao = new JdbcTaskBatchDao(this.dataSource);
}
 
Example 11
Source File: JobExecutionsDocumentation.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void initialize() throws Exception {
	JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
	repositoryFactoryBean.setDataSource(this.dataSource);
	repositoryFactoryBean.setTransactionManager(new DataSourceTransactionManager(this.dataSource));
	this.jobRepository = repositoryFactoryBean.getObject();
	this.dao = (new TaskExecutionDaoFactoryBean(this.dataSource)).getObject();
	this.taskBatchDao = new JdbcTaskBatchDao(this.dataSource);
}
 
Example 12
Source File: DefaultSpringBatchLightminBatchConfigurer.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
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 13
Source File: SpringbatchPartitionConfig.java    From tutorials with 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 14
Source File: SpringConfig.java    From tutorials with 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 15
Source File: JpaBatchConfigurer.java    From spring4-sandbox with 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();
}