Skip to content

Introduced pessimistic locks for derived queries. #1158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

DiegoKrupitza
Copy link
Contributor

@DiegoKrupitza DiegoKrupitza commented Feb 4, 2022

Methods which use the derive query functionality now can be annotated with @Lock to used a given LockMode. Right now there are two different modes PESSIMISTIC_READ and PESSIMISTIC_WRITE. Based on the dialect the right select is generated. For example for HSQLDB Select ... FOR UPDATE.

Related tickets #1041

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Methods which use the derive query functionality now can be annotated with `@Lock` to used a given `LockMode`. Right now there are two different modes `PESSIMISTIC_READ` and `PESSIMISTIC_WRITE`. Based on the dialect the right select is generated. For example for HSQLDB `Select ... FOR UPDATE`.

Related tickets spring-projects#1041
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 4, 2022
schauder pushed a commit that referenced this pull request Feb 9, 2022
Methods which use the derive query functionality now can be annotated with `@Lock` to used a given `LockMode`. Right now there are two different modes `PESSIMISTIC_READ` and `PESSIMISTIC_WRITE`. Based on the dialect the right select is generated. For example for HSQLDB `Select ... FOR UPDATE`.

See #1041
Original pull request #1158
schauder added a commit that referenced this pull request Feb 9, 2022
Refactored the unit tests to include a negative case and to separate the different scenarios tested.

Removed the default LockMode from the Lock annotation.
I have the feeling that most users will assume an exclusive Lock when none is specified, but also don't want to request stronger locks than required.

Original pull request #1158
See #1041
@schauder
Copy link
Contributor

schauder commented Feb 9, 2022

Thanks for the PR that is polished and merged.

It does not solve #1041 since that one asked for the same thing, but for Spring Data R2DBC.
If you happen to be interested in tackling that as well, it would be highly appreciated.

@schauder schauder closed this Feb 9, 2022
@DiegoKrupitza
Copy link
Contributor Author

DiegoKrupitza commented Feb 9, 2022

Thanks for the PR that is polished and merged.

It does not solve #1041 since that one asked for the same thing, but for Spring Data R2DBC.

Oh ok I don't know why I thought that 😅 . I am quite confused why is this issue then in the spring-data-jpa and not Spring Data R2DBC?

If you happen to be interested in tackling that as well, it would be highly appreciated.

If I find time for it I will take a closer look at it, but my R2DBC knowledge is quite limited...

@schauder

@schauder
Copy link
Contributor

schauder commented Feb 9, 2022

I am quite confused why is this issue then in the spring-data-jpa and not Spring Data R2DBC?

Well it's in spring-data-jdbc not spring-data-jpa 😂

Since both modules spring-data-jdbc and spring-data-r2dbc rely on spring-data-relational which is an artifact build from the spring-data-jdbc repository, it gets easy to get confused.

In the not to far future spring-data-jdbc and spring-data-r2dbc will get moved into one repository.
I'm not sure though if this will be helpful on the confusion front.

@DiegoKrupitza
Copy link
Contributor Author

Well it's in spring-data-jdbc not spring-data-jpa 😂

Yeah I wrote spring-data-jpa by mistake 😂

In the not to far future spring-data-jdbc and spring-data-r2dbc will get moved into one repository. I'm not sure though if this will be helpful on the confusion front.

I think this won't make it better 😅 because when I hear "r2dbc" I instantly think about "reactive" and when I hear "jdbc" the last thing that comes to my mind is "reactive" 😅 , but maybe with clear documentation this should not be a problem

@schauder
Copy link
Contributor

schauder commented Feb 9, 2022

when I hear "r2dbc" I instantly think about "reactive" and when I hear "jdbc" the last thing that comes to my mind is "reactive"

And that is absolutely correct. But both use SQL to access relational databases, so they already have a lot in common and in the future will share even more code.

schauder pushed a commit that referenced this pull request Feb 15, 2022
Methods which use the derive query functionality now can be annotated with `@Lock` to used a given `LockMode`. Right now there are two different modes `PESSIMISTIC_READ` and `PESSIMISTIC_WRITE`. Based on the dialect the right select is generated. For example for HSQLDB `Select ... FOR UPDATE`.

See #1041
Original pull request #1158
schauder added a commit that referenced this pull request Feb 15, 2022
Refactored the unit tests to include a negative case and to separate the different scenarios tested.

Removed the default LockMode from the Lock annotation.
I have the feeling that most users will assume an exclusive Lock when none is specified, but also don't want to request stronger locks than required.

Original pull request #1158
See #1041
@DiegoKrupitza
Copy link
Contributor Author

DiegoKrupitza commented Feb 15, 2022

It does not solve #1041 since that one asked for the same thing, but for Spring Data R2DBC.
@schauder

This should now be implemented with spring-projects/spring-data-r2dbc#720

schauder added a commit that referenced this pull request Feb 22, 2022
This allows both Spring Data R2DBC and Spring Data JDBC to use the same annotation.

See /issues/1041, spring-projects/spring-data-r2dbc/pull/720, /pull/1158
schauder added a commit that referenced this pull request Feb 22, 2022
This allows both Spring Data R2DBC and Spring Data JDBC to use the same annotation.

See /issues/1041, spring-projects/spring-data-r2dbc/pull/720, /pull/1158
schauder pushed a commit that referenced this pull request Feb 22, 2022
Methods which use the derive query functionality now can be annotated with `@Lock` to used a given `LockMode`. Right now there are two different modes `PESSIMISTIC_READ` and `PESSIMISTIC_WRITE`. Based on the dialect the right select is generated. For example for H2 `Select ... FOR UPDATE`.

Closes #1041
See #643,
Original pull request /pull/1158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants