GoogleCloudPlatform / spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Apache License 2.0
416 stars 307 forks source link

[Spring Data Cloud Spanner] Add configuration to favour mutations or dml statements #660

Open sebarthel89 opened 2 years ago

sebarthel89 commented 2 years ago

Spring data cloud spanner: add configuration to favour mutations or dml statements

Is your feature request related to a problem? Please describe.

Like stated in the spanner documenation (https://cloud.google.com/spanner/docs/dml-versus-mutations), it should avoided to uses mutations and dml statements in the same transaction. There is some behavior in Spring Data Cloud Spanner that

Describe the solution you'd like From an application development, if there is no explicit need to execute a dml statement to make use of the benefits of dml statements vs mutations, it should be easy to use mutations if possible.

Because I can imagine that applications were already but around, and applications already use dml statements and mutations, maybe without even knowing, I want to request a configuration property, to control the default behavior of the execution of UPDATE, INSERT and DELETE queries.

suggestion:

spring.cloud.gcp.spanner.useMutationsOnly=true (default false)

Describe alternatives you've considered Alternatives we are using right now is, to add custom methods to the Repository interface using the @Query annotation and set the dmlStatement to false.

Additional context DML statements and mutations are 2 different APIs. By default, to reduce risk that comes with mixing mutation/query API. Also, engineers should be able to use the dml API if needed, but this is another API/Option they can slowly adopt. By executing dml statements although it's not explicitly visible, there are confusions about the execution path, nested transactions (transaction handling).

mpeddada1 commented 2 years ago

Thanks for the suggestion. We will leave this open and look into this further.