Skip to content

Commit 0b4c270

Browse files
committed
Move unused methods in DefaultBatchConfiguration to its subclasses
While this creates some duplication (which can be avoided by introducing an intermediate base class), it removes the exposure of methods to clients who do not need/use them.
1 parent 7d269e9 commit 0b4c270

File tree

3 files changed

+66
-33
lines changed

3 files changed

+66
-33
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
package org.springframework.batch.core.configuration.support;
1717

1818
import org.springframework.batch.core.configuration.DuplicateJobException;
19-
import org.springframework.batch.core.job.DefaultJobKeyGenerator;
2019
import org.springframework.batch.core.job.Job;
21-
import org.springframework.batch.core.job.JobInstance;
22-
import org.springframework.batch.core.job.JobKeyGenerator;
2320
import org.springframework.batch.core.configuration.BatchConfigurationException;
2421
import org.springframework.batch.core.configuration.JobRegistry;
2522
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
@@ -39,7 +36,6 @@
3936
import org.springframework.core.task.SyncTaskExecutor;
4037
import org.springframework.core.task.TaskExecutor;
4138
import org.springframework.transaction.PlatformTransactionManager;
42-
import org.springframework.transaction.annotation.Isolation;
4339

4440
/**
4541
* Base {@link Configuration} class that provides common infrastructure beans for enabling
@@ -153,33 +149,4 @@ protected JobParametersConverter getJobParametersConverter() {
153149
return new DefaultJobParametersConverter();
154150
}
155151

156-
/**
157-
* Return the value of the {@code validateTransactionState} parameter. Defaults to
158-
* {@code true}.
159-
* @return true if the transaction state should be validated, false otherwise
160-
*/
161-
protected boolean getValidateTransactionState() {
162-
return true;
163-
}
164-
165-
/**
166-
* Return the transaction isolation level when creating job executions. Defaults to
167-
* {@link Isolation#SERIALIZABLE}.
168-
* @return the transaction isolation level when creating job executions
169-
*/
170-
protected Isolation getIsolationLevelForCreate() {
171-
return Isolation.SERIALIZABLE;
172-
}
173-
174-
/**
175-
* A custom implementation of the {@link JobKeyGenerator}. The default, if not
176-
* injected, is the {@link DefaultJobKeyGenerator}.
177-
* @return the generator that creates the key used in identifying {@link JobInstance}
178-
* objects
179-
* @since 5.1
180-
*/
181-
protected JobKeyGenerator getJobKeyGenerator() {
182-
return new DefaultJobKeyGenerator();
183-
}
184-
185152
}

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JdbcDefaultBatchConfiguration.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import org.springframework.batch.core.converter.StringToLocalDateConverter;
2525
import org.springframework.batch.core.converter.StringToLocalDateTimeConverter;
2626
import org.springframework.batch.core.converter.StringToLocalTimeConverter;
27+
import org.springframework.batch.core.job.DefaultJobKeyGenerator;
28+
import org.springframework.batch.core.job.JobInstance;
29+
import org.springframework.batch.core.job.JobKeyGenerator;
2730
import org.springframework.batch.core.launch.JobOperator;
2831
import org.springframework.batch.core.repository.ExecutionContextSerializer;
2932
import org.springframework.batch.core.repository.JobRepository;
@@ -45,6 +48,7 @@
4548
import org.springframework.jdbc.support.MetaDataAccessException;
4649
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
4750
import org.springframework.transaction.PlatformTransactionManager;
51+
import org.springframework.transaction.annotation.Isolation;
4852

4953
import javax.sql.DataSource;
5054
import java.nio.charset.Charset;
@@ -255,4 +259,33 @@ protected ConfigurableConversionService getConversionService() {
255259
return conversionService;
256260
}
257261

262+
/**
263+
* Return the value of the {@code validateTransactionState} parameter. Defaults to
264+
* {@code true}.
265+
* @return true if the transaction state should be validated, false otherwise
266+
*/
267+
protected boolean getValidateTransactionState() {
268+
return true;
269+
}
270+
271+
/**
272+
* Return the transaction isolation level when creating job executions. Defaults to
273+
* {@link Isolation#SERIALIZABLE}.
274+
* @return the transaction isolation level when creating job executions
275+
*/
276+
protected Isolation getIsolationLevelForCreate() {
277+
return Isolation.SERIALIZABLE;
278+
}
279+
280+
/**
281+
* A custom implementation of the {@link JobKeyGenerator}. The default, if not
282+
* injected, is the {@link DefaultJobKeyGenerator}.
283+
* @return the generator that creates the key used in identifying {@link JobInstance}
284+
* objects
285+
* @since 5.1
286+
*/
287+
protected JobKeyGenerator getJobKeyGenerator() {
288+
return new DefaultJobKeyGenerator();
289+
}
290+
258291
}

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/MongoDefaultBatchConfiguration.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
package org.springframework.batch.core.configuration.support;
1717

1818
import org.springframework.batch.core.configuration.BatchConfigurationException;
19+
import org.springframework.batch.core.job.DefaultJobKeyGenerator;
20+
import org.springframework.batch.core.job.JobInstance;
21+
import org.springframework.batch.core.job.JobKeyGenerator;
1922
import org.springframework.batch.core.launch.JobOperator;
2023
import org.springframework.batch.core.repository.JobRepository;
2124
import org.springframework.batch.core.repository.support.MongoJobRepositoryFactoryBean;
2225
import org.springframework.context.annotation.Bean;
2326
import org.springframework.context.annotation.Configuration;
2427
import org.springframework.data.mongodb.MongoTransactionManager;
2528
import org.springframework.data.mongodb.core.MongoOperations;
29+
import org.springframework.transaction.annotation.Isolation;
2630

2731
/**
2832
* Base {@link Configuration} class that provides common MongoDB-based infrastructure
@@ -115,4 +119,33 @@ protected MongoTransactionManager getTransactionManager() {
115119
return this.applicationContext.getBean("transactionManager", MongoTransactionManager.class);
116120
}
117121

122+
/**
123+
* Return the value of the {@code validateTransactionState} parameter. Defaults to
124+
* {@code true}.
125+
* @return true if the transaction state should be validated, false otherwise
126+
*/
127+
protected boolean getValidateTransactionState() {
128+
return true;
129+
}
130+
131+
/**
132+
* Return the transaction isolation level when creating job executions. Defaults to
133+
* {@link Isolation#SERIALIZABLE}.
134+
* @return the transaction isolation level when creating job executions
135+
*/
136+
protected Isolation getIsolationLevelForCreate() {
137+
return Isolation.SERIALIZABLE;
138+
}
139+
140+
/**
141+
* A custom implementation of the {@link JobKeyGenerator}. The default, if not
142+
* injected, is the {@link DefaultJobKeyGenerator}.
143+
* @return the generator that creates the key used in identifying {@link JobInstance}
144+
* objects
145+
* @since 5.1
146+
*/
147+
protected JobKeyGenerator getJobKeyGenerator() {
148+
return new DefaultJobKeyGenerator();
149+
}
150+
118151
}

0 commit comments

Comments
 (0)