Skip to content

BATCH-2294: Don't replace my PlatformTransactionManager with a new one #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ public class DefaultBatchConfigurer implements BatchConfigurer {

/**
* Sets the dataSource. If the {@link DataSource} has been set once, all future
* values are passed are ignored (to prevent {@code}@Autowired{@code} from overwriting
* values passed in are ignored (to prevent {@code}@Autowired{@code} from overwriting
* the value).
*
* @param dataSource
Expand All @@ -58,9 +58,19 @@ public void setDataSource(DataSource dataSource) {
if(this.dataSource == null) {
this.dataSource = dataSource;
}
}

/**
* Sets the transactionManager. If the {@link PlatformTransactionManager} has been set
* once, all future values passed in are ignored (to prevent {@code}@Autowired{@code}
* from overwriting the value).
*
* @param transactionManager
*/
@Autowired(required = false)
public void setTransactionManager(PlatformTransactionManager transactionManager) {
if(this.transactionManager == null) {
this.transactionManager = new DataSourceTransactionManager(this.dataSource);
this.transactionManager = transactionManager;
}
}

Expand Down Expand Up @@ -93,12 +103,18 @@ public JobExplorer getJobExplorer() {
@PostConstruct
public void initialize() {
try {
if(dataSource == null) {
logger.warn("No datasource was provided...using a Map based JobRepository");

if(this.transactionManager == null) {
if(this.transactionManager == null) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatting seems inconsistent with the Spring Framework Code Style. There should be a space between "if" and the paren. I mimicked what was already in the file because I felt it would be weird to mix the style within a single file. I'm happy to fix the formatting if you'd like me to, but I want to make sure the approach I took is acceptable before I go to that effort.

if (dataSource == null) {
logger.info("No transactionManager was provided, no dataSource either... generating a ResourcelessTransactionManager");
this.transactionManager = new ResourcelessTransactionManager();
} else {
logger.info("No transactionManager was provided, but we have a dataSource... generating a DataSourceTransactionManager");
this.transactionManager = new DataSourceTransactionManager(dataSource);
}
}

if(dataSource == null) {
logger.warn("No datasource was provided...using a Map based JobRepository");

MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(this.transactionManager);
jobRepositoryFactory.afterPropertiesSet();
Expand Down