spwrap is a little library that simplify calls to database stored procedures in java.
Read this introduction to talk an idea about spwrap before continue reading this post.
We have talked before about how to use spwrap in spring boot application.
Today we will talk about a new feature just release in version 0.0.18, which is spwrap now can participate in spring transactions.
spwrap itself doesn't allow spanning transaction across DAO method calls. but as part of 0.0.18, it will participate in spring Transactions if spwrap is used inside spring and there's an active transaction.
Suppose we have a spring project with Datasource transaction manager is enabled.
And we have SupplierDAO which is a spwrap DAO defined like this:
And we have a domain object supplier and its spring-data-jpa repository
And here's the service class:
Now because the supplierDAO.insertSupplier(supplierName) insert supplier with name "Abdullah", and supplierRepo.save(s2) insert supplier with the same name, then spring frameowkr will throw DataAccessException subclass and rollback the entire transaction.
Which meaning the stored procedure that is executed as a result of calling supplierDAO.insertSupplier(supplierName) will be rollbacked as well.
Again, this is a new feature as part of spwrap 0.0.18.
You can see the full example at github: https://github.com/mhewedy/spwrap-examples/tree/master/spring-boot-transactions-mysql Don't forget, if you like the spwrap library, don't forget to like the project page at github.