Polish "Add BatchTransactionManager annotation"
See gh-39473
This commit is contained in:
parent
bb87faf237
commit
22952c3057
|
@ -27,10 +27,9 @@ import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Qualifier annotation for a {@link PlatformTransactionManager
|
* Qualifier annotation for a {@link PlatformTransactionManager} to be injected into Batch
|
||||||
* PlatformTransactionManager} to be injected into Batch auto-configuration. Can be used
|
* auto-configuration. Can be used on a secondary {@link PlatformTransactionManager}, if
|
||||||
* on a secondary {@link PlatformTransactionManager PlatformTransactionManager}, if there
|
* there is another one marked as {@link Primary @Primary}.
|
||||||
* is another one marked as {@link Primary @Primary}.
|
|
||||||
*
|
*
|
||||||
* @author Lasse Wulff
|
* @author Lasse Wulff
|
||||||
* @since 3.3.0
|
* @since 3.3.0
|
||||||
|
|
|
@ -80,13 +80,16 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||||
import org.springframework.integration.transaction.PseudoTransactionManager;
|
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.jdbc.datasource.init.DatabasePopulator;
|
import org.springframework.jdbc.datasource.init.DatabasePopulator;
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.TransactionDefinition;
|
||||||
|
import org.springframework.transaction.TransactionException;
|
||||||
|
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
|
||||||
|
import org.springframework.transaction.support.DefaultTransactionStatus;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
@ -544,13 +547,34 @@ class BatchAutoConfigurationTests {
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
public PlatformTransactionManager normalTransactionManager() {
|
public PlatformTransactionManager normalTransactionManager() {
|
||||||
return new PseudoTransactionManager();
|
return new TestTransactionManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BatchTransactionManager
|
@BatchTransactionManager
|
||||||
@Bean
|
@Bean
|
||||||
public PlatformTransactionManager batchTransactionManager() {
|
public PlatformTransactionManager batchTransactionManager() {
|
||||||
return new PseudoTransactionManager();
|
return new TestTransactionManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class TestTransactionManager extends AbstractPlatformTransactionManager {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object doGetTransaction() throws TransactionException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doCommit(DefaultTransactionStatus status) throws TransactionException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doRollback(DefaultTransactionStatus status) throws TransactionException {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ For more info about Spring Batch, see the {spring-batch}[Spring Batch project pa
|
||||||
|
|
||||||
[[howto.batch.specifying-a-transaction-manager]]
|
[[howto.batch.specifying-a-transaction-manager]]
|
||||||
=== Specifying a Batch Transaction Manager
|
=== Specifying a Batch Transaction Manager
|
||||||
Similar to <<howto.batch.specifying-a-data-source>> you can also define a `PlatformTransactionManager`
|
Similar to <<howto.batch.specifying-a-data-source>>, you can define a `PlatformTransactionManager` for use in the batch processing by marking it as `@BatchTransactionManager`.
|
||||||
for use in the batch processing by marking it as `@BatchTransactionManager`.
|
|
||||||
If you do so and want two transaction managers, remember to mark the other one as `@Primary`.
|
If you do so and want two transaction managers, remember to mark the other one as `@Primary`.
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue