Transactions
Comprehensive transaction support is among the most compelling reasons to use the Spring Framework.
That’s why we implemented Spring Transactions.
Just like Spring JPA you can use declarative or programmatic transaction management.
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
//...
@Service
@Transactional
public class VetService
{
//...
public void saveNewEntries()
{
final Vet vet = this.createVet();
this.vetRepository.save(vet);
}
//...
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
//...
@Service
public class OwnerService
{
private final PlatformTransactionManager transactionManager;
@Autowired
public OwnerService(
final OwnerRepository ownerRepository,
final PlatformTransactionManager transactionManager)
{
this.ownerRepository = ownerRepository;
this.transactionManager = transactionManager;
}
//...
public void deleteAll()
{
new TransactionTemplate(this.transactionManager).execute(
status ->
{
this.ownerRepository.deleteAll();
return null;
});
}
//...
If you are using transaction, you need to define a Bean for PlatformTransactionManager ! This is easiest achieved by extending the EclipseStoreClientConfiguration . See the complex demo.
|