Skip to content

Commit adae2e1

Browse files
committed
Polish "Allow to configure validateTransactionState for Spring Batch"
See gh-44803
1 parent f4a9236 commit adae2e1

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ protected String getTablePrefix() {
143143

144144
@Override
145145
protected boolean getValidateTransactionState() {
146-
Boolean validateTransactionState = this.properties.getJdbc().getValidateTransactionState();
147-
return (validateTransactionState != null) ? validateTransactionState : super.getValidateTransactionState();
146+
return this.properties.getJdbc().isValidateTransactionState();
148147
}
149148

150149
@Override

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchProperties.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static class Jdbc {
7171
/**
7272
* Whether to validate the transaction state.
7373
*/
74-
private Boolean validateTransactionState;
74+
private boolean validateTransactionState = true;
7575

7676
/**
7777
* Transaction isolation level to use when creating job meta-data for new jobs.
@@ -99,7 +99,7 @@ public static class Jdbc {
9999
*/
100100
private DatabaseInitializationMode initializeSchema = DatabaseInitializationMode.EMBEDDED;
101101

102-
public Boolean getValidateTransactionState() {
102+
public boolean isValidateTransactionState() {
103103
return this.validateTransactionState;
104104
}
105105

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.batch;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Tests for {@link BatchProperties}.
27+
*
28+
* @author Andy Wilkinson
29+
*/
30+
class BatchPropertiesTests {
31+
32+
@Test
33+
void validateTransactionStateDefaultMatchesSpringBatchDefault() {
34+
assertThat(new BatchProperties().getJdbc().isValidateTransactionState())
35+
.isEqualTo(new TestBatchConfiguration().getValidateTransactionState());
36+
}
37+
38+
static class TestBatchConfiguration extends DefaultBatchConfiguration {
39+
40+
@Override
41+
public boolean getValidateTransactionState() {
42+
return super.getValidateTransactionState();
43+
}
44+
45+
}
46+
47+
}

0 commit comments

Comments
 (0)