[Spanner Data] Accessing custom repository methods within a readWrite transaction
See original GitHub issueIs your feature request related to a problem? Please describe. Transaction management is essential for creating reliable applications. Spanner allows us to create an interface and add custom methods for example by creating new method following naming conventions.
For example:
deleteByColumn(String columnValue)
Based on the name, Spanner data will execute a delete query and delete every row where column == columnValue.
For transaction management, we prefer programmatic transaction management calling the method on the SpannerRepository
performReadWriteTransaction
Unfortunately, this method returns
SpannerRepository<T, ID>
that does not provide us custom methods, that we added to our custom repository interface. Therefore, the usage of custom-added methods on a repository is limited.
Describe the solution you’d like Adapt the spanner data implementation and update performReadWriteTransaction to get a function with a parameter type of the custom subclass. This could be done with generics, but the actual implementation of the parent class and related parts need to be adapted. Also, this is not a breaking change because customers of spring data anyhow can for now only use SpannerRepository methods. The new way would require that the interface extends SpannerRepository, therefore, it should not break any build.
In short, the combination of custom repository and programmatic transaction handling should work without any limitations. It’s a key selling point of Spanner and part of every application.
Describe alternatives you’ve considered For now, we try to use methods of the SpannerRepository base class and avoid many custom methods in case if we need to group multiple executions within a single transaction. If this is really needed, we will try to fall back to SpannerOperations and execute queries manually using the SpannerTemplate.
Thanks in advance!
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Thanks for the clarifications @sebarthel89. I will share this with our team internally to discuss more about priority and how to fix.
Good point! I would suggest you add it to the documentation and to the spring boot example. This is very useful !
Thank you, keep up the good work 😃