-
Notifications
You must be signed in to change notification settings - Fork 0
Transaction Management
Overall the framework assumes that the queued task is not transactional nor a transaction is needed. To wrap the trigger status updates together with any transactional workload (recommended) where are two possibilites:
- Use the transactional flag
- Use the Spring
@Transactional
annotation
@Bean
TransactionalTask<String> savePersonInTrx(PersonRepository personRepository) {
return (state) -> personRepository.save(new PersonBE(name));
}
which is basically the same as
@Bean
PersistentTask<String> savePersonInTrx(PersonRepository personRepository) {
return new TransactionalTask<String>() {
@Override
public void accept(String name) {
personRepository.save(new PersonBE(name));
}turn RetryStrategy.THREE_RETRIES_IMMEDIATELY;
}
@Override
public boolean isTransactional() {
return true;
}
};
}
NOTE: Any annotation will overwrite
isTransactional
flag
@Component("transactionalClass") @Transactional(timeout = 5, propagation = Propagation.MANDATORY) @RequiredArgsConstructor public class TransactionalClass implements PersistentTask { private final PersonRepository personRepository; @Override public void accept(String name) { personRepository.save(new PersonBE(name)); } }
In this example the REPEATABLE_READ
will be applied to the outside transaction
@Component("transactionalMethod") @RequiredArgsConstructor static class TransactionalMethod implements PersistentTask { private final PersonRepository personRepository; @Transactional(timeout = 6, propagation = Propagation.MANDATORY, isolation = Isolation.REPEATABLE_READ) @Override public void accept(String name) { personRepository.save(new PersonBE(name)); } }
No annotation or setting REQUIRES_NEW
will force the framework to not wrap everything into a transactional template
@Component("transactionalMethod") @RequiredArgsConstructor static class TransactionalMethod implements PersistentTask { private final PersonRepository personRepository; @Transactional(timeout = 6, propagation = Propagation.MANDATORY, isolation = Isolation.REPEATABLE_READ) @Override public void accept(String name) { personRepository.save(new PersonBE(name)); } }